terratest icon indicating copy to clipboard operation
terratest copied to clipboard

kubectl run with stdin not working in k8s.RunKubectl method

Open developer-guy opened this issue 4 years ago • 3 comments

This is my code below : output2, _ := k8s.RunKubectlAndGetOutputE(t, kubectlOptions, "run", "netshoot", "--generator=run-pod/v1", "--image=nicolaka/netshoot", "-i", "--", podCommand)

And the output of that command here is : command.go:87: Running command kubectl with args [run netshoot --generator=run-pod/v1 --image=nicolaka/netshoot -i -- curl http://172.17.0.5:8200/v1]

but after that nothing happens and process stucks here.

developer-guy avatar Mar 18 '20 17:03 developer-guy

I believe you also need the -t flag, but in general I believe interactive commands don't quite work when going through terratest because of the way the logging infrastructure works.

yorinasub17 avatar Mar 18 '20 22:03 yorinasub17

I believe you also need the -t flag, but in general I believe interactive commands don't quite work when going through terratest because of the way the logging infrastructure works.

I added -t flag also, but nothing changed @yorinasub17

Running command kubectl with args [run netshoot --generator=run-pod/v1 -it --image=nicolaka/netshoot curl http://172.17.0.5:8200/v1]

developer-guy avatar Mar 19 '20 05:03 developer-guy

Hi, not sure if the issue is still actual, I tested this code, and got results from curl execution:

	curlOutput, _ := k8s.RunKubectlAndGetOutputE(t, options, "run", "netshoot", "--image=nicolaka/netshoot", "-i", "--", "curl", "google.com")
	fmt.Printf("\n%s\n", curlOutput)

Output:

TestKubernetesRun 2022-01-09T20:50:19+02:00 logger.go:66: Running command kubectl with args [--namespace default run netshoot --image=nicolaka/netshoot -i -- curl google.com]
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: If you don't see a command prompt, try pressing enter.
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: <TITLE>301 Moved</TITLE></HEAD><BODY>
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: <H1>301 Moved</H1>
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: The document has moved
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: <A HREF="http://www.google.com/">here</A>.
TestKubernetesRun 2022-01-09T20:51:12+02:00 logger.go:66: </BODY></HTML>

denis256 avatar Jan 09 '22 18:01 denis256