mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 05:22:39 +00:00
k8s_exec: Select first container from the pod (#363)
k8s_exec: Select first container from the pod SUMMARY kubectl command select first container from the pod in order to execute commands on. We replicate the same behavior in k8s_exec module. Fixes: #358 Signed-off-by: Abhijeet Kasurde akasurde@redhat.com ISSUE TYPE Bugfix Pull Request COMPONENT NAME changelogs/fragments/358-k8s_exec.yml plugins/modules/k8s_exec.py Reviewed-by: Mike Graves <mgraves@redhat.com> Reviewed-by: None <None>
This commit is contained in:
@@ -13,6 +13,21 @@
|
||||
- name: sleeper
|
||||
image: busybox
|
||||
command: ["sleep", "infinity"]
|
||||
multi_container_pod_name: pod-2
|
||||
multi_container_pod_definition:
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: "{{ multi_container_pod_name }}"
|
||||
namespace: "{{ exec_namespace }}"
|
||||
spec:
|
||||
containers:
|
||||
- name: sleeper-1
|
||||
image: busybox
|
||||
command: ["sleep", "infinity"]
|
||||
- name: sleeper-2
|
||||
image: busybox
|
||||
command: ["sleep", "infinity"]
|
||||
|
||||
block:
|
||||
- name: "Ensure that {{ exec_namespace }} namespace exists"
|
||||
@@ -57,6 +72,25 @@
|
||||
- command_status.rc != 0
|
||||
- command_status.return_code != 0
|
||||
|
||||
- name: Create a multi container pod
|
||||
k8s:
|
||||
definition: "{{ multi_container_pod_definition }}"
|
||||
wait: yes
|
||||
wait_sleep: 1
|
||||
wait_timeout: 30
|
||||
|
||||
- name: Execute command on the first container of the pod
|
||||
k8s_exec:
|
||||
pod: "{{ multi_container_pod_name }}"
|
||||
namespace: "{{ exec_namespace }}"
|
||||
command: echo hello
|
||||
register: output
|
||||
|
||||
- name: Assert k8s_exec output is correct
|
||||
assert:
|
||||
that:
|
||||
- "'hello' in output.stdout"
|
||||
|
||||
always:
|
||||
- name: "Cleanup namespace"
|
||||
k8s:
|
||||
|
||||
Reference in New Issue
Block a user