mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-08 14:02:38 +00:00
[backport/2.2] Move integration test suite from molecule to ansible-test (#392)
Move integration test suite from molecule to ansible-test
SUMMARY
molecule has been replaced with ansible-test
some test cases have been updated
k8s_apply : remove duplicated tasks increasing the running time of the test
helm: use different namespaces for different test cases in order to wait for the namespace deletion before moving to the next test.
all: remove wait: yes at the end of each test when deleting namespace, the role used to create namespace will ensure that it is deleted before if existing.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
integration testing
Reviewed-by: Mike Graves mgraves@redhat.com
Reviewed-by: Gonéri Le Bouder goneri@lebouder.net
Reviewed-by: None
(cherry picked from commit fd61f8b)
SUMMARY
ISSUE TYPE
Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION
This commit is contained in:
121
tests/integration/targets/k8s_log/tasks/main.yml
Normal file
121
tests/integration/targets/k8s_log/tasks/main.yml
Normal file
@@ -0,0 +1,121 @@
|
||||
---
|
||||
- block:
|
||||
- name: create hello-world deployment
|
||||
k8s:
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: hello-world
|
||||
namespace: "{{ test_namespace }}"
|
||||
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
|
||||
k8s_log:
|
||||
api_version: apps/v1
|
||||
kind: Deployment
|
||||
namespace: "{{ test_namespace }}"
|
||||
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
|
||||
k8s_log:
|
||||
namespace: "{{ test_namespace }}"
|
||||
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: "{{ test_namespace }}"
|
||||
label_selectors:
|
||||
- 'app=hello-world'
|
||||
register: k8s_log_pods
|
||||
|
||||
- name: retrieve the log directly with the pod name
|
||||
k8s_log:
|
||||
namespace: "{{ test_namespace }}"
|
||||
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 }}'
|
||||
|
||||
- name: Create a job that calculates 7
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
wait_condition:
|
||||
type: Complete
|
||||
status: 'True'
|
||||
definition:
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: int-log
|
||||
namespace: "{{ test_namespace }}"
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: busybox
|
||||
image: busybox
|
||||
command: ["echo", "7"]
|
||||
restartPolicy: Never
|
||||
backoffLimit: 4
|
||||
|
||||
- name: retrieve logs from the job
|
||||
k8s_log:
|
||||
api_version: batch/v1
|
||||
kind: Job
|
||||
namespace: "{{ test_namespace }}"
|
||||
name: int-log
|
||||
register: job_logs
|
||||
|
||||
- name: verify the log was successfully retrieved
|
||||
assert:
|
||||
that: job_logs.log_lines[0] == "7"
|
||||
|
||||
always:
|
||||
- name: ensure that namespace is removed
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: "{{ test_namespace }}"
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
Reference in New Issue
Block a user