mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-29 19:04:39 +00:00
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 <None>
This commit is contained in:
4
tests/integration/targets/k8s_rollback/aliases
Normal file
4
tests/integration/targets/k8s_rollback/aliases
Normal file
@@ -0,0 +1,4 @@
|
||||
k8s_rollback
|
||||
k8s
|
||||
k8s_info
|
||||
time=187
|
||||
3
tests/integration/targets/k8s_rollback/defaults/main.yml
Normal file
3
tests/integration/targets/k8s_rollback/defaults/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
test_namespace: "testingrollback"
|
||||
k8s_wait_timeout: 400
|
||||
2
tests/integration/targets/k8s_rollback/meta/main.yml
Normal file
2
tests/integration/targets/k8s_rollback/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- setup_namespace
|
||||
301
tests/integration/targets/k8s_rollback/tasks/main.yml
Normal file
301
tests/integration/targets/k8s_rollback/tasks/main.yml
Normal file
@@ -0,0 +1,301 @@
|
||||
---
|
||||
- block:
|
||||
- name: Set variables
|
||||
set_fact:
|
||||
namespace: "{{ test_namespace }}"
|
||||
|
||||
- name: Create a deployment
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
inline: &deploy
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deploy
|
||||
labels:
|
||||
app: nginx
|
||||
namespace: "{{ namespace }}"
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.17
|
||||
ports:
|
||||
- containerPort: 80
|
||||
|
||||
|
||||
- name: Crash the existing deployment
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deploy
|
||||
labels:
|
||||
app: nginx
|
||||
namespace: "{{ namespace }}"
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.0.23449928384992872784
|
||||
ports:
|
||||
- containerPort: 80
|
||||
ignore_errors: yes
|
||||
register: crash
|
||||
|
||||
- name: Assert that the Deployment failed
|
||||
assert:
|
||||
that:
|
||||
- crash is failed
|
||||
|
||||
- name: Read the deployment
|
||||
k8s_info:
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
register: deployment
|
||||
|
||||
- set_fact:
|
||||
failed_version: "{{ deployment.resources[0].metadata.annotations['deployment.kubernetes.io/revision'] }}"
|
||||
|
||||
- name: Rolling Back the crashed deployment (check mode)
|
||||
k8s_rollback:
|
||||
api_version: apps/v1
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Read the deployment
|
||||
k8s_info:
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
register: deployment
|
||||
|
||||
- name: Validate that Rollback using check_mode did not changed the Deployment
|
||||
assert:
|
||||
that:
|
||||
- failed_version == deployment.resources[0].metadata.annotations['deployment.kubernetes.io/revision']
|
||||
|
||||
- name: Rolling Back the crashed deployment
|
||||
k8s_rollback:
|
||||
api_version: apps/v1
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
|
||||
- name: assert rollback is changed
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Read the deployment once again
|
||||
k8s_info:
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
register: deployment
|
||||
|
||||
- name: Validate that Rollback changed the Deployment
|
||||
assert:
|
||||
that:
|
||||
- failed_version | int + 1 == deployment.resources[0].metadata.annotations['deployment.kubernetes.io/revision'] | int
|
||||
|
||||
- name: Create a DaemonSet
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
k8s-app: fluentd-logging
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
name: fluentd-elasticsearch
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
name: fluentd-elasticsearch
|
||||
spec:
|
||||
tolerations:
|
||||
- key: node-role.kubernetes.io/master
|
||||
effect: NoSchedule
|
||||
containers:
|
||||
- name: fluentd-elasticsearch
|
||||
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
|
||||
resources:
|
||||
limits:
|
||||
memory: 200Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 200Mi
|
||||
volumeMounts:
|
||||
- name: varlog
|
||||
mountPath: /var/log
|
||||
- name: varlibdockercontainers
|
||||
mountPath: /var/lib/docker/containers
|
||||
readOnly: true
|
||||
terminationGracePeriodSeconds: 30
|
||||
volumes:
|
||||
- name: varlog
|
||||
hostPath:
|
||||
path: /var/log
|
||||
- name: varlibdockercontainers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
|
||||
- name: Crash the existing DaemonSet
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
k8s-app: fluentd-logging
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
name: fluentd-elasticsearch
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
name: fluentd-elasticsearch
|
||||
spec:
|
||||
tolerations:
|
||||
- key: node-role.kubernetes.io/master
|
||||
effect: NoSchedule
|
||||
containers:
|
||||
- name: fluentd-elasticsearch
|
||||
image: quay.io/fluentd_elasticsearch/fluentd:v2734894949
|
||||
resources:
|
||||
limits:
|
||||
memory: 200Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 200Mi
|
||||
volumeMounts:
|
||||
- name: varlog
|
||||
mountPath: /var/log
|
||||
- name: varlibdockercontainers
|
||||
mountPath: /var/lib/docker/containers
|
||||
readOnly: true
|
||||
terminationGracePeriodSeconds: 30
|
||||
volumes:
|
||||
- name: varlog
|
||||
hostPath:
|
||||
path: /var/log
|
||||
- name: varlibdockercontainers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
register: crash
|
||||
ignore_errors: true
|
||||
|
||||
- name: Assert that the Daemonset failed
|
||||
assert:
|
||||
that:
|
||||
- crash is failed
|
||||
|
||||
- name: Read the crashed DaemonSet
|
||||
k8s_info:
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
|
||||
- set_fact:
|
||||
failed_version: "{{ result.resources[0].metadata.annotations['deprecated.daemonset.template.generation'] }}"
|
||||
|
||||
- name: Rolling Back the crashed DaemonSet (check_mode)
|
||||
k8s_rollback:
|
||||
api_version: apps/v1
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
check_mode: yes
|
||||
|
||||
- name: Read the DaemonSet
|
||||
k8s_info:
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
|
||||
- name: Validate that Rollback using check_mode did not changed the DaemonSet version
|
||||
assert:
|
||||
that:
|
||||
- failed_version == result.resources[0].metadata.annotations['deprecated.daemonset.template.generation']
|
||||
|
||||
- name: Rolling Back the crashed DaemonSet
|
||||
k8s_rollback:
|
||||
api_version: apps/v1
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
|
||||
- name: assert rollback is changed
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Read the DaemonSet
|
||||
k8s_info:
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
register: result
|
||||
|
||||
- name: Validate that Rollback changed the Daemonset version
|
||||
assert:
|
||||
that:
|
||||
- failed_version | int + 1 == result.resources[0].metadata.annotations['deprecated.daemonset.template.generation'] | int
|
||||
|
||||
always:
|
||||
- name: Delete {{ namespace }} namespace
|
||||
k8s:
|
||||
name: "{{ namespace }}"
|
||||
kind: Namespace
|
||||
api_version: v1
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
Reference in New Issue
Block a user