Skip to content

Commit

Permalink
Restart etcd if the etcd version changes (#8556)
Browse files Browse the repository at this point in the history
Signed-off-by: Mac Chaffee <[email protected]>
  • Loading branch information
mac-chaffee authored Mar 12, 2022
1 parent 4b6892e commit 512d5e3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
24 changes: 24 additions & 0 deletions roles/etcd/tasks/install_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
- import_tasks: install_etcdctl_docker.yml
when: etcd_cluster_setup

- name: Get currently-deployed etcd version
shell: "{{ docker_bin_dir }}/docker ps --filter='name={{ etcd_member_name }}' --format='{{ '{{ .Image }}' }}'"
register: etcd_current_docker_image
when: etcd_cluster_setup

- name: Get currently-deployed etcd-events version
shell: "{{ docker_bin_dir }}/docker ps --filter='name={{ etcd_member_name }}-events' --format='{{ '{{ .Image }}' }}'"
register: etcd_events_current_docker_image
when: etcd_events_cluster_setup

- name: Restart etcd if necessary
command: /bin/true
notify: restart etcd
when:
- etcd_cluster_setup
- etcd_image_tag not in etcd_current_docker_image.stdout|default('')

- name: Restart etcd-events if necessary
command: /bin/true
notify: restart etcd-events
when:
- etcd_events_cluster_setup
- etcd_image_tag not in etcd_events_current_docker_image.stdout|default('')

- name: Install etcd launch script
template:
src: etcd.j2
Expand Down
21 changes: 21 additions & 0 deletions roles/etcd/tasks/install_host.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
---
- name: Get currently-deployed etcd version
command: "{{ bin_dir }}/etcd --version"
register: etcd_current_host_version
# There's a chance this play could run before etcd is installed at all
ignore_errors: true
when: etcd_cluster_setup

- name: Restart etcd if necessary
command: /bin/true
notify: restart etcd
when:
- etcd_cluster_setup
- etcd_version.lstrip('v') not in etcd_current_host_version.stdout|default('')

- name: Restart etcd-events if necessary
command: /bin/true
notify: restart etcd-events
when:
- etcd_events_cluster_setup
- etcd_version.lstrip('v') not in etcd_current_host_version.stdout|default('')

- name: install | Download etcd and etcdctl
include_tasks: "../../download/tasks/download_file.yml"
vars:
Expand Down
12 changes: 4 additions & 8 deletions roles/etcd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@
when: is_etcd_master

- name: Restart etcd if certs changed
service:
name: etcd
state: restarted
enabled: yes
command: /bin/true
notify: restart etcd
when: is_etcd_master and etcd_cluster_setup and etcd_secret_changed|default(false)

- name: Restart etcd-events if certs changed
service:
name: etcd-events
state: restarted
enabled: yes
command: /bin/true
notify: restart etcd
when: is_etcd_master and etcd_events_cluster_setup and etcd_secret_changed|default(false)

# After etcd cluster is assembled, make sure that
Expand Down

0 comments on commit 512d5e3

Please sign in to comment.