Skip removing nodes if cluster is not set

This commit is contained in:
Ho Kim 2022-10-17 13:30:44 +00:00
parent 5ad1d9db5e
commit 7de885f899
No known key found for this signature in database
GPG key ID: 92D99E8FE190A578
3 changed files with 12 additions and 4 deletions

View file

@ -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 }}"
when:
- groups['kube_control_plane'] | length > 0
# ignore servers that are not nodes # ignore servers that are not nodes
when: inventory_hostname in groups['k8s_cluster'] and kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines - 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 }}"

View file

@ -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) }}
when:
- groups['kube_control_plane'] | length > 0
# ignore servers that are not nodes # ignore servers that are not nodes
when: kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines - 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

View file

@ -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