You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

43 lines
1.7 KiB

---
- name: Remove-node | List nodes
command: >-
{{ kubectl }} get nodes -o go-template={% raw %}'{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'{% endraw %}
register: nodes
when:
- groups['kube_control_plane'] | length > 0
delegate_to: "{{ groups['kube_control_plane'] | first }}"
changed_when: false
run_once: true
- name: Remove-node | Drain node except daemonsets resource
command: >-
{{ kubectl }} drain
--force
--ignore-daemonsets
--grace-period {{ drain_grace_period }}
--timeout {{ drain_timeout }}
--delete-emptydir-data {{ kube_override_hostname | default(inventory_hostname) }}
when:
- groups['kube_control_plane'] | length > 0
# ignore servers that are not nodes
- kube_override_hostname | default(inventory_hostname) in nodes.stdout_lines
register: result
failed_when: result.rc != 0 and not allow_ungraceful_removal
delegate_to: "{{ groups['kube_control_plane'] | first }}"
until: result.rc == 0 or allow_ungraceful_removal
retries: "{{ drain_retries }}"
delay: "{{ drain_retry_delay_seconds }}"
- 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:
- groups['kube_control_plane'] | length > 0
- not allow_ungraceful_removal
- kube_override_hostname | default(inventory_hostname) in nodes.stdout_lines