fix: use boolean conditions in control-plane recovery (#13541)

Signed-off-by: Kay Yan <kay.yan@daocloud.io>
This commit is contained in:
Kay Yan
2026-09-22 04:26:09 +00:00
committed by GitHub
parent b1b5c3689c
commit 9751ea6f63
2 changed files with 12 additions and 12 deletions
@@ -8,7 +8,7 @@
retries: 6 retries: 6
delay: 10 delay: 10
changed_when: false 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 - name: Delete broken kube_control_plane nodes from cluster
command: "{{ kubectl }} delete node {{ item }}" command: "{{ kubectl }} delete node {{ item }}"
@@ -17,7 +17,7 @@
with_items: "{{ groups['broken_kube_control_plane'] }}" with_items: "{{ groups['broken_kube_control_plane'] }}"
register: delete_broken_kube_control_plane_nodes register: delete_broken_kube_control_plane_nodes
failed_when: false 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 - name: Fail if unable to delete broken kube_control_plane nodes from cluster
fail: fail:
@@ -25,5 +25,5 @@
loop: "{{ delete_broken_kube_control_plane_nodes.results }}" loop: "{{ delete_broken_kube_control_plane_nodes.results }}"
changed_when: false changed_when: false
when: when:
- groups['broken_kube_control_plane'] - groups['broken_kube_control_plane'] | length > 0
- "item.rc != 0 and not 'NotFound' in item.stderr" - "item.rc != 0 and not 'NotFound' in item.stderr"
@@ -12,24 +12,24 @@
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem" ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem" ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- name: Set healthy fact - name: Set healthy fact
set_fact: set_fact:
healthy: "{{ etcd_endpoint_health.stderr is match('Error: unhealthy cluster') }}" healthy: "{{ etcd_endpoint_health.stderr is match('Error: unhealthy cluster') }}"
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- name: Set has_quorum fact - name: Set has_quorum fact
set_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 }}" 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: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- name: Recover lost etcd quorum - name: Recover lost etcd quorum
include_tasks: recover_lost_quorum.yml include_tasks: recover_lost_quorum.yml
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- not has_quorum - not has_quorum
- name: Remove etcd data dir - name: Remove etcd data dir
@@ -41,7 +41,7 @@
ignore_errors: true # noqa ignore-errors ignore_errors: true # noqa ignore-errors
ignore_unreachable: true ignore_unreachable: true
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- has_quorum - has_quorum
- name: Delete old certificates - name: Delete old certificates
@@ -49,7 +49,7 @@
with_items: "{{ groups['broken_etcd'] }}" with_items: "{{ groups['broken_etcd'] }}"
register: delete_old_cerificates register: delete_old_cerificates
ignore_errors: true ignore_errors: true
when: groups['broken_etcd'] when: groups['broken_etcd'] | length > 0
- name: Fail if unable to delete old certificates - name: Fail if unable to delete old certificates
fail: fail:
@@ -57,7 +57,7 @@
loop: "{{ delete_old_cerificates.results }}" loop: "{{ delete_old_cerificates.results }}"
changed_when: false changed_when: false
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- "item.rc != 0 and not 'No such file or directory' in item.stderr" - "item.rc != 0 and not 'No such file or directory' in item.stderr"
- name: Get etcd cluster members - name: Get etcd cluster members
@@ -72,7 +72,7 @@
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem" ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem" ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- not healthy - not healthy
- has_quorum - has_quorum
@@ -88,7 +88,7 @@
- "{{ groups['broken_etcd'] }}" - "{{ groups['broken_etcd'] }}"
- "{{ member_list.stdout_lines }}" - "{{ member_list.stdout_lines }}"
when: when:
- groups['broken_etcd'] - groups['broken_etcd'] | length > 0
- not healthy - not healthy
- has_quorum - has_quorum
- hostvars[item[0]]['etcd_member_name'] == item[1].replace(' ', '').split(',')[2] - hostvars[item[0]]['etcd_member_name'] == item[1].replace(' ', '').split(',')[2]