Skip to content

Executing commands on a pod fails when only command kwarg is provided #312

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
flavianmissi opened this issue Aug 3, 2017 · 10 comments
Closed
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@flavianmissi
Copy link

When calling connect_get_namespaced_pod_exec and providing only the required arguments + command, e.g. connect_get_namespaced_pod_exec("mypod", "namespace", command="ls"), I get the following exception:

ApiException: (0)
# Reason: Handshake status 404

After debugging it, I found that the issue lies on how the query string is built for multiple values vs single ones:
The resulting url path + query string for the request above is: /api/v1/namespaces/default/pods/mypod/exec&command=ls
Note the lack of ? when starting the query string.
But when giving another kwarg, e.g. connect_get_namespaced_pod_exec("mypod", "namespace", command="ls", stderr=True), the call works fine.

Note that this issue is specifically when using websockets. Relevant code is on websocket_call

Here's a full example that reproduces my problem:

from kubernetes.client import configuration
from kubernetes import config
from kubernetes.client.apis import core_v1_api

configuration.assert_hostname = False
config.load_kube_config()
c = core_v1_api.CoreV1Api()
c.connect_get_namespaced_pod_exec("mypod", "namespace", command="ls")
# raises exception "Handshake status 404"

FTR, here's where I first asked for/got help #36

@mildebrandt
Copy link

mildebrandt commented Aug 30, 2017

Using 3.0.0 from pip and python3.6, I get the same issue. However, the workaround of supplying another parameter does not work for me. Is there something else I could try to get this working? My resulting URL is a bit more complex, but even "ls" fails for me:

/api/v1/namespaces/demo/pods/mongo-0/exec?stderr=True&command=mongo&&command=admin&&command=--eval&&command=db.createUser%28%5C%7B+user%3A+%27myuser%27%2C+pwd%3A+%27mypass%27%2C+roles%3A+%5B%7B%27role%27%3A+%27userAdminAnyDatabase%27%2C+%27db%27%3A+%27admin%27%7D%5D+%5C%7D%29&

@flavianmissi
Copy link
Author

Have you tried with 2.0.0? your url seems broken in a different way than mine was, you've got duplicated &, and my problem was that I got no ? at the beginning of the query string, so it makes sense that the work around doesn't fix it for you:(

@mildebrandt
Copy link

mildebrandt commented Aug 31, 2017

It seems my issue was the lack of the "container" parameter since there are two in my pod. However, I needed to run the command through curl to get that message back from the system:

HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Wed, 30 Aug 2017 02:20:52 GMT
Content-Length: 231

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "a container name must be specified for pod mongo-0, choose one of: [mongo mongo-sidecar]",
  "reason": "BadRequest",
  "code": 400
}

It doesn't seem like the double ampersands cause any issue, but it's easily fixed by changing:

url += "&command=%s&" % quote_plus(command)

to

url += "&command=%s" % quote_plus(command)

in ws_client.py.

@mbohlool
Copy link
Contributor

mbohlool commented Sep 4, 2017

@eyeofthefrog nice catch. can you send a PR to fix ws_client.py?

@mildebrandt
Copy link

Yeah, I'll create one after my vacation.

@mildebrandt
Copy link

Done #346

@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 Apr 21, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

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 rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 21, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

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

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants