Skip to content

Commit

Permalink
k8s_exec: add argument to support pod with multiple containers
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Nov 12, 2019
1 parent a66481b commit 9c36f8d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/ansible/modules/clustering/k8s/k8s_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
- The pod name
type: str
required: yes
container:
description:
- The name of the container in the pod to connect to. Defaults to only container if there is only one container in the pod.
type: str
required: no
command:
description:
- The command to execute
Expand Down Expand Up @@ -109,6 +114,7 @@ def argspec(self):
spec = copy.deepcopy(AUTH_ARG_SPEC)
spec['namespace'] = {'type': 'str'}
spec['pod'] = {'type': 'str'}
spec['container'] = {'type': 'str'}
spec['command'] = {'type': 'str'}
return spec

Expand All @@ -118,6 +124,11 @@ def main():
# Load kubernetes.client.Configuration
module.get_api_client()
api = core_v1_api.CoreV1Api()

# hack because passing the container as None breaks things
optional_kwargs = {}
if module.params.get('container'):
optional_kwargs['container'] = module.params['container']
resp = stream(
api.connect_get_namespaced_pod_exec,
module.params["pod"],
Expand All @@ -127,7 +138,7 @@ def main():
stderr=True,
stdin=False,
tty=False,
_preload_content=False)
_preload_content=False, **optional_kwargs)
stdout, stderr = [], []
while resp.is_open():
resp.update(timeout=1)
Expand Down

0 comments on commit 9c36f8d

Please sign in to comment.