Skip to content

Commit

Permalink
Fix recover-quorum play executed when quorum is already here
Browse files Browse the repository at this point in the history
  • Loading branch information
floryut authored and CI committed Jul 10, 2020
1 parent ef90bb3 commit 15c3271
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion roles/recover_control_plane/etcd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
when:
- groups['broken_etcd']

# When there is an error, everything is printed in stderr_lines, even "is healthy" messages.
- 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 }}"
has_quorum: "{{ etcd_endpoint_health.stderr_lines | select('match', '.*is healthy.*') | list | length >= etcd_endpoint_health.stderr_lines | select('match', '.*is unhealthy.*') | list | length }}"

- include_tasks: recover_lost_quorum.yml
when:
Expand Down
12 changes: 10 additions & 2 deletions roles/recover_control_plane/etcd/tasks/recover_lost_quorum.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
- name: Save etcd snapshot
shell: "{{ bin_dir }}/etcdctl --cacert {{ etcd_cert_dir }}/ca.pem --cert {{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem --key {{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem snapshot save /tmp/snapshot.db"
shell: "{{ bin_dir }}/etcdctl snapshot save /tmp/snapshot.db"
environment:
- ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
- ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
- ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
- ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses.split(',') | first }}"
- ETCDCTL_API: 3
when: etcd_snapshot is not defined

Expand All @@ -22,8 +26,12 @@
state: absent

- name: Restore etcd snapshot
shell: "{{ bin_dir }}/etcdctl --cacert {{ etcd_cert_dir }}/ca.pem --cert {{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem --key {{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem snapshot restore /tmp/snapshot.db --name {{ etcd_member_name }} --initial-cluster {{ etcd_member_name }}={{ etcd_peer_url }} --initial-cluster-token k8s_etcd --initial-advertise-peer-urls {{ etcd_peer_url }} --data-dir {{ etcd_data_dir }}"
shell: "{{ bin_dir }}/etcdctl snapshot restore /tmp/snapshot.db --name {{ etcd_member_name }} --initial-cluster {{ etcd_member_name }}={{ etcd_peer_url }} --initial-cluster-token k8s_etcd --initial-advertise-peer-urls {{ etcd_peer_url }} --data-dir {{ etcd_data_dir }}"
environment:
- ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
- ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
- ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
- ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
- ETCDCTL_API: 3

- name: Remove etcd snapshot
Expand Down

0 comments on commit 15c3271

Please sign in to comment.