Skip to content

Commit

Permalink
(refactor) add ability to perform group kill of pod (#972)
Browse files Browse the repository at this point in the history
Signed-off-by: ksatchit <[email protected]>
  • Loading branch information
Karthik Satchitanand authored and gprasath committed Dec 9, 2019
1 parent 0036a40 commit f0c542b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
41 changes: 35 additions & 6 deletions chaoslib/litmus/kill_random_pod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,47 @@
- "{{ app_label }}"
register: pod_list

- name: Select a random pod to kill
- name: Initialize deletion list
set_fact:
app_pod: "{{ pod_list.resources | random | json_query('metadata.name') }}"
target_pod_list: []

when: app_pod_name is undefined or app_pod_name == ''
- block:

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

- name: Construct the deletion list with single random pod
set_fact:
target_pod_list: "{{ target_pod_list + [app_pod_random] }}"

- set_fact:
app_pod: "{{ target_pod_list | join(' ') }}"

when: "not kill_count or kill_count == ''"

- block:

- name: Add elements into target pod group list
set_fact:
target_pod_list: "{{ target_pod_list + [resource | json_query('metadata.name')] }}"
loop: "{{ pod_list.resources }}"
loop_control:
loop_var: resource

- set_fact:
app_pod: "{{ target_pod_list[0:(kill_count|int)] | join(' ') }}"

when: "kill_count is defined and kill_count != ''"

when: not app_pod_name or app_pod_name == ''

- block:
- name: Record app pod
set_fact:
app_pod: "{{ app_pod_name }}"

when: app_pod_name is defined and app_pod_name != ''
when: "app_pod_name is defined and app_pod_name != ''"

- debug:
msg: "Killing pod {{ app_pod }}"
Expand All @@ -29,15 +58,15 @@
args:
executable: /bin/bash
register: result
when: "c_force == 'true'"
when: "c_force is defined and c_force == 'true'"

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

- name: Wait for the interval timer
pause:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
a_ns: "{{ lookup('env','APP_NAMESPACE') }}"
a_label: "{{ lookup('env','APP_LABEL') }}"
a_kind: "{{ lookup('env','APP_KIND') }}"
kill_count: "{{ lookup('env','KILL_COUNT') }}"


tasks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
c_interval: "{{ lookup('env','CHAOS_INTERVAL') }}"
c_force: "{{ lookup('env','FORCE') }}"
c_lib: "{{ lookup('env','LIB') }}"
kill_count: "{{ lookup('env','KILL_COUNT') }}"
kafka_instance: "{{ lookup('env','KAFKA_INSTANCE_NAME') }}"
kafka_ns: "{{ lookup('env','KAFKA_NAMESPACE') }}"
kafka_label: "{{ lookup('env','KAFKA_LABEL') }}"
Expand Down

0 comments on commit f0c542b

Please sign in to comment.