2018-03-05 15:02:47 +08:00
|
|
|
---
|
2021-03-26 23:48:43 +08:00
|
|
|
- name: remove-node | List nodes
|
2021-04-09 03:24:02 +08:00
|
|
|
command: >-
|
2022-01-05 18:26:32 +08:00
|
|
|
{{ kubectl }} get nodes -o go-template={% raw %}'{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'{% endraw %}
|
2021-01-16 05:17:43 +08:00
|
|
|
register: nodes
|
2023-01-03 21:03:32 +08:00
|
|
|
when:
|
|
|
|
- groups['kube_control_plane'] | length > 0
|
2021-03-24 08:26:05 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
2021-01-16 05:17:43 +08:00
|
|
|
changed_when: false
|
|
|
|
run_once: true
|
|
|
|
|
2020-07-27 21:24:17 +08:00
|
|
|
- name: remove-node | Drain node except daemonsets resource # noqa 301
|
2018-03-05 15:02:47 +08:00
|
|
|
command: >-
|
2022-01-05 18:26:32 +08:00
|
|
|
{{ kubectl }} drain
|
2018-03-05 15:02:47 +08:00
|
|
|
--force
|
|
|
|
--ignore-daemonsets
|
|
|
|
--grace-period {{ drain_grace_period }}
|
|
|
|
--timeout {{ drain_timeout }}
|
2022-01-04 23:10:53 +08:00
|
|
|
--delete-emptydir-data {{ kube_override_hostname|default(inventory_hostname) }}
|
2023-01-03 21:03:32 +08:00
|
|
|
when:
|
|
|
|
- groups['kube_control_plane'] | length > 0
|
|
|
|
# ignore servers that are not nodes
|
|
|
|
- kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines
|
2020-10-29 03:55:56 +08:00
|
|
|
register: result
|
2020-12-30 23:15:49 +08:00
|
|
|
failed_when: result.rc != 0 and not allow_ungraceful_removal
|
2021-03-24 08:26:05 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
2021-01-16 05:17:43 +08:00
|
|
|
until: result.rc == 0 or allow_ungraceful_removal
|
|
|
|
retries: "{{ drain_retries }}"
|
|
|
|
delay: "{{ drain_retry_delay_seconds }}"
|
2022-05-11 00:57:43 +08:00
|
|
|
|
|
|
|
- name: remove-node | Wait until Volumes will be detached from the node
|
|
|
|
command: >-
|
|
|
|
{{ kubectl }} get volumeattachments -o go-template={% raw %}'{{ range .items }}{{ .spec.nodeName }}{{ "\n" }}{{ end }}'{% endraw %}
|
|
|
|
register: nodes_with_volumes
|
|
|
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
|
|
|
changed_when: false
|
|
|
|
until: not (kube_override_hostname|default(inventory_hostname) in nodes_with_volumes.stdout_lines)
|
|
|
|
retries: 3
|
|
|
|
delay: "{{ drain_grace_period }}"
|
|
|
|
when:
|
2023-01-03 21:03:32 +08:00
|
|
|
- groups['kube_control_plane'] | length > 0
|
2022-05-11 00:57:43 +08:00
|
|
|
- not allow_ungraceful_removal
|
|
|
|
- kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines
|