Add timeout parameter to 'connect_get_namespaced_pod_exec'

Sometimes the 'connect_get_namespaced_pod_exec' call is hanging
see [1] from some reason (on OS select) although the command
completed.
To resolve that we add support for '_request_timeout' parameter,
default value set to 20 seconds.

[1]: https://github.com/kubernetes-client/python/issues/559

Change-Id: Iea480269f7623e687fee41fb859537c026227c05
This commit is contained in:
Yossi Boaron 2018-11-18 09:07:19 +02:00
parent 26e363f0cb
commit a27fe3d35f
1 changed files with 7 additions and 1 deletions

View File

@ -218,12 +218,18 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
return kuryr_if['versioned_object.data']['id']
def exec_command_in_pod(self, pod_name, command, namespace="default",
stderr=False, container=None):
stderr=False, container=None, req_timeout=20):
api = self.k8s_client.CoreV1Api()
kwargs = dict(command=command, stdin=False, stdout=True, tty=False,
stderr=stderr)
if container is not None:
kwargs['container'] = container
# NOTE(yboaron): sometimes the 'connect_get_namespaced_pod_exec'
# call is hanging from some reason (on OS select) although the command
# completed. To resolve that we set the '_request_timeout' value.
# see https://github.com/kubernetes-client/python/issues/559
if req_timeout is not None:
kwargs['_request_timeout'] = req_timeout
if stderr:
kwargs['_preload_content'] = False
resp = stream(api.connect_get_namespaced_pod_exec, pod_name,