mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-05-28 04:04:39 -04:00
add retries to exec command in cgroup verification
This commit is contained in:
parent
c6739dd54d
commit
22fa3c747b
1 changed files with 15 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue