From 35e15a770a94cb9bc41aeeb3769f4fe621eebc4a Mon Sep 17 00:00:00 2001 From: LinPeiWen <591171850@qq.com> Date: Sat, 13 Mar 2021 06:22:58 +0000 Subject: [PATCH] Use Docker healthchecks for haproxy services This change enables the use of Docker healthchecks for haproxy services. Implements: blueprint container-health-check Change-Id: I4b486e9c78e9a01a0f5983b83aca00ea3a001dcc --- ansible/roles/haproxy/defaults/main.yml | 14 ++++++++++++++ ansible/roles/haproxy/handlers/main.yml | 2 ++ ansible/roles/haproxy/tasks/check-containers.yml | 1 + ...-healthchecks-for-haproxy-e222d45809a1a9a1.yaml | 6 ++++++ 4 files changed, 23 insertions(+) create mode 100644 releasenotes/notes/implement-docker-healthchecks-for-haproxy-e222d45809a1a9a1.yaml diff --git a/ansible/roles/haproxy/defaults/main.yml b/ansible/roles/haproxy/defaults/main.yml index 9db1d9d03b..ac369d48c4 100644 --- a/ansible/roles/haproxy/defaults/main.yml +++ b/ansible/roles/haproxy/defaults/main.yml @@ -10,6 +10,7 @@ haproxy_services: privileged: True volumes: "{{ haproxy_default_volumes + haproxy_extra_volumes }}" dimensions: "{{ haproxy_dimensions }}" + healthcheck: "{{ haproxy_healthcheck }}" keepalived: container_name: keepalived group: haproxy @@ -49,6 +50,19 @@ haproxy_defaults_max_connections: 10000 haproxy_dimensions: "{{ default_container_dimensions }}" keepalived_dimensions: "{{ default_container_dimensions }}" +haproxy_enable_healthchecks: "{{ enable_container_healthchecks }}" +haproxy_healthcheck_interval: "{{ default_container_healthcheck_interval }}" +haproxy_healthcheck_retries: "{{ default_container_healthcheck_retries }}" +haproxy_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}" +haproxy_healthcheck_test: ["CMD-SHELL", "healthcheck_curl http://{{ api_interface_address | put_address_in_context('url') }}:{{ haproxy_monitor_port }}"] +haproxy_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}" +haproxy_healthcheck: + interval: "{{ haproxy_healthcheck_interval }}" + retries: "{{ haproxy_healthcheck_retries }}" + start_period: "{{ haproxy_healthcheck_start_period }}" + test: "{% if haproxy_enable_healthchecks | bool %}{{ haproxy_healthcheck_test }}{% else %}NONE{% endif %}" + timeout: "{{ haproxy_healthcheck_timeout }}" + haproxy_default_volumes: - "{{ node_config_directory }}/haproxy/:{{ container_config_directory }}/:ro" - "/etc/localtime:/etc/localtime:ro" diff --git a/ansible/roles/haproxy/handlers/main.yml b/ansible/roles/haproxy/handlers/main.yml index ca94f3480f..aa7d52e25a 100644 --- a/ansible/roles/haproxy/handlers/main.yml +++ b/ansible/roles/haproxy/handlers/main.yml @@ -58,6 +58,7 @@ privileged: "{{ service.privileged | default(False) }}" volumes: "{{ service.volumes }}" dimensions: "{{ service.dimensions }}" + healthcheck: "{{ service.healthcheck | default(omit) }}" when: - kolla_action != "config" - groups.kolla_ha_is_master_False is defined @@ -136,6 +137,7 @@ privileged: "{{ service.privileged | default(False) }}" volumes: "{{ service.volumes }}" dimensions: "{{ service.dimensions }}" + healthcheck: "{{ service.healthcheck | default(omit) }}" when: - kolla_action != "config" - groups.kolla_ha_is_master_True is defined diff --git a/ansible/roles/haproxy/tasks/check-containers.yml b/ansible/roles/haproxy/tasks/check-containers.yml index f572177e91..bb19a0c804 100644 --- a/ansible/roles/haproxy/tasks/check-containers.yml +++ b/ansible/roles/haproxy/tasks/check-containers.yml @@ -8,6 +8,7 @@ image: "{{ item.value.image }}" volumes: "{{ item.value.volumes }}" dimensions: "{{ item.value.dimensions }}" + healthcheck: "{{ item.value.healthcheck | default(omit) }}" privileged: "{{ item.value.privileged | default(False) }}" when: - inventory_hostname in groups[item.value.group] diff --git a/releasenotes/notes/implement-docker-healthchecks-for-haproxy-e222d45809a1a9a1.yaml b/releasenotes/notes/implement-docker-healthchecks-for-haproxy-e222d45809a1a9a1.yaml new file mode 100644 index 0000000000..9607fffcd4 --- /dev/null +++ b/releasenotes/notes/implement-docker-healthchecks-for-haproxy-e222d45809a1a9a1.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Implements container healthchecks for haproxy services. + See `blueprint + `__