mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-06-10 10:36:16 +00:00
add support for check_mode for modules k8s_scale and k8s_rollback (#255)
k8s_scale, k8s_rollback - add support for check_mode SUMMARY closes #243 and #244 ISSUE TYPE Bugfix Pull Request COMPONENT NAME k8s_scale k8s_rollback ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None> Reviewed-by: Mike Graves <mgraves@redhat.com>
This commit is contained in:
@@ -8,18 +8,12 @@
|
||||
k8s:
|
||||
name: "{{ namespace }}"
|
||||
kind: Namespace
|
||||
api_version: v1
|
||||
apply: no
|
||||
register: output
|
||||
|
||||
- name: show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Create a deployment
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: 30
|
||||
inline: &deploy
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -43,11 +37,7 @@
|
||||
image: nginx:1.17
|
||||
ports:
|
||||
- containerPort: 80
|
||||
register: output
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Crash the existing deployment
|
||||
k8s:
|
||||
@@ -77,7 +67,47 @@
|
||||
ports:
|
||||
- containerPort: 80
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
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:
|
||||
@@ -85,12 +115,24 @@
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
when: output.failed
|
||||
register: output
|
||||
register: result
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
- 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:
|
||||
@@ -139,16 +181,12 @@
|
||||
- name: varlibdockercontainers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
register: output
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Crash the existing DaemonSet
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
wait_timeout: 30
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
@@ -192,8 +230,44 @@
|
||||
- name: varlibdockercontainers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
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:
|
||||
@@ -201,12 +275,24 @@
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
when: output.failed
|
||||
register: output
|
||||
register: result
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user