MCPcopy
hub / github.com/microsoft/retina / waitForContainerRunning

Function waitForContainerRunning

shell/attach.go:47–80  ·  view source on GitHub ↗
(ctx context.Context, timeout time.Duration, clientset *kubernetes.Clientset, namespace, podName, containerName string)

Source from the content-addressed store, hash-verified

45}
46
47func waitForContainerRunning(ctx context.Context, timeout time.Duration, clientset *kubernetes.Clientset, namespace, podName, containerName string) error {
48 ctx, cancel := context.WithTimeout(ctx, timeout)
49 defer cancel()
50 for {
51 pod, err := clientset.CoreV1().
52 Pods(namespace).
53 Get(ctx, podName, metav1.GetOptions{})
54 if err != nil {
55 if errors.Is(err, context.DeadlineExceeded) {
56 return waitTimeoutError(err, timeout, containerName)
57 }
58 return fmt.Errorf("error retrieving pod %s in namespace %s: %w", podName, namespace, err)
59 }
60
61 for i := range pod.Status.ContainerStatuses {
62 status := pod.Status.ContainerStatuses[i]
63 if status.Name == containerName && status.State.Running != nil {
64 return nil
65 }
66 }
67 for i := range pod.Status.EphemeralContainerStatuses {
68 status := pod.Status.EphemeralContainerStatuses[i]
69 if status.Name == containerName && status.State.Running != nil {
70 return nil
71 }
72 }
73
74 select {
75 case <-ctx.Done():
76 return waitTimeoutError(context.DeadlineExceeded, timeout, containerName)
77 case <-time.After(1 * time.Second):
78 }
79 }
80}
81
82func waitTimeoutError(err error, timeout time.Duration, containerName string) error {
83 return fmt.Errorf("timed out after %s waiting for container %s to start. The timeout can be increased by setting --timeout. Err: %w", timeout, containerName, err)

Callers 3

RunInPodFunction · 0.85
RunInNodeFunction · 0.85
RunTraceFunction · 0.85

Calls 2

waitTimeoutErrorFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected