Skip to content

Commit 06a1b7b

Browse files
committed
tests: Retries exec after container restart due to liveness
The test "should not change the subpath mount on a container restart if the environment variable changes" creates a pod with the liveness probe: cat /volume_mount/test.log. The test then deletes that file, which causes the probe to fail and the container to be restarted. After which it recreates the file by exec-ing into the pod, but there is a chance that the container was not created yet, or it did not start yet. This commit adds a few retries to the exec command.
1 parent 707883d commit 06a1b7b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

test/e2e/common/expansion.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
417417
pod := newPod([]string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts, volumes)
418418
pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
419419
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "foo"}
420+
sideContainerName := "side-container"
421+
pod.Spec.Containers = append(pod.Spec.Containers, newContainer(sideContainerName, []string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts))
420422
suffix := string(uuid.NewUUID())
421423
pod.Spec.InitContainers = []v1.Container{newContainer(
422424
fmt.Sprintf("init-volume-%s", suffix), []string{"sh", "-c", "mkdir -p /volume_mount/foo; touch /volume_mount/foo/test.log"}, nil, mounts)}
@@ -512,9 +514,8 @@ func waitForPodContainerRestart(f *framework.Framework, pod *v1.Pod, volumeMount
512514

513515
// Fix liveness probe
514516
ginkgo.By("Rewriting the file")
515-
stdout, _, err = f.ExecShellInPodWithFullOutput(pod.Name, fmt.Sprintf("echo test-after > %v", volumeMount))
517+
stdout = f.ExecShellInContainer(pod.Name, pod.Spec.Containers[1].Name, fmt.Sprintf("echo test-after > %v", volumeMount))
516518
framework.Logf("Pod exec output: %v", stdout)
517-
framework.ExpectNoError(err, "while rewriting the probe file")
518519

519520
// Wait for container restarts to stabilize
520521
ginkgo.By("Waiting for container to stop restarting")

0 commit comments

Comments
 (0)