Skip to content

Commit 1866891

Browse files
authored
Merge pull request kubernetes#79235 from justinsb/fix_73099
kubectl attach test: wait for input before proceeding
2 parents 3a50184 + 0c57ad0 commit 1866891

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

test/e2e/kubectl/kubectl.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -533,25 +533,13 @@ var _ = SIGDescribe("Kubectl client", func() {
533533
nsFlag := fmt.Sprintf("--namespace=%v", ns)
534534

535535
ginkgo.By("executing a command with run and attach with stdin")
536-
runOutput := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
537-
WithStdinData("abcd1234").
536+
// We wait for a non-empty line so we know kubectl has attached
537+
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'").
538+
WithStdinData("value\nabcd1234").
538539
ExecOrDie()
539-
540-
g := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) }
541-
runTestPod, _, err := polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test", 1*time.Minute, g)
542-
gomega.Expect(err).To(gomega.BeNil())
543-
// NOTE: we cannot guarantee our output showed up in the container logs before stdin was closed, so we have
544-
// to loop test.
545-
err = wait.PollImmediate(time.Second, time.Minute, func() (bool, error) {
546-
if !e2epod.CheckPodsRunningReady(c, ns, []string{runTestPod.Name}, 1*time.Second) {
547-
e2elog.Failf("Pod %q of Job %q should still be running", runTestPod.Name, "run-test")
548-
}
549-
logOutput := framework.RunKubectlOrDie(nsFlag, "logs", runTestPod.Name)
550-
gomega.Expect(runOutput).To(gomega.ContainSubstring("abcd1234"))
551-
gomega.Expect(runOutput).To(gomega.ContainSubstring("stdin closed"))
552-
return strings.Contains(logOutput, "abcd1234"), nil
553-
})
554-
gomega.Expect(err).To(gomega.BeNil())
540+
gomega.Expect(runOutput).To(gomega.ContainSubstring("read:value"))
541+
gomega.Expect(runOutput).To(gomega.ContainSubstring("abcd1234"))
542+
gomega.Expect(runOutput).To(gomega.ContainSubstring("stdin closed"))
555543

556544
gomega.Expect(c.BatchV1().Jobs(ns).Delete("run-test", nil)).To(gomega.BeNil())
557545

@@ -568,8 +556,8 @@ var _ = SIGDescribe("Kubectl client", func() {
568556
WithStdinData("abcd1234\n").
569557
ExecOrDie()
570558
gomega.Expect(runOutput).ToNot(gomega.ContainSubstring("stdin closed"))
571-
g = func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) }
572-
runTestPod, _, err = polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test-3", 1*time.Minute, g)
559+
g := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) }
560+
runTestPod, _, err := polymorphichelpers.GetFirstPod(f.ClientSet.CoreV1(), ns, "run=run-test-3", 1*time.Minute, g)
573561
gomega.Expect(err).To(gomega.BeNil())
574562
if !e2epod.CheckPodsRunningReady(c, ns, []string{runTestPod.Name}, time.Minute) {
575563
e2elog.Failf("Pod %q of Job %q should still be running", runTestPod.Name, "run-test-3")

0 commit comments

Comments
 (0)