kubernetes-client / kubernetes-client/python

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

Open
#2,292 13 comments 0 reactions 1 assignee Claimed by @yliaog View on GitHub
help wanted kind/bug lifecycle/rotten
Dominant language
Python
Stars
7.7k
Forks
3.5k
Avg merge
1d 14h
Merged PRs (30d)
18

Description

**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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.