2018-03-05 07:02:47 +00:00
|
|
|
---
|
2021-01-15 21:17:43 +00:00
|
|
|
- name: remove-node | Set `nodes_to_drain` as empty list
|
|
|
|
set_fact:
|
|
|
|
nodes_to_drain: []
|
|
|
|
|
|
|
|
- name: remove-node | Identify nodes to drain, ignore non-cluster nodes
|
|
|
|
shell: |
|
|
|
|
set -o pipefail
|
|
|
|
{{ bin_dir }}/kubectl get nodes -o json \
|
|
|
|
| jq .items[].metadata.name \
|
|
|
|
| jq "select(. | test(\"^{{ hostvars[item]['kube_override_hostname']|default(item) }}$\"))"
|
|
|
|
loop: "{{ node.split(',') | default(groups['kube-node']) }}"
|
|
|
|
register: nodes
|
2019-05-22 06:36:05 +00:00
|
|
|
delegate_to: "{{ groups['kube-master']|first }}"
|
2021-01-15 21:17:43 +00:00
|
|
|
changed_when: false
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: remove-node | Generate list of nodes to drain
|
|
|
|
set_fact:
|
|
|
|
nodes_to_drain: "{{ nodes_to_drain }} + [ '{{ item.stdout | regex_replace('\"', '') }}' ]"
|
|
|
|
loop: "{{ nodes.results }}"
|
|
|
|
when: item.stdout | length != 0
|
2019-05-22 06:36:05 +00:00
|
|
|
run_once: true
|
2018-03-05 07:02:47 +00:00
|
|
|
|
2020-07-27 13:24:17 +00:00
|
|
|
- name: remove-node | Drain node except daemonsets resource # noqa 301
|
2018-03-05 07:02:47 +00:00
|
|
|
command: >-
|
2018-12-06 10:33:38 +00:00
|
|
|
{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf drain
|
2018-03-05 07:02:47 +00:00
|
|
|
--force
|
|
|
|
--ignore-daemonsets
|
|
|
|
--grace-period {{ drain_grace_period }}
|
|
|
|
--timeout {{ drain_timeout }}
|
2020-07-13 14:18:40 +00:00
|
|
|
--delete-local-data {{ hostvars[item]['kube_override_hostname']|default(item) }}
|
2021-01-15 21:17:43 +00:00
|
|
|
loop: "{{ nodes_to_drain }}"
|
2020-10-28 19:55:56 +00:00
|
|
|
register: result
|
2020-12-30 15:15:49 +00:00
|
|
|
failed_when: result.rc != 0 and not allow_ungraceful_removal
|
2018-06-23 06:40:59 +00:00
|
|
|
delegate_to: "{{ groups['kube-master']|first }}"
|
|
|
|
run_once: true
|
2021-01-15 21:17:43 +00:00
|
|
|
until: result.rc == 0 or allow_ungraceful_removal
|
|
|
|
retries: "{{ drain_retries }}"
|
|
|
|
delay: "{{ drain_retry_delay_seconds }}"
|