Skip to content

How do you get exit code connect_get_namespaced_pod_exec ? #812

Description

@oz123

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.

Activity

  1. tomplus commented on Jun 6, 2019

    @tomplus
    Member

    @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.

  2. phracek commented on Jun 6, 2019

    @phracek
  3. fejta-bot commented on Sep 4, 2019

    @fejta-bot

    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

  4. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Sep 4, 2019
  5. roycaihw commented on Sep 18, 2019

    @roycaihw
    Member
  6. k8s-ci-robot commented on Sep 18, 2019

    @k8s-ci-robot
    Contributor

    @roycaihw: Closing this issue.

    Details

    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.

  7. sunchill06 commented on Jul 31, 2020

    @sunchill06

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions