From 9751ea6f63244e433a7a6263d9ecf381e57bb8e9 Mon Sep 17 00:00:00 2001 From: Kay Yan Date: Tue, 22 Sep 2026 12:26:09 +0800 Subject: [PATCH] fix: use boolean conditions in control-plane recovery (#13541) Signed-off-by: Kay Yan --- .../control-plane/tasks/main.yml | 6 +++--- .../recover_control_plane/etcd/tasks/main.yml | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/roles/recover_control_plane/control-plane/tasks/main.yml b/roles/recover_control_plane/control-plane/tasks/main.yml index 2dc811321..062237485 100644 --- a/roles/recover_control_plane/control-plane/tasks/main.yml +++ b/roles/recover_control_plane/control-plane/tasks/main.yml @@ -8,7 +8,7 @@ retries: 6 delay: 10 changed_when: false - when: groups['broken_kube_control_plane'] + when: groups['broken_kube_control_plane'] | length > 0 - name: Delete broken kube_control_plane nodes from cluster command: "{{ kubectl }} delete node {{ item }}" @@ -17,7 +17,7 @@ with_items: "{{ groups['broken_kube_control_plane'] }}" register: delete_broken_kube_control_plane_nodes failed_when: false - when: groups['broken_kube_control_plane'] + when: groups['broken_kube_control_plane'] | length > 0 - name: Fail if unable to delete broken kube_control_plane nodes from cluster fail: @@ -25,5 +25,5 @@ loop: "{{ delete_broken_kube_control_plane_nodes.results }}" changed_when: false when: - - groups['broken_kube_control_plane'] + - groups['broken_kube_control_plane'] | length > 0 - "item.rc != 0 and not 'NotFound' in item.stderr" diff --git a/roles/recover_control_plane/etcd/tasks/main.yml b/roles/recover_control_plane/etcd/tasks/main.yml index 6291ea36f..3aea5f028 100644 --- a/roles/recover_control_plane/etcd/tasks/main.yml +++ b/roles/recover_control_plane/etcd/tasks/main.yml @@ -12,24 +12,24 @@ ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem" ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem" when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - name: Set healthy fact set_fact: healthy: "{{ etcd_endpoint_health.stderr is match('Error: unhealthy cluster') }}" when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - name: Set has_quorum fact set_fact: has_quorum: "{{ etcd_endpoint_health.stdout_lines | select('match', '.*is healthy.*') | list | length >= etcd_endpoint_health.stderr_lines | select('match', '.*is unhealthy.*') | list | length }}" when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - name: Recover lost etcd quorum include_tasks: recover_lost_quorum.yml when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - not has_quorum - name: Remove etcd data dir @@ -41,7 +41,7 @@ ignore_errors: true # noqa ignore-errors ignore_unreachable: true when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - has_quorum - name: Delete old certificates @@ -49,7 +49,7 @@ with_items: "{{ groups['broken_etcd'] }}" register: delete_old_cerificates ignore_errors: true - when: groups['broken_etcd'] + when: groups['broken_etcd'] | length > 0 - name: Fail if unable to delete old certificates fail: @@ -57,7 +57,7 @@ loop: "{{ delete_old_cerificates.results }}" changed_when: false when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - "item.rc != 0 and not 'No such file or directory' in item.stderr" - name: Get etcd cluster members @@ -72,7 +72,7 @@ ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem" ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem" when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - not healthy - has_quorum @@ -88,7 +88,7 @@ - "{{ groups['broken_etcd'] }}" - "{{ member_list.stdout_lines }}" when: - - groups['broken_etcd'] + - groups['broken_etcd'] | length > 0 - not healthy - has_quorum - hostvars[item[0]]['etcd_member_name'] == item[1].replace(' ', '').split(',')[2]