Skip to content

Commit f5f049c

Browse files
committed
Wait for pods of deployment to be ready too
1 parent 96f2e07 commit f5f049c

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

pkg/k8s/wait.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// - The number of available replicas matches the desired replicas
1818
// - All replicas are updated to the latest version
1919
// - There are no unavailable replicas
20+
// - All pods associated with the deployment are running
2021
func WaitForDeploymentAvailable(ctx context.Context, clientset *kubernetes.Clientset, namespace, deploymentName string, timeout time.Duration) error {
2122
ctx, cancel := context.WithTimeout(ctx, timeout)
2223
defer cancel()
@@ -42,7 +43,38 @@ func WaitForDeploymentAvailable(ctx context.Context, clientset *kubernetes.Clien
4243
deployment.Status.ReadyReplicas == desiredReplicas &&
4344
deployment.Status.AvailableReplicas == desiredReplicas &&
4445
deployment.Status.UnavailableReplicas == 0 {
45-
return true, nil
46+
47+
// Verify all pods are actually running
48+
labelSelector := metav1.FormatLabelSelector(deployment.Spec.Selector)
49+
pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
50+
LabelSelector: labelSelector,
51+
})
52+
if err != nil {
53+
return false, err
54+
}
55+
56+
// Count running pods
57+
runningPods := 0
58+
for _, pod := range pods.Items {
59+
if pod.Status.Phase == corev1.PodRunning {
60+
// Verify all containers in the pod are ready
61+
allContainersReady := true
62+
for _, containerStatus := range pod.Status.ContainerStatuses {
63+
if !containerStatus.Ready {
64+
allContainersReady = false
65+
break
66+
}
67+
}
68+
if allContainersReady {
69+
runningPods++
70+
}
71+
}
72+
}
73+
74+
// Ensure we have the desired number of running pods
75+
if int32(runningPods) == desiredReplicas {
76+
return true, nil
77+
}
4678
}
4779
}
4880
}

0 commit comments

Comments
 (0)