Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] pod_failure_by_litmus to use ansible k8s module #824

Merged
merged 3 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions chaoslib/litmus/kill_random_pod.yml
Original file line number Diff line number Diff line change
@@ -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}}"
ksatchit marked this conversation as resolved.
Show resolved Hide resolved
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
ksatchit marked this conversation as resolved.
Show resolved Hide resolved
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 == ''"