add retries to exec command in cgroup verification

This commit is contained in:
Natasha Sarkar 2025-05-06 17:57:05 +00:00
parent c6739dd54d
commit 22fa3c747b

View file

@ -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)