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

  1. ---
  2. - name: Remove-node | List nodes
  3. command: >-
  4. {{ kubectl }} get nodes -o go-template={% raw %}'{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'{% endraw %}
  5. register: nodes
  6. when:
  7. - groups['kube_control_plane'] | length > 0
  8. delegate_to: "{{ groups['kube_control_plane'] | first }}"
  9. changed_when: false
  10. run_once: true
  11. - name: Remove-node | Drain node except daemonsets resource
  12. command: >-
  13. {{ kubectl }} drain
  14. --force
  15. --ignore-daemonsets
  16. --grace-period {{ drain_grace_period }}
  17. --timeout {{ drain_timeout }}
  18. --delete-emptydir-data {{ kube_override_hostname | default(inventory_hostname) }}
  19. when:
  20. - groups['kube_control_plane'] | length > 0
  21. # ignore servers that are not nodes
  22. - kube_override_hostname | default(inventory_hostname) in nodes.stdout_lines
  23. register: result
  24. failed_when: result.rc != 0 and not allow_ungraceful_removal
  25. delegate_to: "{{ groups['kube_control_plane'] | first }}"
  26. until: result.rc == 0 or allow_ungraceful_removal
  27. retries: "{{ drain_retries }}"
  28. delay: "{{ drain_retry_delay_seconds }}"
  29. - name: Remove-node | Wait until Volumes will be detached from the node
  30. command: >-
  31. {{ kubectl }} get volumeattachments -o go-template={% raw %}'{{ range .items }}{{ .spec.nodeName }}{{ "\n" }}{{ end }}'{% endraw %}
  32. register: nodes_with_volumes
  33. delegate_to: "{{ groups['kube_control_plane'] | first }}"
  34. changed_when: false
  35. until: not (kube_override_hostname | default(inventory_hostname) in nodes_with_volumes.stdout_lines)
  36. retries: 3
  37. delay: "{{ drain_grace_period }}"
  38. when:
  39. - groups['kube_control_plane'] | length > 0
  40. - not allow_ungraceful_removal
  41. - kube_override_hostname | default(inventory_hostname) in nodes.stdout_lines