Skip to content

Commit 495c188

Browse files
Merge pull request #22829 from sanchezl/oc_adm_must-gather_logs-not-available
wait for must-gather logs to be available
2 parents 201952b + dbe387c commit 495c188

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

pkg/oc/cli/admin/mustgather/mustgather.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package mustgather
22

33
import (
4-
"context"
54
"fmt"
65
"math/rand"
76
"path"
@@ -211,7 +210,7 @@ func (o *MustGatherOptions) Run(rsyncCmd *cobra.Command) error {
211210

212211
// stream gather container logs
213212
if err := o.getInitContainerLogs(pod); err != nil {
214-
fmt.Fprintf(o.Out, "container logs unavailable: %v", err)
213+
fmt.Fprintf(o.Out, "container logs unavailable: %v\n", err)
215214
}
216215

217216
// wait for pod to be running (gather has completed)
@@ -270,22 +269,25 @@ func (o *MustGatherOptions) waitForPodRunning(pod *corev1.Pod) error {
270269
return err
271270
}
272271
if phase != corev1.PodRunning {
273-
return fmt.Errorf("pod is not running: %v", phase)
272+
return fmt.Errorf("pod is not running: %v\n", phase)
274273
}
275274
return nil
276275
}
277276

278277
func (o *MustGatherOptions) waitForGatherContainerRunning(pod *corev1.Pod) error {
279-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
280-
defer cancel()
281-
return retry.RetryOnConnectionErrors(ctx, func(ctx context.Context) (bool, error) {
278+
return wait.PollImmediate(time.Second, 10*time.Minute, func() (bool, error) {
282279
var err error
283-
if pod, err := o.Client.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{}); err == nil {
280+
if pod, err = o.Client.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{}); err == nil {
284281
if len(pod.Status.InitContainerStatuses) == 0 {
285282
return false, nil
286283
}
287284
state := pod.Status.InitContainerStatuses[0].State
288-
return (state.Running != nil) || (state.Terminated != nil), nil
285+
running := state.Running != nil
286+
terminated := state.Terminated != nil
287+
return running || terminated, nil
288+
}
289+
if retry.IsHTTPClientError(err) {
290+
return false, nil
289291
}
290292
return false, err
291293
})

0 commit comments

Comments
 (0)