kubectl attach test: wait for input before proceeding

This way we know stdin is attached and we are in a known state.
This commit is contained in:
Justin SB 2019-06-20 09:24:07 -07:00
parent eb145bef43
commit 0c57ad0004
No known key found for this signature in database
GPG Key ID: 8DEC5C8217494E37

View File

@ -530,25 +530,13 @@ var _ = SIGDescribe("Kubectl client", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns) nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("executing a command with run and attach with stdin") 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'"). // We wait for a non-empty line so we know kubectl has attached
WithStdinData("abcd1234"). 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() ExecOrDie()
gomega.Expect(runOutput).To(gomega.ContainSubstring("read:value"))
g := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) } gomega.Expect(runOutput).To(gomega.ContainSubstring("abcd1234"))
runTestPod, _, err := polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test", 1*time.Minute, g) gomega.Expect(runOutput).To(gomega.ContainSubstring("stdin closed"))
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(c.BatchV1().Jobs(ns).Delete("run-test", nil)).To(gomega.BeNil()) 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"). WithStdinData("abcd1234\n").
ExecOrDie() ExecOrDie()
gomega.Expect(runOutput).ToNot(gomega.ContainSubstring("stdin closed")) gomega.Expect(runOutput).ToNot(gomega.ContainSubstring("stdin closed"))
g = func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) } 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) runTestPod, _, err := polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test-3", 1*time.Minute, g)
gomega.Expect(err).To(gomega.BeNil()) gomega.Expect(err).To(gomega.BeNil())
if !e2epod.CheckPodsRunningReady(c, ns, []string{runTestPod.Name}, time.Minute) { 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") e2elog.Failf("Pod %q of Job %q should still be running", runTestPod.Name, "run-test-3")