|
1 | 1 | package mustgather |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "fmt" |
6 | 5 | "math/rand" |
7 | 6 | "path" |
@@ -211,7 +210,7 @@ func (o *MustGatherOptions) Run(rsyncCmd *cobra.Command) error { |
211 | 210 |
|
212 | 211 | // stream gather container logs |
213 | 212 | 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) |
215 | 214 | } |
216 | 215 |
|
217 | 216 | // wait for pod to be running (gather has completed) |
@@ -270,22 +269,25 @@ func (o *MustGatherOptions) waitForPodRunning(pod *corev1.Pod) error { |
270 | 269 | return err |
271 | 270 | } |
272 | 271 | 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) |
274 | 273 | } |
275 | 274 | return nil |
276 | 275 | } |
277 | 276 |
|
278 | 277 | 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) { |
282 | 279 | 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 { |
284 | 281 | if len(pod.Status.InitContainerStatuses) == 0 { |
285 | 282 | return false, nil |
286 | 283 | } |
287 | 284 | 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 |
289 | 291 | } |
290 | 292 | return false, err |
291 | 293 | }) |
|
0 commit comments