From d98cb84568c13160e0a9055768e5fe8a4a14cab5 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Fri, 11 Mar 2022 09:42:13 +0100 Subject: [PATCH] [e2e] TestTooManyRestarts: check err and len before accessing pod items --- test/e2e/e2e_toomanyrestarts_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/e2e/e2e_toomanyrestarts_test.go b/test/e2e/e2e_toomanyrestarts_test.go index 077b6db3b..82dcf96dc 100644 --- a/test/e2e/e2e_toomanyrestarts_test.go +++ b/test/e2e/e2e_toomanyrestarts_test.go @@ -183,14 +183,18 @@ func waitPodRestartCount(ctx context.Context, clientSet clientset.Interface, nam podList, err := clientSet.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ LabelSelector: labels.SelectorFromSet(labels.Set(map[string]string{"test": "restart-pod", "name": "test-toomanyrestarts"})).String(), }) - if podList.Items[0].Status.ContainerStatuses[0].RestartCount >= 4 && podList.Items[1].Status.ContainerStatuses[0].RestartCount >= 4 && podList.Items[2].Status.ContainerStatuses[0].RestartCount >= 4 && podList.Items[3].Status.ContainerStatuses[0].RestartCount >= 4 { - t.Log("Pod restartCount as expected") - return true, nil - } if err != nil { t.Fatalf("Unexpected err: %v", err) return false, err } + if len(podList.Items) < 4 { + t.Log("Waiting for 4 pods") + return false, nil + } + if podList.Items[0].Status.ContainerStatuses[0].RestartCount >= 4 && podList.Items[1].Status.ContainerStatuses[0].RestartCount >= 4 && podList.Items[2].Status.ContainerStatuses[0].RestartCount >= 4 && podList.Items[3].Status.ContainerStatuses[0].RestartCount >= 4 { + t.Log("Pod restartCount as expected") + return true, nil + } } } }