(feat): Added rescue block in pod-delete by powerseal lib (#1085)

Signed-off-by: shubhamchaudhary <shubham.chaudhary@mayadata.io>

Co-authored-by: Amit Bhatt <33670159+amitbhatt818@users.noreply.github.com>
This commit is contained in:
Shubham Chaudhary 2020-01-09 17:02:26 +05:30 committed by Chandan Kumar
parent a0b92ea50d
commit 2ec1f03f53
1 changed files with 67 additions and 39 deletions

View File

@ -1,44 +1,72 @@
- name: Generate the powerfulseal deployment spec from template - block:
template:
src: /chaoslib/powerfulseal/powerfulseal.j2 - name: Generate the powerfulseal deployment spec from template
dest: powerfulseal.yml template:
src: /chaoslib/powerfulseal/powerfulseal.j2
dest: powerfulseal.yml
- name: Setup powerfulseal to initiate random pod chaos - name: Setup powerfulseal to initiate random pod chaos
shell: shell:
kubectl apply -f powerfulseal.yml -n {{ a_ns }} kubectl apply -f powerfulseal.yml -n {{ a_ns }}
args: args:
executable: /bin/bash executable: /bin/bash
register: result register: deployment_result
failed_when: "result.rc != 0" failed_when: "deployment_result.rc != 0"
- name: Confirm that powerfulseal pod is running - name: Confirm that powerfulseal pod is running
shell: > shell: >
kubectl get pod -l name=powerfulseal --no-headers -n {{ a_ns }} kubectl get pod -l name=powerfulseal --no-headers -n {{ a_ns }}
args: args:
executable: /bin/bash executable: /bin/bash
register: result register: result
until: "'Running' in result.stdout" until: "'Running' in result.stdout"
delay: 1 delay: 1
retries: 90 retries: 90
- name: Wait for chaos duration - name: Wait for chaos duration
wait_for: timeout={{ c_duration }} wait_for: timeout={{ c_duration }}
- name: Tear down the powerfulseal deployment - name: Tear down the powerfulseal deployment
shell: shell:
kubectl delete -f powerfulseal.yml -n {{ a_ns }} kubectl delete -f powerfulseal.yml -n {{ a_ns }}
args: args:
executable: /bin/bash executable: /bin/bash
register: result register: result
failed_when: "result.rc != 0" failed_when: "result.rc != 0"
- name: Confirm that powerfulseal pod is cleaned up - name: Confirm that powerfulseal pod is cleaned up
shell: > k8s_facts:
kubectl get pod -l name=powerfulseal --no-headers -n {{ a_ns }} kind: Deployment
args: label_selectors:
executable: /bin/bash - name=powerfulseal
register: result register: resource_deployment
until: "'Running' not in result.stdout" until: "resource_deployment.resources | length < 1"
delay: 1 delay: 1
retries: 120 retries: 120
rescue:
- block:
- name: Tear down the powerfulseal deployment
shell: >
kubectl delete -f powerfulseal.yml -n {{ a_ns }}
args:
executable: /bin/bash
when: deployment_result.rc == 0
- name: Confirm that powerfulseal pod is cleaned up
k8s_facts:
kind: Deployment
label_selectors:
- name=powerfulseal
register: resource_deployment
until: "resource_deployment.resources | length < 1"
delay: 1
retries: 120
when: "deployment_result is defined"
- fail:
msg: "pod_failure_by_powerfulseal lib failed"
when: true