From 0c57ad0004f1ee6bc0ec2c822b9dbb92ee4ed6ef Mon Sep 17 00:00:00 2001 From: Justin SB Date: Thu, 20 Jun 2019 09:24:07 -0700 Subject: [PATCH] kubectl attach test: wait for input before proceeding This way we know stdin is attached and we are in a known state. --- test/e2e/kubectl/kubectl.go | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index d3c20d6b51e..2e658030722 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -530,25 +530,13 @@ var _ = SIGDescribe("Kubectl client", func() { nsFlag := fmt.Sprintf("--namespace=%v", ns) ginkgo.By("executing a command with run and attach with stdin") - runOutput := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). - WithStdinData("abcd1234"). + // We wait for a non-empty line so we know kubectl has attached + runOutput := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "while [ -z \"$s\" ]; do read s; sleep 1; done; echo read:$s && cat && echo 'stdin closed'"). + WithStdinData("value\nabcd1234"). ExecOrDie() - - g := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) } - runTestPod, _, err := polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test", 1*time.Minute, g) - gomega.Expect(err).To(gomega.BeNil()) - // NOTE: we cannot guarantee our output showed up in the container logs before stdin was closed, so we have - // to loop test. - err = wait.PollImmediate(time.Second, time.Minute, func() (bool, error) { - if !e2epod.CheckPodsRunningReady(c, ns, []string{runTestPod.Name}, 1*time.Second) { - e2elog.Failf("Pod %q of Job %q should still be running", runTestPod.Name, "run-test") - } - logOutput := framework.RunKubectlOrDie(nsFlag, "logs", runTestPod.Name) - gomega.Expect(runOutput).To(gomega.ContainSubstring("abcd1234")) - gomega.Expect(runOutput).To(gomega.ContainSubstring("stdin closed")) - return strings.Contains(logOutput, "abcd1234"), nil - }) - gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(runOutput).To(gomega.ContainSubstring("read:value")) + gomega.Expect(runOutput).To(gomega.ContainSubstring("abcd1234")) + gomega.Expect(runOutput).To(gomega.ContainSubstring("stdin closed")) gomega.Expect(c.BatchV1().Jobs(ns).Delete("run-test", nil)).To(gomega.BeNil()) @@ -565,8 +553,8 @@ var _ = SIGDescribe("Kubectl client", func() { WithStdinData("abcd1234\n"). ExecOrDie() gomega.Expect(runOutput).ToNot(gomega.ContainSubstring("stdin closed")) - g = func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) } - runTestPod, _, err = polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test-3", 1*time.Minute, g) + g := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) } + runTestPod, _, err := polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test-3", 1*time.Minute, g) gomega.Expect(err).To(gomega.BeNil()) if !e2epod.CheckPodsRunningReady(c, ns, []string{runTestPod.Name}, time.Minute) { e2elog.Failf("Pod %q of Job %q should still be running", runTestPod.Name, "run-test-3")