From 04b970ca08fde40c1d2a50ec01e14c26b1e32f3b Mon Sep 17 00:00:00 2001 From: wuchunyang Date: Wed, 10 Mar 2021 23:24:20 +0800 Subject: [PATCH] Use Docker healthchecks for zun services This change enables the use of Docker healthchecks for zun services. Implements: blueprint container-health-check Change-Id: I32ffa9754820098bb4d3325b25fc7a1a624507d5 --- ansible/roles/zun/defaults/main.yml | 56 +++++++++++++++++++ ansible/roles/zun/handlers/main.yml | 4 ++ ansible/roles/zun/tasks/check-containers.yml | 1 + ...healthchecks-for-zun-b898231c54f487d5.yaml | 6 ++ 4 files changed, 67 insertions(+) create mode 100644 releasenotes/notes/implement-docker-healthchecks-for-zun-b898231c54f487d5.yaml diff --git a/ansible/roles/zun/defaults/main.yml b/ansible/roles/zun/defaults/main.yml index 62643039b5..3cdcf387c2 100644 --- a/ansible/roles/zun/defaults/main.yml +++ b/ansible/roles/zun/defaults/main.yml @@ -9,6 +9,7 @@ zun_services: image: "{{ zun_api_image_full }}" volumes: "{{ zun_api_default_volumes + zun_api_extra_volumes }}" dimensions: "{{ zun_api_dimensions }}" + healthcheck: "{{ zun_api_healthcheck }}" haproxy: zun_api: enabled: "{{ enable_zun }}" @@ -27,6 +28,7 @@ zun_services: image: "{{ zun_wsproxy_image_full }}" volumes: "{{ zun_wsproxy_default_volumes + zun_wsproxy_extra_volumes }}" dimensions: "{{ zun_wsproxy_dimensions }}" + healthcheck: "{{ zun_wsproxy_healthcheck }}" haproxy: zun_wsproxy: enabled: "{{ enable_zun }}" @@ -46,6 +48,7 @@ zun_services: privileged: True volumes: "{{ zun_compute_default_volumes + zun_compute_extra_volumes }}" dimensions: "{{ zun_compute_dimensions }}" + healthcheck: "{{ zun_compute_healthcheck }}" zun-cni-daemon: container_name: zun_cni_daemon group: zun-cni-daemon @@ -54,6 +57,7 @@ zun_services: privileged: True volumes: "{{ zun_cni_daemon_default_volumes + zun_cni_daemon_extra_volumes }}" dimensions: "{{ zun_cni_daemon_dimensions }}" + healthcheck: "{{ zun_cni_daemon_healthcheck }}" #################### ## Database @@ -91,6 +95,58 @@ zun_wsproxy_dimensions: "{{ default_container_dimensions }}" zun_compute_dimensions: "{{ default_container_dimensions }}" zun_cni_daemon_dimensions: "{{ default_container_dimensions }}" +zun_api_enable_healthchecks: "{{ enable_container_healthchecks }}" +zun_api_healthcheck_interval: "{{ default_container_healthcheck_interval }}" +zun_api_healthcheck_retries: "{{ default_container_healthcheck_retries }}" +zun_api_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}" +zun_api_healthcheck_test: ["CMD-SHELL", "healthcheck_curl http://{{ api_interface_address | put_address_in_context('url') }}:{{ zun_api_port }}"] +zun_api_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}" +zun_api_healthcheck: + interval: "{{ zun_api_healthcheck_interval }}" + retries: "{{ zun_api_healthcheck_retries }}" + start_period: "{{ zun_api_healthcheck_start_period }}" + test: "{% if zun_api_enable_healthchecks | bool %}{{ zun_api_healthcheck_test }}{% else %}NONE{% endif %}" + timeout: "{{ zun_api_healthcheck_timeout }}" + +zun_wsproxy_enable_healthchecks: "{{ enable_container_healthchecks }}" +zun_wsproxy_healthcheck_interval: "{{ default_container_healthcheck_interval }}" +zun_wsproxy_healthcheck_retries: "{{ default_container_healthcheck_retries }}" +zun_wsproxy_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}" +zun_wsproxy_healthcheck_test: ["CMD-SHELL", "healthcheck_listen zun-wsproxy {{ zun_wsproxy_port }}"] +zun_wsproxy_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}" +zun_wsproxy_healthcheck: + interval: "{{ zun_wsproxy_healthcheck_interval }}" + retries: "{{ zun_wsproxy_healthcheck_retries }}" + start_period: "{{ zun_wsproxy_healthcheck_start_period }}" + test: "{% if zun_wsproxy_enable_healthchecks | bool %}{{ zun_wsproxy_healthcheck_test }}{% else %}NONE{% endif %}" + timeout: "{{ zun_wsproxy_healthcheck_timeout }}" + +zun_compute_enable_healthchecks: "{{ enable_container_healthchecks }}" +zun_compute_healthcheck_interval: "{{ default_container_healthcheck_interval }}" +zun_compute_healthcheck_retries: "{{ default_container_healthcheck_retries }}" +zun_compute_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}" +zun_compute_healthcheck_test: ["CMD-SHELL", "healthcheck_port zun-compute {{ om_rpc_port }}"] +zun_compute_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}" +zun_compute_healthcheck: + interval: "{{ zun_compute_healthcheck_interval }}" + retries: "{{ zun_compute_healthcheck_retries }}" + start_period: "{{ zun_compute_healthcheck_start_period }}" + test: "{% if zun_compute_enable_healthchecks | bool %}{{ zun_compute_healthcheck_test }}{% else %}NONE{% endif %}" + timeout: "{{ zun_compute_healthcheck_timeout }}" + +zun_cni_daemon_enable_healthchecks: "{{ enable_container_healthchecks }}" +zun_cni_daemon_healthcheck_interval: "{{ default_container_healthcheck_interval }}" +zun_cni_daemon_healthcheck_retries: "{{ default_container_healthcheck_retries }}" +zun_cni_daemon_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}" +zun_cni_daemon_healthcheck_test: ["CMD-SHELL", "healthcheck_listen zun-cni-daemon {{ zun_cni_daemon_port }}"] +zun_cni_daemon_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}" +zun_cni_daemon_healthcheck: + interval: "{{ zun_cni_daemon_healthcheck_interval }}" + retries: "{{ zun_cni_daemon_healthcheck_retries }}" + start_period: "{{ zun_cni_daemon_healthcheck_start_period }}" + test: "{% if zun_cni_daemon_enable_healthchecks | bool %}{{ zun_cni_daemon_healthcheck_test }}{% else %}NONE{% endif %}" + timeout: "{{ zun_cni_daemon_healthcheck_timeout }}" + zun_api_default_volumes: - "{{ node_config_directory }}/zun-api/:{{ container_config_directory }}/:ro" - "/etc/localtime:/etc/localtime:ro" diff --git a/ansible/roles/zun/handlers/main.yml b/ansible/roles/zun/handlers/main.yml index 39a3ef0261..0813ccf134 100644 --- a/ansible/roles/zun/handlers/main.yml +++ b/ansible/roles/zun/handlers/main.yml @@ -12,6 +12,7 @@ privileged: "{{ service.privileged | default(False) }}" volumes: "{{ service.volumes|reject('equalto', '')|list }}" dimensions: "{{ service.dimensions }}" + healthcheck: "{{ service.healthcheck | default(omit) }}" listen: - zun-api container changed when: @@ -30,6 +31,7 @@ privileged: "{{ service.privileged | default(False) }}" volumes: "{{ service.volumes|reject('equalto', '')|list }}" dimensions: "{{ service.dimensions }}" + healthcheck: "{{ service.healthcheck | default(omit) }}" listen: - zun-wsproxy container changed when: @@ -48,6 +50,7 @@ privileged: "{{ service.privileged | default(False) }}" volumes: "{{ service.volumes|reject('equalto', '')|list }}" dimensions: "{{ service.dimensions }}" + healthcheck: "{{ service.healthcheck | default(omit) }}" listen: - zun-compute container changed when: @@ -66,6 +69,7 @@ privileged: "{{ service.privileged | default(False) }}" volumes: "{{ service.volumes|reject('equalto', '')|list }}" dimensions: "{{ service.dimensions }}" + healthcheck: "{{ service.healthcheck | default(omit) }}" listen: - zun-cni-daemon container changed when: diff --git a/ansible/roles/zun/tasks/check-containers.yml b/ansible/roles/zun/tasks/check-containers.yml index 5c28c2fc48..9de35c7a00 100644 --- a/ansible/roles/zun/tasks/check-containers.yml +++ b/ansible/roles/zun/tasks/check-containers.yml @@ -9,6 +9,7 @@ privileged: "{{ item.value.privileged | default(False) }}" volumes: "{{ item.value.volumes|reject('equalto', '')|list }}" dimensions: "{{ item.value.dimensions }}" + healthcheck: "{{ item.value.healthcheck | default(omit) }}" when: - inventory_hostname in groups[item.value.group] - item.value.enabled | bool diff --git a/releasenotes/notes/implement-docker-healthchecks-for-zun-b898231c54f487d5.yaml b/releasenotes/notes/implement-docker-healthchecks-for-zun-b898231c54f487d5.yaml new file mode 100644 index 0000000000..497fc90a95 --- /dev/null +++ b/releasenotes/notes/implement-docker-healthchecks-for-zun-b898231c54f487d5.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Implements container healthchecks for zun services. + See `blueprint + `__