Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (56 sloc) 2 KB
- block:
- name: Get a list of all pods from given namespace
k8s_facts:
kind: Pod
namespace: "{{ app_ns }}"
label_selectors:
- "{{ app_label }}"
register: pod_list
- name: Initialize deletion list
set_fact:
target_pod_list: []
- 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: "kill_count is not defined 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: "app_pod_name is not defined 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 != ''"
- debug:
msg: "Killing pod {{ app_pod }}"
- name: Force Kill application pod
shell: |
kubectl delete pod -n {{ app_ns }} --force --grace-period=0 --wait=false {{ app_pod }}
args:
executable: /bin/bash
register: result
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 is not defined or c_force == 'false' or c_force == ''"
- name: Wait for the interval timer
pause:
seconds: "{{ c_interval }}"
You can’t perform that action at this time.