mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-06 13:02:37 +00:00
k8s_rollback: new module (#26)
This module allows user to rollback deployment and daemonsets. Signed-off-by: Julien Huon <julien@huon.email>
This commit is contained in:
217
molecule/default/tasks/rollback.yml
Normal file
217
molecule/default/tasks/rollback.yml
Normal file
@@ -0,0 +1,217 @@
|
||||
---
|
||||
- block:
|
||||
- name: Set variables
|
||||
set_fact:
|
||||
namespace: "testingrollback"
|
||||
|
||||
- name: Create a namespace
|
||||
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
|
||||
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
|
||||
register: output
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Crash the existing deployment
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
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: output
|
||||
|
||||
- name: Rolling Back the crashed deployment
|
||||
k8s_rollback:
|
||||
api_version: apps/v1
|
||||
kind: Deployment
|
||||
name: nginx-deploy
|
||||
namespace: "{{ namespace }}"
|
||||
when: output.failed
|
||||
register: output
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Create a DaemonSet
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
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
|
||||
register: output
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Crash the existing DaemonSet
|
||||
k8s:
|
||||
state: present
|
||||
wait: yes
|
||||
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
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: Rolling Back the crashed DaemonSet
|
||||
k8s_rollback:
|
||||
api_version: apps/v1
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
namespace: "{{ namespace }}"
|
||||
when: output.failed
|
||||
register: output
|
||||
|
||||
- name: Show output
|
||||
debug:
|
||||
var: output
|
||||
|
||||
always:
|
||||
- name: Delete {{ namespace }} namespace
|
||||
k8s:
|
||||
name: "{{ namespace }}"
|
||||
kind: Namespace
|
||||
api_version: v1
|
||||
state: absent
|
||||
Reference in New Issue
Block a user