@@ -558,11 +558,24 @@ var _ = SIGDescribe("Kubectl client", func() {
558
558
})
559
559
560
560
ginkgo .It ("should support inline execution and attach" , func () {
561
+ waitForStdinContent := func (pod , content string ) string {
562
+ var logOutput string
563
+ err := wait .Poll (10 * time .Second , 5 * time .Minute , func () (bool , error ) {
564
+ logOutput = framework .RunKubectlOrDie (ns , "logs" , pod )
565
+ return strings .Contains (logOutput , content ), nil
566
+ })
567
+
568
+ gomega .Expect (err ).To (gomega .BeNil (), fmt .Sprintf ("unexpected error waiting for '%v' output" , content ))
569
+ return logOutput
570
+ }
571
+
561
572
ginkgo .By ("executing a command with run and attach with stdin" )
562
573
// We wait for a non-empty line so we know kubectl has attached
563
- runOutput := framework .NewKubectlCommand (ns , "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'" ).
574
+ framework .NewKubectlCommand (ns , "run" , "run-test" , "--image=" + busyboxImage , "--restart=OnFailure" , "--attach=true" , "--stdin" , "--" , "sh" , "-c" , "echo -n read: && cat && echo 'stdin closed'" ).
564
575
WithStdinData ("value\n abcd1234" ).
565
576
ExecOrDie (ns )
577
+
578
+ runOutput := waitForStdinContent ("run-test" , "stdin closed" )
566
579
gomega .Expect (runOutput ).To (gomega .ContainSubstring ("read:value" ))
567
580
gomega .Expect (runOutput ).To (gomega .ContainSubstring ("abcd1234" ))
568
581
gomega .Expect (runOutput ).To (gomega .ContainSubstring ("stdin closed" ))
@@ -575,38 +588,32 @@ var _ = SIGDescribe("Kubectl client", func() {
575
588
// "stdin closed", but hasn't exited yet.
576
589
// We wait 10 seconds before printing to give time to kubectl to attach
577
590
// to the container, this does not solve the race though.
578
- runOutput = framework .NewKubectlCommand (ns , "run" , "run-test-2" , "--image=" + busyboxImage , "--restart=OnFailure" , "--attach=true" , "--leave-stdin-open=true" , "--" , "sh" , "-c" , "sleep 10; cat && echo 'stdin closed'" ).
591
+ framework .NewKubectlCommand (ns , "run" , "run-test-2" , "--image=" + busyboxImage , "--restart=OnFailure" , "--attach=true" , "--leave-stdin-open=true" , "--" , "sh" , "-c" , "cat && echo 'stdin closed'" ).
579
592
WithStdinData ("abcd1234" ).
580
593
ExecOrDie (ns )
594
+
595
+ runOutput = waitForStdinContent ("run-test-2" , "stdin closed" )
581
596
gomega .Expect (runOutput ).ToNot (gomega .ContainSubstring ("abcd1234" ))
582
597
gomega .Expect (runOutput ).To (gomega .ContainSubstring ("stdin closed" ))
583
598
584
599
gomega .Expect (c .CoreV1 ().Pods (ns ).Delete (context .TODO (), "run-test-2" , metav1.DeleteOptions {})).To (gomega .BeNil ())
585
600
586
601
ginkgo .By ("executing a command with run and attach with stdin with open stdin should remain running" )
587
- runOutput = framework .NewKubectlCommand (ns , "run" , "run-test-3" , "--image=" + busyboxImage , "--restart=OnFailure" , "--attach=true" , "--leave-stdin-open=true" , "--stdin" , "--" , "sh" , "-c" , "cat && echo 'stdin closed'" ).
602
+ framework .NewKubectlCommand (ns , "run" , "run-test-3" , "--image=" + busyboxImage , "--restart=OnFailure" , "--attach=true" , "--leave-stdin-open=true" , "--stdin" , "--" , "sh" , "-c" , "cat && echo 'stdin closed'" ).
588
603
WithStdinData ("abcd1234\n " ).
589
604
ExecOrDie (ns )
605
+
606
+ runOutput = waitForStdinContent ("run-test-3" , "abcd1234" )
607
+ gomega .Expect (runOutput ).To (gomega .ContainSubstring ("abcd1234" ))
590
608
gomega .Expect (runOutput ).ToNot (gomega .ContainSubstring ("stdin closed" ))
609
+
591
610
g := func (pods []* v1.Pod ) sort.Interface { return sort .Reverse (controller .ActivePods (pods )) }
592
611
runTestPod , _ , err := polymorphichelpers .GetFirstPod (f .ClientSet .CoreV1 (), ns , "run=run-test-3" , 1 * time .Minute , g )
593
612
framework .ExpectNoError (err )
594
613
if ! e2epod .CheckPodsRunningReady (c , ns , []string {runTestPod .Name }, time .Minute ) {
595
614
framework .Failf ("Pod %q of Job %q should still be running" , runTestPod .Name , "run-test-3" )
596
615
}
597
616
598
- // NOTE: we cannot guarantee our output showed up in the container logs before stdin was closed, so we have
599
- // to loop test.
600
- err = wait .PollImmediate (time .Second , time .Minute , func () (bool , error ) {
601
- if ! e2epod .CheckPodsRunningReady (c , ns , []string {runTestPod .Name }, 1 * time .Second ) {
602
- framework .Failf ("Pod %q of Job %q should still be running" , runTestPod .Name , "run-test-3" )
603
- }
604
- logOutput := framework .RunKubectlOrDie (ns , "logs" , runTestPod .Name )
605
- gomega .Expect (logOutput ).ToNot (gomega .ContainSubstring ("stdin closed" ))
606
- return strings .Contains (logOutput , "abcd1234" ), nil
607
- })
608
- framework .ExpectNoError (err )
609
-
610
617
gomega .Expect (c .CoreV1 ().Pods (ns ).Delete (context .TODO (), "run-test-3" , metav1.DeleteOptions {})).To (gomega .BeNil ())
611
618
})
612
619
0 commit comments