mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-08 14:02:38 +00:00
Update test variable name and k8s_exec version_added attribute
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
---
|
---
|
||||||
- vars:
|
- vars:
|
||||||
ns: k8s-exec
|
exec_namespace: k8s-exec
|
||||||
pod: sleep-pod
|
pod: sleep-pod
|
||||||
pod_def:
|
exec_pod_definition:
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
metadata:
|
||||||
name: "{{ pod }}"
|
name: "{{ pod }}"
|
||||||
namespace: "{{ ns }}"
|
namespace: "{{ exec_namespace }}"
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: sleeper
|
- name: sleeper
|
||||||
@@ -15,36 +15,37 @@
|
|||||||
command: ["sleep", "infinity"]
|
command: ["sleep", "infinity"]
|
||||||
|
|
||||||
block:
|
block:
|
||||||
- name: Ensure that k8s-log namespace exists
|
- name: "Ensure that {{ exec_namespace }} namespace exists"
|
||||||
k8s:
|
k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: "{{ ns }}"
|
name: "{{ exec_namespace }}"
|
||||||
|
|
||||||
- name: Create a pod
|
- name: "Create a pod"
|
||||||
k8s:
|
k8s:
|
||||||
definition: "{{ pod_def }}"
|
definition: "{{ exec_pod_definition }}"
|
||||||
wait: yes
|
wait: yes
|
||||||
wait_sleep: 1
|
wait_sleep: 1
|
||||||
wait_timeout: 30
|
wait_timeout: 30
|
||||||
|
|
||||||
- name: Execute a command
|
- name: "Execute a command"
|
||||||
k8s_exec:
|
k8s_exec:
|
||||||
pod: "{{ pod }}"
|
pod: "{{ pod }}"
|
||||||
namespace: "{{ ns }}"
|
namespace: "{{ exec_namespace }}"
|
||||||
command: cat /etc/resolv.conf
|
command: cat /etc/resolv.conf
|
||||||
register: output
|
register: output
|
||||||
|
|
||||||
- name: Show k8s_exec output
|
- name: "Show k8s_exec output"
|
||||||
debug:
|
debug:
|
||||||
var: output
|
var: output
|
||||||
|
|
||||||
- name: Assert k8s_exec output is correct
|
- name: "Assert k8s_exec output is correct"
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "'nameserver' in output.stdout"
|
- "'nameserver' in output.stdout"
|
||||||
|
|
||||||
- name: Cleanup namespace
|
always:
|
||||||
|
- name: "Cleanup namespace"
|
||||||
k8s:
|
k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: "{{ ns }}"
|
name: "{{ exec_namespace }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|||||||
2
plugins/modules/k8s_exec.py
Normal file → Executable file
2
plugins/modules/k8s_exec.py
Normal file → Executable file
@@ -16,7 +16,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
module: k8s_exec
|
module: k8s_exec
|
||||||
short_description: Execute command in Pod
|
short_description: Execute command in Pod
|
||||||
version_added: "2.10"
|
version_added: "1.0.0"
|
||||||
author: "Tristan de Cacqueray (@tristanC)"
|
author: "Tristan de Cacqueray (@tristanC)"
|
||||||
description:
|
description:
|
||||||
- Use the Kubernetes Python client to execute command on K8s pods.
|
- Use the Kubernetes Python client to execute command on K8s pods.
|
||||||
|
|||||||
Reference in New Issue
Block a user