From ee0d9c542861dc0315b84ca02e1b2308a185cbc7 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Thu, 5 Sep 2024 05:53:28 +0200 Subject: [PATCH] remove-etcd-node: cleanups, correct change semantics --- playbooks/remove_node.yml | 3 ++- roles/remove-node/remove-etcd-node/tasks/main.yml | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/playbooks/remove_node.yml b/playbooks/remove_node.yml index 469b32632..3bb6d9981 100644 --- a/playbooks/remove_node.yml +++ b/playbooks/remove_node.yml @@ -30,7 +30,8 @@ roles: - { role: kubespray-defaults, when: reset_nodes | default(True) | bool } - { role: remove-node/pre-remove, tags: pre-remove } - - { role: remove-node/remove-etcd-node } + - role: remove-node/remove-etcd-node + when: "'etcd' in group_names" - { role: reset, tags: reset, when: reset_nodes | default(True) | bool } # Currently cannot remove first control plane node or first etcd node diff --git a/roles/remove-node/remove-etcd-node/tasks/main.yml b/roles/remove-node/remove-etcd-node/tasks/main.yml index 484231525..4b845ff6c 100644 --- a/roles/remove-node/remove-etcd-node/tasks/main.yml +++ b/roles/remove-node/remove-etcd-node/tasks/main.yml @@ -4,12 +4,12 @@ {{ kubectl }} get nodes {{ node }} -o jsonpath-as-json='{.status.addresses[?(@.type=="InternalIP")].address}' register: k8s_node_ips + changed_when: false when: - - groups['kube_control_plane'] | length > 0 - - ('etcd' in group_names) - - ip is not defined - - access_ip is not defined - delegate_to: "{{ groups['etcd'] | first }}" + - groups['kube_control_plane'] | length > 0 + - ip is not defined + - access_ip is not defined + delegate_to: "{{ groups['kube_control_plane'] | first }}" - name: Remove etcd member from cluster environment: @@ -19,7 +19,6 @@ ETCDCTL_CACERT: "{{ kube_cert_dir + '/etcd/ca.crt' if etcd_deployment_type == 'kubeadm' else etcd_cert_dir + '/ca.pem' }}" ETCDCTL_ENDPOINTS: "https://127.0.0.1:2379" delegate_to: "{{ groups['etcd'] | first }}" - when: ('etcd' in group_names) block: - name: Lookup members infos command: "{{ bin_dir }}/etcdctl member list" @@ -37,3 +36,5 @@ - member - remove - "{{ ((etcd_members.stdout_lines | select('contains', '//' + node_ip + ':'))[0] | split(','))[0] }}" + register: etcd_removal_output + changed_when: "'Removed member' in etcd_removal_output.stdout"