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