From 06a1b7b4911ea9bc5a7eea71952356a5a577bf3b Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Mon, 13 Apr 2020 20:37:51 -0700 Subject: [PATCH] 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. --- test/e2e/common/expansion.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/common/expansion.go b/test/e2e/common/expansion.go index eb0f7321fe9..f6982f63dae 100644 --- a/test/e2e/common/expansion.go +++ b/test/e2e/common/expansion.go @@ -417,6 +417,8 @@ var _ = framework.KubeDescribe("Variable Expansion", func() { pod := newPod([]string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts, volumes) pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "foo"} + sideContainerName := "side-container" + pod.Spec.Containers = append(pod.Spec.Containers, newContainer(sideContainerName, []string{"/bin/sh", "-ec", "sleep 100000"}, envVars, subpathMounts)) suffix := string(uuid.NewUUID()) pod.Spec.InitContainers = []v1.Container{newContainer( 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 // Fix liveness probe ginkgo.By("Rewriting the file") - stdout, _, err = f.ExecShellInPodWithFullOutput(pod.Name, fmt.Sprintf("echo test-after > %v", volumeMount)) + stdout = f.ExecShellInContainer(pod.Name, pod.Spec.Containers[1].Name, fmt.Sprintf("echo test-after > %v", volumeMount)) framework.Logf("Pod exec output: %v", stdout) - framework.ExpectNoError(err, "while rewriting the probe file") // Wait for container restarts to stabilize ginkgo.By("Waiting for container to stop restarting")