Merge pull request #79235 from justinsb/fix_73099

kubectl attach test: wait for input before proceeding
This commit is contained in:
Kubernetes Prow Robot 2019-09-06 04:36:57 -07:00 committed by GitHub
commit 1866891f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -533,25 +533,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("read:value"))
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())
@ -568,8 +556,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")