Skip removing nodes if cluster is not set (#9430)
parent
8ca0bfffe0
commit
4bc5e8d912
|
@ -2,8 +2,10 @@
|
|||
- name: remove-node | Delete node
|
||||
command: "{{ kubectl }} delete node {{ kube_override_hostname|default(inventory_hostname) }}"
|
||||
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
||||
# ignore servers that are not nodes
|
||||
when: inventory_hostname in groups['k8s_cluster'] and kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines
|
||||
when:
|
||||
- groups['kube_control_plane'] | length > 0
|
||||
# ignore servers that are not nodes
|
||||
- inventory_hostname in groups['k8s_cluster'] and kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines
|
||||
retries: "{{ delete_node_retries }}"
|
||||
# Sometimes the api-server can have a short window of indisponibility when we delete a master node
|
||||
delay: "{{ delete_node_delay_seconds }}"
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
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
|
||||
|
@ -15,8 +17,10 @@
|
|||
--grace-period {{ drain_grace_period }}
|
||||
--timeout {{ drain_timeout }}
|
||||
--delete-emptydir-data {{ kube_override_hostname|default(inventory_hostname) }}
|
||||
# ignore servers that are not nodes
|
||||
when: kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines
|
||||
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 }}"
|
||||
|
@ -34,5 +38,6 @@
|
|||
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
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
-o jsonpath='{range .status.addresses[?(@.type=="InternalIP")]}{@.address}{"\n"}{end}'
|
||||
register: remove_node_ip
|
||||
when:
|
||||
- groups['kube_control_plane'] | length > 0
|
||||
- inventory_hostname in groups['etcd']
|
||||
- ip is not defined
|
||||
- access_ip is not defined
|
||||
|
|
Loading…
Reference in New Issue