Skip to content

Commit

Permalink
converted pod_failure_by_litmus to use ansible k8s module
Browse files Browse the repository at this point in the history
Signed-off-by: Jayadeep KM <[email protected]>
  • Loading branch information
kmjayadeep authored and Jayadeep KM committed Oct 9, 2019
1 parent 842a05d commit d9a6a2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
37 changes: 37 additions & 0 deletions chaoslib/litmus/kill_random_pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- name: Get a list of all pods from given namespace
k8s_facts:
kind: Pod
namespace: "{{ a_ns }}"
label_selectors:
- "{{a_label}}"
register: pod_list

- name: Select a random pod to kill
set_fact:
a_pod_to_kill: "{{ pod_list.resources | random | json_query('metadata.name') }}"

- debug:
msg: "Killing pod {{a_pod_to_kill}}"

- name: Force Kill application pod
shell: |
kubectl delete pod -n {{ a_ns }} --force --grace-period=0 --wait=false {{a_pod_to_kill}}
args:
executable: /bin/bash
register: result
when: "c_force == 'true'"

- name: Kill application pod
shell: |
kubectl delete pod -n {{ a_ns }} --grace-period=0 --wait=false {{a_pod_to_kill}}
args:
executable: /bin/bash
register: result
when: "c_force == 'false' or c_force == ''"

- debug:
var: result

- name: Wait for the interval timer
pause:
seconds: "{{c_interval}}"
21 changes: 3 additions & 18 deletions chaoslib/litmus/pod_failure_by_litmus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@
chaos_iterations: 1
when: "chaos_iterations == '0'"

- name: Kill application pods randomly for the specified duration
shell: |
kubectl get pods -l {{ a_label }} -n {{ a_ns }} --no-headers -o custom-columns=:metadata.name | shuf -n 1 | xargs kubectl delete pod -n {{ a_ns }} --force --grace-period=0 --wait=false
sleep {{ c_interval }}
args:
executable: /bin/bash
register: result
- name: Kill random pod
include: kill_random_pod.yml
with_sequence: start=1 end={{ chaos_iterations }}
when: "c_force == 'true'"

- name: Kill application pods randomly for the specified duration
shell: |
kubectl get pods -l {{ a_label }} -n {{ a_ns }} --no-headers -o custom-columns=:metadata.name | shuf -n 1 | xargs kubectl delete pod -n {{ a_ns }}
sleep {{ c_interval }}
args:
executable: /bin/bash
register: result
with_sequence: start=1 end={{ chaos_iterations }}
when: "c_force == 'false' or c_force == ''"

0 comments on commit d9a6a2f

Please sign in to comment.