mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-04-05 18:23:03 +00:00
Add test
This commit is contained in:
@@ -26,3 +26,4 @@
|
||||
- include_tasks: tasks/waiter.yml
|
||||
- include_tasks: tasks/full.yml
|
||||
- include_tasks: tasks/exec.yml
|
||||
- include_tasks: tasks/log.yml
|
||||
|
||||
87
molecule/default/tasks/log.yml
Normal file
87
molecule/default/tasks/log.yml
Normal file
@@ -0,0 +1,87 @@
|
||||
---
|
||||
- block:
|
||||
- name: ensure that k8s-log namespace exists
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: k8s-log
|
||||
|
||||
- name: create hello-world deployment
|
||||
k8s:
|
||||
wait: yes
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: hello-world
|
||||
namespace: k8s-log
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: hello-world
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: hello-world
|
||||
spec:
|
||||
containers:
|
||||
- image: busybox
|
||||
name: hello-world
|
||||
command: ['sh']
|
||||
args: ['-c', 'while true ; do echo "hello world" && sleep 10 ; done']
|
||||
restartPolicy: Always
|
||||
|
||||
- name: retrieve the log by providing the deployment
|
||||
community.kubernetes.k8s_log:
|
||||
api_version: apps/v1
|
||||
kind: Deployment
|
||||
namespace: k8s-log
|
||||
name: hello-world
|
||||
register: deployment_log
|
||||
|
||||
- name: verify that the log can be retrieved via the deployment
|
||||
assert:
|
||||
that:
|
||||
- "'hello world' in deployment_log.log"
|
||||
- item == 'hello world' or item == ''
|
||||
with_items: '{{ deployment_log.log_lines }}'
|
||||
|
||||
- name: retrieve the log with a label selector
|
||||
community.kubernetes.k8s_log:
|
||||
namespace: k8s-log
|
||||
label_selectors:
|
||||
- 'app=hello-world'
|
||||
register: label_selector_log
|
||||
|
||||
- name: verify that the log can be retrieved via the label
|
||||
assert:
|
||||
that:
|
||||
- "'hello world' in label_selector_log.log"
|
||||
- item == 'hello world' or item == ''
|
||||
with_items: '{{ label_selector_log.log_lines }}'
|
||||
|
||||
- name: get the hello-world pod
|
||||
k8s_info:
|
||||
kind: Pod
|
||||
namespace: k8s-log
|
||||
label_selectors:
|
||||
- 'app=hello-world'
|
||||
register: k8s_log_pods
|
||||
|
||||
- name: retrieve the log directly with the pod name
|
||||
community.kubernetes.k8s_log:
|
||||
namespace: k8s-log
|
||||
name: '{{ k8s_log_pods.resources.0.metadata.name }}'
|
||||
register: pod_log
|
||||
|
||||
- name: verify that the log can be retrieved via the pod name
|
||||
assert:
|
||||
that:
|
||||
- "'hello world' in pod_log.log"
|
||||
- item == 'hello world' or item == ''
|
||||
with_items: '{{ pod_log.log_lines }}'
|
||||
always:
|
||||
- name: ensure that namespace is removed
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: k8s-log
|
||||
state: absent
|
||||
Reference in New Issue
Block a user