kubernetes: Make pods/exec websocket channel 3 content easier to parse exit code
/kind feature
What happened:
As part of kubernetes-client/java, I’m looking at the websocket calls for pods/exec. When the exec’d process exits with a non-zero code, we would like to provide this exit code value to the caller.
Exec status information is provided through websocket channel 3; however, this content is presently unstructured. For instance, the following content was returned:
command terminated with non-zero exit code: Error executing in Docker Container: 1
What you expected to happen:
I’d like to see the status returned as a JSON object with an exitCode attribute.
How to reproduce it (as minimally and precisely as possible):
- Create a Pod that has a script that returns a non-zero exit code.
- kubectl exec this Pod and script and watch the traffic on channel 3.
Anything else we need to know?:
Environment:
- Kubernetes version (use
kubectl version
): Client Version: version.Info{Major:“1”, Minor:“9”, GitVersion:“v1.9.2”, GitCommit:“5fa2db2bd46ac79e5e00a4e6ed24191080aa463b”, GitTreeState:“clean”, BuildDate:“2018-01-18T10:09:24Z”, GoVersion:“go1.9.2”, Compiler:“gc”, Platform:“darwin/amd64”} Server Version: version.Info{Major:“1”, Minor:“8”, GitVersion:“v1.8.7”, GitCommit:“b30876a5539f09684ff9fde266fda10b37738c9c”, GitTreeState:“clean”, BuildDate:“2018-01-16T21:52:38Z”, GoVersion:“go1.8.3”, Compiler:“gc”, Platform:“linux/amd64”} - Cloud provider or hardware configuration:
- OS (e.g. from /etc/os-release):
- Kernel (e.g.
uname -a
): - Install tools:
- Others:
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (9 by maintainers)
So, this appears to be not a bug.
One final question here though… The existing code we were working with (kubernetes-client/java project) was trying to select the protocol version by setting and then reading the header: “X-Stream-Protocol-Version”. However, I saw from the earlier code shared that the correct header is: “Sec-WebSocket-Protocol”.
@brendandburns, if I adjust io.kubernetes.client.util.WebSockets to use “Sec-WebSocket-Protocol”, then I see “v4.channel.k8s.io” selected and the message delivered to the status channel looks like this:
{"metadata":{},"status":"Failure","message":"command terminated with non-zero exit code: Error executing in Docker Container: 1","reason":"NonZeroExitCode","details":{"causes":[{"reason":"ExitCode","message":"1"}]}}