From 7a86b6c73e45e5f321aa0dfdf101f286e1bb8ad9 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Tue, 19 Jul 2016 16:45:37 +0300 Subject: [PATCH] Set default etcd deployment to docker Improved docker reload command to wait for etcd to be up before proceeding. Switched reload to run restart because it can't reload if it is not guaranteed to be in running state. --- roles/etcd/defaults/main.yml | 2 +- roles/etcd/handlers/main.yml | 27 +++++++------------ roles/etcd/tasks/main.yml | 26 +++++++++--------- roles/etcd/templates/etcd-docker.service.j2 | 2 +- .../templates/etcd-proxy-docker.service.j2 | 2 +- roles/network_plugin/calico/tasks/main.yml | 7 +++-- 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/roles/etcd/defaults/main.yml b/roles/etcd/defaults/main.yml index 63f485719..e4234179f 100644 --- a/roles/etcd/defaults/main.yml +++ b/roles/etcd/defaults/main.yml @@ -3,7 +3,7 @@ etcd_version: v3.0.1 etcd_bin_dir: "{{ local_release_dir }}/etcd/etcd-{{ etcd_version }}-linux-amd64/" # Possible values: host, docker -etcd_deployment_type: "host" +etcd_deployment_type: "docker" etcd_image_repo: "quay.io/coreos/etcd" diff --git a/roles/etcd/handlers/main.yml b/roles/etcd/handlers/main.yml index cf0aaa5bf..cc22b1c72 100644 --- a/roles/etcd/handlers/main.yml +++ b/roles/etcd/handlers/main.yml @@ -3,42 +3,35 @@ command: /bin/true notify: - reload systemd - - start etcd - reload etcd + - wait for etcd up - name: restart etcd-proxy command: /bin/true notify: - reload systemd - - start etcd-proxy - reload etcd-proxy + - wait for etcd up - name: reload systemd command: systemctl daemon-reload when: ansible_service_mgr == "systemd" -- name: start etcd - service: - name: etcd - enabled: yes - state: started - when: is_etcd_master - -- name: start etcd-proxy - service: - name: etcd-proxy - enabled: yes - state: started - when: is_etcd_proxy +- name: wait for etcd up + uri: url=http://localhost:2379/health + register: result + until: result.status == 200 + retries: 10 + delay: 5 - name: reload etcd service: name: etcd - state: "{{ 'restarted' if etcd_deployment_type == 'host' else 'reloaded' }}" + state: restarted when: is_etcd_master - name: reload etcd-proxy service: name: etcd-proxy - state: "{{ 'restarted' if etcd_deployment_type == 'host' else 'reloaded' }}" + state: restarted when: is_etcd_proxy diff --git a/roles/etcd/tasks/main.yml b/roles/etcd/tasks/main.yml index 34d94ab73..f2d31badb 100644 --- a/roles/etcd/tasks/main.yml +++ b/roles/etcd/tasks/main.yml @@ -5,19 +5,6 @@ - include: configure.yml - include: refresh_config.yml -- name: Restart etcd if binary changed - command: /bin/true - notify: restart etcd - when: etcd_deployment_type == "host" and etcd_copy.stdout_lines and is_etcd_master - -- name: Restart etcd-proxy if binary changed - command: /bin/true - notify: restart etcd-proxy - when: etcd_deployment_type == "host" and etcd_copy.stdout_lines and is_etcd_proxy - -# Reload systemd before starting service -- meta: flush_handlers - - name: Ensure etcd is running service: name: etcd @@ -32,6 +19,19 @@ enabled: yes when: is_etcd_proxy +- name: Restart etcd if binary changed + command: /bin/true + notify: restart etcd + when: etcd_deployment_type == "host" and etcd_copy.stdout_lines and is_etcd_master + +- name: Restart etcd-proxy if binary changed + command: /bin/true + notify: restart etcd-proxy + when: etcd_deployment_type == "host" and etcd_copy.stdout_lines and is_etcd_proxy + +# Reload systemd before starting service +- meta: flush_handlers + # After etcd cluster is assembled, make sure that # initial state of the cluster is in `existing` # state insted of `new`. diff --git a/roles/etcd/templates/etcd-docker.service.j2 b/roles/etcd/templates/etcd-docker.service.j2 index a02e84c25..e196c0b59 100644 --- a/roles/etcd/templates/etcd-docker.service.j2 +++ b/roles/etcd/templates/etcd-docker.service.j2 @@ -22,7 +22,7 @@ ExecStartPre=-{{ docker_bin_dir | default("/usr/bin") }}/docker rm -f {{ etcd_me ExecReload={{ docker_bin_dir | default("/usr/bin") }}/docker restart {{ etcd_member_name | default("etcd-proxy") }} ExecStop={{ docker_bin_dir | default("/usr/bin") }}/docker stop {{ etcd_member_name | default("etcd-proxy") }} Restart=always -RestartSec=10s +RestartSec=15s [Install] WantedBy=multi-user.target diff --git a/roles/etcd/templates/etcd-proxy-docker.service.j2 b/roles/etcd/templates/etcd-proxy-docker.service.j2 index 757423bb4..98d548cce 100644 --- a/roles/etcd/templates/etcd-proxy-docker.service.j2 +++ b/roles/etcd/templates/etcd-proxy-docker.service.j2 @@ -22,7 +22,7 @@ ExecStartPre=-{{ docker_bin_dir | default("/usr/bin") }}/docker rm -f {{ etcd_pr ExecReload={{ docker_bin_dir | default("/usr/bin") }}/docker restart {{ etcd_proxy_member_name | default("etcd-proxy") }} ExecStop={{ docker_bin_dir | default("/usr/bin") }}/docker stop {{ etcd_proxy_member_name | default("etcd-proxy") }} Restart=always -RestartSec=10s +RestartSec=15s [Install] WantedBy=multi-user.target diff --git a/roles/network_plugin/calico/tasks/main.yml b/roles/network_plugin/calico/tasks/main.yml index 7e732d632..99d97b01b 100644 --- a/roles/network_plugin/calico/tasks/main.yml +++ b/roles/network_plugin/calico/tasks/main.yml @@ -38,8 +38,11 @@ changed_when: false - name: Calico | wait for etcd - wait_for: - port: 2379 + uri: url=http://localhost:2379/health + register: result + until: result.status == 200 + retries: 10 + delay: 5 when: inventory_hostname in groups['kube-master'] - name: Calico | Check if calico network pool has already been configured