diff --git a/build/ansible-runner/Dockerfile b/build/ansible-runner/Dockerfile index cdf9b5688b8..a1b96b38e2a 100644 --- a/build/ansible-runner/Dockerfile +++ b/build/ansible-runner/Dockerfile @@ -9,8 +9,8 @@ RUN rm -rf /var/lib/apt/lists/* && \ apt-get install -y python-minimal python-pip netcat iproute2 jq sshpass \ curl openssh-client -#Installing ansible -RUN pip install ansible==2.7.3 +#Installing ansible and dependencies for k8s module +RUN pip install ansible==2.7.3 openshift jmespath RUN touch /mnt/parameters.yml diff --git a/chaoslib/litmus/kill_random_pod.yml b/chaoslib/litmus/kill_random_pod.yml new file mode 100644 index 00000000000..56cf73977e2 --- /dev/null +++ b/chaoslib/litmus/kill_random_pod.yml @@ -0,0 +1,34 @@ +- 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 == ''" + +- name: Wait for the interval timer + pause: + seconds: "{{c_interval}}" \ No newline at end of file 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