Skip to content

Commit f481df5

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use Docker healthchecks for keystone-fernet container" into stable/wallaby
2 parents b042125 + 6191719 commit f481df5

File tree

7 files changed

+71
-12
lines changed

7 files changed

+71
-12
lines changed

ansible/roles/keystone/defaults/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ keystone_services:
5959
- "kolla_logs:/var/log/kolla/"
6060
- "keystone_fernet_tokens:/etc/keystone/fernet-keys"
6161
dimensions: "{{ keystone_fernet_dimensions }}"
62+
healthcheck: "{{ keystone_fernet_healthcheck }}"
6263

6364
####################
6465
# Database
@@ -123,6 +124,19 @@ keystone_ssh_healthcheck:
123124
test: "{% if keystone_ssh_enable_healthchecks | bool %}{{ keystone_ssh_healthcheck_test }}{% else %}NONE{% endif %}"
124125
timeout: "{{ keystone_ssh_healthcheck_timeout }}"
125126

127+
keystone_fernet_enable_healthchecks: "{{ enable_container_healthchecks }}"
128+
keystone_fernet_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
129+
keystone_fernet_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
130+
keystone_fernet_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
131+
keystone_fernet_healthcheck_test: ["CMD-SHELL", "/usr/bin/fernet-healthcheck.sh"]
132+
keystone_fernet_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
133+
keystone_fernet_healthcheck:
134+
interval: "{{ keystone_fernet_healthcheck_interval }}"
135+
retries: "{{ keystone_fernet_healthcheck_retries }}"
136+
start_period: "{{ keystone_fernet_healthcheck_start_period }}"
137+
test: "{% if keystone_fernet_enable_healthchecks | bool %}{{ keystone_fernet_healthcheck_test }}{% else %}NONE{% endif %}"
138+
timeout: "{{ keystone_fernet_healthcheck_timeout }}"
139+
126140
keystone_default_volumes:
127141
- "{{ node_config_directory }}/keystone/:{{ container_config_directory }}/:ro"
128142
- "/etc/localtime:/etc/localtime:ro"

ansible/roles/keystone/tasks/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
- { src: "fernet-rotate.sh.j2", dest: "fernet-rotate.sh" }
224224
- { src: "fernet-node-sync.sh.j2", dest: "fernet-node-sync.sh" }
225225
- { src: "fernet-push.sh.j2", dest: "fernet-push.sh" }
226+
- { src: "fernet-healthcheck.sh.j2", dest: "fernet-healthcheck.sh" }
226227
- { src: "id_rsa", dest: "id_rsa" }
227228
- { src: "ssh_config.j2", dest: "ssh_config" }
228229
when:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
(/usr/bin/fernet-node-sync.sh --check && /usr/bin/fernet-push.sh --check) || exit 1
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
#!/bin/bash
1+
!/bin/bash
22

33
set -o errexit
44
set -o pipefail
55

6-
# Ensure tokens are populated, check for 0 key which should always exist
7-
n=0
8-
while [ ! -f /etc/keystone/fernet-keys/0 ]; do
9-
if [ $n -lt 10 ]; then
10-
n=$(( n + 1 ))
11-
echo "ERROR: Fernet tokens have not been populated, rechecking in 1 minute"
12-
echo "DEBUG: /etc/keystone/fernet-keys contents:"
13-
ls -l /etc/keystone/fernet-keys/
14-
sleep 60
6+
if [ ! -z "$1" ] && [ "$1" == "--check" ]; then
7+
if [ -f /etc/keystone/fernet-keys/0 ]; then
8+
if [[ $(stat -c %U:%G /etc/keystone/fernet-keys/0) != "keystone:keystone" ]]; then
9+
exit 1
10+
fi
1511
else
16-
echo "CRITICAL: Waited for 10 minutes - failing"
1712
exit 1
1813
fi
19-
done
14+
else
15+
# Ensure tokens are populated, check for 0 key which should always exist
16+
n=0
17+
while [ ! -f /etc/keystone/fernet-keys/0 ]; do
18+
if [ $n -lt 10 ]; then
19+
n=$(( n + 1 ))
20+
echo "ERROR: Fernet tokens have not been populated, rechecking in 1 minute"
21+
echo "DEBUG: /etc/keystone/fernet-keys contents:"
22+
ls -l /etc/keystone/fernet-keys/
23+
sleep 60
24+
else
25+
echo "CRITICAL: Waited for 10 minutes - failing"
26+
exit 1
27+
fi
28+
done
29+
fi

ansible/roles/keystone/templates/fernet-push.sh.j2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33
set -o errexit
44
set -o pipefail
55

6+
if [ ! -z "$1" ] && [ "$1" == "--check" ]; then
7+
{% if groups['keystone'] | length > 1 %}
8+
{% for host in groups['keystone'] %}
9+
{% if inventory_hostname != host %}
10+
/usr/bin/rsync --dry-run -az -e 'ssh -i /var/lib/keystone/.ssh/id_rsa -p {{ hostvars[host]['keystone_ssh_port'] }} -F /var/lib/keystone/.ssh/config' --delete /etc/keystone/fernet-keys/ keystone@{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:/etc/keystone/fernet-keys
11+
{% endif %}
12+
{% endfor %}
13+
{% else %}
14+
echo "No additional keystone-server where fernet keys could be rsynced."
15+
{% endif %}
16+
else
17+
{% if groups['keystone'] | length > 1 %}
618
{% for host in groups['keystone'] %}
719
{% if inventory_hostname != host %}
820
/usr/bin/rsync -az -e 'ssh -i /var/lib/keystone/.ssh/id_rsa -p {{ hostvars[host]['keystone_ssh_port'] }} -F /var/lib/keystone/.ssh/config' --delete /etc/keystone/fernet-keys/ keystone@{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:/etc/keystone/fernet-keys
921
{% endif %}
1022
{% endfor %}
23+
{% else %}
24+
echo "No additional keystone-server where fernet keys could be rsynced."
25+
{% endif %}
26+
fi

ansible/roles/keystone/templates/keystone-fernet.json.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
"dest": "/etc/keystone/{{ keystone_policy_file }}",
5050
"owner": "keystone",
5151
"perm": "0600"
52+
}{% endif %}{% if keystone_fernet_enable_healthchecks | bool %},
53+
{
54+
"source": "{{ container_config_directory }}/fernet-healthcheck.sh",
55+
"dest": "/usr/bin/fernet-healthcheck.sh",
56+
"owner": "root",
57+
"perm": "0755"
5258
}{% endif %}
5359
],
5460
"permissions": [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Implements container healthchecks for keystone-fernet container.
5+
See `blueprint
6+
<https://blueprints.launchpad.net/kolla-ansible/+spec/container-health-check>`__

0 commit comments

Comments
 (0)