Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl attach test: wait for input before proceeding #79235

Merged
merged 1 commit into from Sep 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 8 additions & 20 deletions test/e2e/kubectl/kubectl.go
Expand Up @@ -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())

Expand All @@ -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")
Expand Down