question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/kubernetes-incubator/client-python/issues/36

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mildebrandtcommented, Sep 4, 2017

Yeah, I’ll create one after my vacation.

2reactions
mildebrandtcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Execute kubectl command using Python script - Stack Overflow
I have requirement to execute the kubectl command to create pod and check the pod log for any failure. What am I doing...
Read more >
Use the KubernetesPodOperator | Cloud Composer
This page describes how to use the KubernetesPodOperator to launch Kubernetes pods from Cloud Composer into the Google Kubernetes Engine cluster that is ......
Read more >
Executing Commands - Troubleshoot Docs
The exec collector can be used to run a command in an existing pod and include the output in the collected data. The...
Read more >
ansible_runner package — ansible-runner documentation
Run an ansible-config command to get ansible configuration releated details. ... only_changed (bool) – The boolean value when set to True returns only...
Read more >
ansible-runner Documentation - Read the Docs
Ansible Runner gathers command line options provided here as a string ... run ansible/generic commands in interactive mode within container.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found