From bfef0279a72ed104062dfb6b4f3986706457e201 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 28 Apr 2022 10:35:34 +0200 Subject: [PATCH] e2e: retry getting Pods before executing commands On occasion the Pods have not been (re)started before they get listed. This can result in an empty list. It can occur during RBD testing where Pods are restarted before `uname` is executed. In case the Pods are not available yet, the test will fail with the "podlist is empty" error. By adding a retry when the list of Pods is empty, the tests should become a little more stable. Signed-off-by: Niels de Vos --- e2e/pod.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/e2e/pod.go b/e2e/pod.go index 61fb03db8..4083589a1 100644 --- a/e2e/pod.go +++ b/e2e/pod.go @@ -91,13 +91,31 @@ func waitForDaemonSets(name, ns string, c kubernetes.Interface, t int) error { } func findPodAndContainerName(f *framework.Framework, ns, cn string, opt *metav1.ListOptions) (string, string, error) { - podList, err := f.PodClientNS(ns).List(context.TODO(), *opt) - if err != nil { - return "", "", err - } + timeout := time.Duration(deployTimeout) * time.Minute - if len(podList.Items) == 0 { - return "", "", errors.New("podlist is empty") + var ( + podList *v1.PodList + listErr error + ) + err := wait.PollImmediate(poll, timeout, func() (bool, error) { + podList, listErr = f.PodClientNS(ns).List(context.TODO(), *opt) + if listErr != nil { + if isRetryableAPIError(listErr) { + return false, nil + } + + return false, fmt.Errorf("failed to list Pods: %w", listErr) + } + + if len(podList.Items) == 0 { + // retry in case the pods have not been (re)started yet + return false, nil + } + + return true, nil + }) + if err != nil { + return "", "", fmt.Errorf("failed to find pod for %v: %w", opt, err) } if cn != "" {