Skip to content
Draft
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
11 changes: 8 additions & 3 deletions pkg/cli/admin/mustgather/mustgather.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,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 @@ -947,6 +948,10 @@ func (o *MustGatherOptions) copyFilesFromPod(ctx context.Context, pod *corev1.Po
}

func (o *MustGatherOptions) getGatherContainerLogs(ctx context.Context, pod *corev1.Pod) error {
// Use a timeout context to prevent RunLogsContext or isGatherDone from waiting indefinitely
gatherCtx, gatherCancel := context.WithTimeout(ctx, o.Timeout)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not precise, this is only for log streaming. Actually the other branches may use their own timeout, but this is handled sequentially, so the user can in the end wait N * Timeout. We need to implement this so that there is only a single timeout handling really.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the comment.

Moving this PR to draft as I haven't seen this case for a while now. Without a solid reproducer, I will just be guessing at the behavior.

Thanks for all your help reviewing.

defer gatherCancel()

since2s := int64(2)
opts := &logs.LogsOptions{
Namespace: pod.Namespace,
Expand All @@ -967,13 +972,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