Cleanup WaitForPodsRunningReady: fail for bad pods and reword log message

This commit is contained in:
Matt Karrmann 2024-04-02 23:40:33 -05:00
parent 88350dbeb0
commit 273cd03c01

View File

@ -126,14 +126,12 @@ func WaitForPodsRunningReady(ctx context.Context, c clientset.Interface, ns stri
Pods []v1.Pod Pods []v1.Pod
} }
// notReady is -1 for any failure other than a timeout. nOk := int32(0)
// Otherwise it is the number of pods that we were still badPods := []v1.Pod{}
// waiting for. otherPods := []v1.Pod{}
notReady := int32(-1) succeededPods := []string{}
err := framework.Gomega().Eventually(ctx, framework.HandleRetry(func(ctx context.Context) (*state, error) { err := framework.Gomega().Eventually(ctx, framework.HandleRetry(func(ctx context.Context) (*state, error) {
// Reset notReady at the start of a poll attempt.
notReady = -1
rcList, err := c.CoreV1().ReplicationControllers(ns).List(ctx, metav1.ListOptions{}) rcList, err := c.CoreV1().ReplicationControllers(ns).List(ctx, metav1.ListOptions{})
if err != nil { if err != nil {
@ -163,11 +161,10 @@ func WaitForPodsRunningReady(ctx context.Context, c clientset.Interface, ns stri
replicaOk += rs.Status.ReadyReplicas replicaOk += rs.Status.ReadyReplicas
} }
nOk := int32(0) nOk = 0
notReady = int32(0) badPods = []v1.Pod{}
failedPods := []v1.Pod{} otherPods = []v1.Pod{}
otherPods := []v1.Pod{} succeededPods = []string{}
succeededPods := []string{}
for _, pod := range s.Pods { for _, pod := range s.Pods {
res, err := testutils.PodRunningReady(&pod) res, err := testutils.PodRunningReady(&pod)
switch { switch {
@ -179,14 +176,13 @@ func WaitForPodsRunningReady(ctx context.Context, c clientset.Interface, ns stri
case pod.Status.Phase == v1.PodFailed: case pod.Status.Phase == v1.PodFailed:
// ignore failed pods that are controlled by some controller // ignore failed pods that are controlled by some controller
if metav1.GetControllerOf(&pod) == nil { if metav1.GetControllerOf(&pod) == nil {
failedPods = append(failedPods, pod) badPods = append(badPods, pod)
} }
default: default:
notReady++
otherPods = append(otherPods, pod) otherPods = append(otherPods, pod)
} }
} }
done := replicaOk == replicas && nOk >= minPods && (len(failedPods)+len(otherPods)) == 0 done := replicaOk == replicas && nOk >= minPods && (len(badPods)+len(otherPods)) == 0
if done { if done {
return nil, nil return nil, nil
} }
@ -200,8 +196,8 @@ func WaitForPodsRunningReady(ctx context.Context, c clientset.Interface, ns stri
if len(succeededPods) > 0 { if len(succeededPods) > 0 {
buffer.WriteString(fmt.Sprintf("Pods that completed successfully:\n%s", format.Object(succeededPods, 1))) buffer.WriteString(fmt.Sprintf("Pods that completed successfully:\n%s", format.Object(succeededPods, 1)))
} }
if len(failedPods) > 0 { if len(badPods) > 0 {
buffer.WriteString(fmt.Sprintf("Pods that failed and were not controlled by some controller:\n%s", format.Object(failedPods, 1))) buffer.WriteString(fmt.Sprintf("Pods that failed and were not controlled by some controller:\n%s", format.Object(badPods, 1)))
} }
if len(otherPods) > 0 { if len(otherPods) > 0 {
buffer.WriteString(fmt.Sprintf("Pods that were neither completed nor running:\n%s", format.Object(otherPods, 1))) buffer.WriteString(fmt.Sprintf("Pods that were neither completed nor running:\n%s", format.Object(otherPods, 1)))
@ -211,8 +207,10 @@ func WaitForPodsRunningReady(ctx context.Context, c clientset.Interface, ns stri
})) }))
// An error might not be fatal. // An error might not be fatal.
if err != nil && notReady >= 0 && notReady <= allowedNotReadyPods { if len(badPods) == 0 && nOk < minPods && nOk+allowedNotReadyPods >= minPods {
framework.Logf("Number of not-ready pods (%d) is below the allowed threshold (%d).", notReady, allowedNotReadyPods) framework.Logf(
"Only %d Pods, instead of the expected %d, are Ready, but this exceeds the minimum threshold of %d - %d = %d",
nOk, minPods, minPods-allowedNotReadyPods, allowedNotReadyPods, minPods)
return nil return nil
} }
return err return err