diff --git a/chaoslib/litmus/kill_random_pod.yml b/chaoslib/litmus/kill_random_pod.yml new file mode 100644 index 00000000000..5dd3931c8d9 --- /dev/null +++ b/chaoslib/litmus/kill_random_pod.yml @@ -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}}" diff --git a/chaoslib/litmus/pod_failure_by_litmus.yml b/chaoslib/litmus/pod_failure_by_litmus.yml index 3556d5a577e..95715966d3a 100644 --- a/chaoslib/litmus/pod_failure_by_litmus.yml +++ b/chaoslib/litmus/pod_failure_by_litmus.yml @@ -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 == ''" + \ No newline at end of file