mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
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:
parent
eb145bef43
commit
0c57ad0004
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user