Skip to content

How do you get exit code connect_get_namespaced_pod_exec ? #812

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

Closed
oz123 opened this issue Apr 11, 2019 · 6 comments
Closed

How do you get exit code connect_get_namespaced_pod_exec ? #812

oz123 opened this issue Apr 11, 2019 · 6 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@oz123
Copy link
Contributor

oz123 commented Apr 11, 2019

Currently I have to simply do this:

        response = stream(self.api.connect_get_namespaced_pod_exec,
                          podname, 'kube-system',
                          command=exec_command,
                          stderr=False, stdin=False,
                          stdout=True, tty=False)

        if not response:
            do_something__()

However, I can't get the error code, or the stderror.
Looking at the source code I don't see an easy way.

@tomplus
Copy link
Member

tomplus commented Jun 6, 2019

@oz123 The error code arrives in the channel number 3 (error-channel) but it is not exposed by the stream() method.

As a workaround you can use:

from kubernetes.stream.ws_client import ERROR_CHANNEL
....

client = stream(api.connect_get_namespaced_pod_exec,
                "myapp-78898448f4-pgnfl",
                "default",
                command=["false"],                  # <<< "false" returns with exit code = 1
                stderr=True, stdin=False,
                stdout=True, tty=False,
                _preload_content=False)             #  <<< we need a client object

client.run_forever(timeout=60)
err = client.read_channel(ERROR_CHANNEL)

pprint(yaml.load(err))

and you should get

{'details': {'causes': [{'message': '1', 'reason': 'ExitCode'}]},
 'message': 'command terminated with non-zero exit code: Error executing in '
            'Docker Container: 1',
 'metadata': {},
 'reason': 'NonZeroExitCode',
 'status': 'Failure'}

I'm going to add a method to get it in more convenient way.

@phracek
Copy link

phracek commented Jun 6, 2019

CC @TomasTomecek

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 4, 2019
@roycaihw
Copy link
Member

fixed by kubernetes-client/python-base#160

/close

@k8s-ci-robot
Copy link
Contributor

@roycaihw: Closing this issue.

In response to this:

fixed by kubernetes-client/python-base#160

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sunchill06
Copy link

@tomplus

When I run this as

resp = stream(v1.connect_get_namespaced_pod_exec, podName, namespace, command=exec_command, stderr=True, stdin=False, stdout=True, tty=False, _preload_content=preloadContent)

resp.run_forever(timeout=5)
print(resp.readline_channel(1))

Response:
None

However, print(resp.read_channel(1)) gives me proper output.

Any pointers why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

7 participants