From 22fa3c747b1f44ad7f85fe845cd502f838c8a705 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 6 May 2025 17:57:05 +0000 Subject: [PATCH] add retries to exec command in cgroup verification --- .../common/node/framework/cgroups/cgroups.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/e2e/common/node/framework/cgroups/cgroups.go b/test/e2e/common/node/framework/cgroups/cgroups.go index 1924fc4e4e6..fc71e946c68 100644 --- a/test/e2e/common/node/framework/cgroups/cgroups.go +++ b/test/e2e/common/node/framework/cgroups/cgroups.go @@ -374,11 +374,22 @@ func VerifyCgroupValue(f *framework.Framework, pod *v1.Pod, cName, cgPath string cmd := fmt.Sprintf("head -n 1 %s", cgPath) framework.Logf("Namespace %s Pod %s Container %s - looking for one of the expected cgroup values %s in path %s", pod.Namespace, pod.Name, cName, expectedCgValues, cgPath) - cgValue, _, err := e2epod.ExecCommandInContainerWithFullOutput(f, pod.Name, cName, "/bin/sh", "-c", cmd) - if err != nil { - return fmt.Errorf("failed to read cgroup value %q for container %q: %w", cgPath, cName, err) + + const maxRetries = 3 + var cgValue string + var err error + for i := range maxRetries { + cgValue, _, err = e2epod.ExecCommandInContainerWithFullOutput(f, pod.Name, cName, "/bin/sh", "-c", cmd) + if err == nil { + cgValue = strings.Trim(cgValue, "\n") + break + } else { + framework.Logf("[Attempt %d of %d] Failed to read cgroup value %q for container %q: %v", i+1, maxRetries, cgPath, cName, err) + } + } + if err != nil { + return fmt.Errorf("failed to read cgroup value %q for container %q after %d attempts: %w", cgPath, cName, maxRetries, err) } - cgValue = strings.Trim(cgValue, "\n") if err := framework.Gomega().Expect(cgValue).To(gomega.BeElementOf(expectedCgValues)); err != nil { return fmt.Errorf("value of cgroup %q for container %q was %q; expected one of %q", cgPath, cName, cgValue, expectedCgValues)