python icon indicating copy to clipboard operation
python copied to clipboard

Executing command in pod fails when _request_timeout is passed in tuple format

Open tusharrobin opened this issue 4 months ago • 5 comments

What happened (please include outputs or screenshots):

Executing command in pod fails if _request_timeout is passed as tuple. The exact error is Exception when calling CoreV1Api->connect_get_namespaced_pod_exec: (0) Reason: '<' not supported between instances of 'float' and 'tuple'

What you expected to happen: Expected to run the command successfully.

How to reproduce it (as minimally and precisely as possible):

`from kubernetes import client, config from kubernetes.stream import stream

def run_command_in_pod(namespace, pod_name, container_name, command, timeout): config.load_kube_config() c = client.Configuration() c.debug = True api_instance = client.CoreV1Api()

exec_command = [
    '/bin/sh',
    '-c',
    command
]

try:
    response = stream(api_instance.connect_get_namespaced_pod_exec,
                      pod_name,
                      namespace,
                      container=container_name,
                      command=exec_command,
                      stderr=True, stdin=False,
                      stdout=True, tty=False,
                      _request_timeout=timeout)
    print("Command output: ", response)
except client.exceptions.ApiException as e:
    print("Exception when calling CoreV1Api->connect_get_namespaced_pod_exec: %s\n" % e)

if name == 'main': namespace = 'test' pod_name = 'test' container_name = 'test' command = 'date' timeout = (5, 10)

run_command_in_pod(namespace, pod_name, container_name, command, timeout)`

Anything else we need to know?:

Environment:

  • Kubernetes version (kubectl version): 1.30
  • OS (e.g., MacOS 10.13.6): Rocky 8.6
  • Python version (python --version) 3.9
  • Python client version (pip list | grep kubernetes) kubernetes-31.0.0

tusharrobin avatar Oct 08 '24 05:10 tusharrobin