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.

69 lines
2.0 KiB

  1. ---
  2. # Node Ready: type = ready, status = True
  3. # Node NotReady: type = ready, status = Unknown
  4. - name: See if node is in ready state
  5. shell: >-
  6. {{ bin_dir }}/kubectl get node {{ inventory_hostname }}
  7. -o jsonpath='{ range .status.conditions[?(@.type == "Ready")].status }{ @ }{ end }'
  8. register: kubectl_node_ready
  9. delegate_to: "{{ groups['kube-master'][0] }}"
  10. failed_when: false
  11. changed_when: false
  12. # SchedulingDisabled: unschedulable = true
  13. # else unschedulable key doesn't exist
  14. - name: See if node is schedulable
  15. shell: >-
  16. {{ bin_dir }}/kubectl get node {{ inventory_hostname }}
  17. -o jsonpath='{ .spec.unschedulable }'
  18. register: kubectl_node_schedulable
  19. delegate_to: "{{ groups['kube-master'][0] }}"
  20. failed_when: false
  21. changed_when: false
  22. - name: Set if node needs cordoning
  23. set_fact:
  24. needs_cordoning: >-
  25. {% if kubectl_node_ready.stdout == "True" and not kubectl_node_schedulable.stdout -%}
  26. true
  27. {%- else -%}
  28. false
  29. {%- endif %}
  30. - name: Cordon node
  31. command: "{{ bin_dir }}/kubectl cordon {{ inventory_hostname }}"
  32. delegate_to: "{{ groups['kube-master'][0] }}"
  33. when: needs_cordoning
  34. - name: Check kubectl version
  35. command: "{{ bin_dir }}/kubectl version --client --short"
  36. register: kubectl_version
  37. delegate_to: "{{ groups['kube-master'][0] }}"
  38. run_once: yes
  39. changed_when: false
  40. when:
  41. - drain_nodes
  42. - needs_cordoning
  43. - drain_pod_selector
  44. - name: Ensure minimum version for drain label selector if necessary
  45. assert:
  46. that: "kubectl_version.stdout.split(' ')[-1] is version('v1.10.0', '>=')"
  47. when:
  48. - drain_nodes
  49. - needs_cordoning
  50. - drain_pod_selector
  51. - name: Drain node
  52. command: >-
  53. {{ bin_dir }}/kubectl drain
  54. --force
  55. --ignore-daemonsets
  56. --grace-period {{ drain_grace_period }}
  57. --timeout {{ drain_timeout }}
  58. --delete-local-data {{ inventory_hostname }}
  59. {% if drain_pod_selector %}--pod-selector '{{ drain_pod_selector }}'{% endif %}
  60. delegate_to: "{{ groups['kube-master'][0] }}"
  61. when:
  62. - drain_nodes
  63. - needs_cordoning