Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/cli/admin/mustgather/mustgather.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,10 @@ func (o *MustGatherOptions) processNextWorkItem(ctx context.Context, ns string,
log("gather did not start: %s", err)
return fmt.Errorf("gather did not start for pod %s: %w", pod.Name, err)
}

// stream gather container logs
if err := o.getGatherContainerLogs(ctx, pod); err != nil {
if !errors.Is(err, context.Canceled) {
if !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
log("gather logs unavailable: %v", err)
}
}
Expand Down Expand Up @@ -950,6 +951,12 @@ func (o *MustGatherOptions) copyFilesFromPod(ctx context.Context, pod *corev1.Po
}

func (o *MustGatherOptions) getGatherContainerLogs(ctx context.Context, pod *corev1.Pod) error {
// Create a timeout context covering the entire gather lifecycle (waiting for
// container start, streaming logs, waiting for completion). Copying is
// intentionally excluded — per flag docs, it continues until finished.
gatherCtx, gatherCancel := context.WithTimeout(ctx, o.Timeout)
defer gatherCancel()

since2s := int64(2)
opts := &logs.LogsOptions{
Namespace: pod.Namespace,
Expand All @@ -970,13 +977,13 @@ func (o *MustGatherOptions) getGatherContainerLogs(ctx context.Context, pod *cor
// gather script might take longer than the default API server time,
// so we should check if the gather script still runs and re-run logs
// thus we run this in a loop
if err := opts.RunLogsContext(ctx); err != nil {
if err := opts.RunLogsContext(gatherCtx); err != nil {
return err
}

// to ensure we don't print all of history set since to past 2 seconds
opts.Options.(*corev1.PodLogOptions).SinceSeconds = &since2s
if done, _ := o.isGatherDone(ctx, pod); done {
if done, _ := o.isGatherDone(gatherCtx, pod); done {
return nil
}
klog.V(4).Infof("lost logs, re-trying...")
Expand Down