Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

graceful termination handler for master nodes #119

Merged
merged 4 commits into from
May 3, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,50 @@ spec:
{{- if .Values.extraVolumeMounts }}
{{ tpl .Values.extraVolumeMounts . | indent 10 }}
{{- end }}
{{- if eq .Values.roles.master "true" }}
kimxogus marked this conversation as resolved.
Show resolved Hide resolved
- name: elasticsearch-master-graceful-termination-handler
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
kimxogus marked this conversation as resolved.
Show resolved Hide resolved
imagePullPolicy: "{{ .Values.imagePullPolicy }}"
command:
- "sh"
- -c
- |
#!/usr/bin/env bash
set -eo pipefail

http () {
local path="${1}"
if [ -n "${ELASTIC_USERNAME}" ] && [ -n "${ELASTIC_PASSWORD}" ]; then
BASIC_AUTH="-u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD}"
else
BASIC_AUTH=''
fi
curl -XGET -s -k --fail ${BASIC_AUTH} {{ .Values.protocol }}://{{ template "masterService" . }}:{{ .Values.httpPort }}${path}
}

cleanup () {
while true ; do
local master="$(http "/_cat/master")"
kimxogus marked this conversation as resolved.
Show resolved Hide resolved
if [[ $master == *"{{ template "uname" . }}"* && $master != *"${NODE_NAME}"* ]]; then
kimxogus marked this conversation as resolved.
Show resolved Hide resolved
echo "This node is not master."
break
fi
echo "This node is still master, waiting gracefully for it to step down"
sleep 1
done

exit 0
}

trap cleanup SIGTERM

while true; do
sleep 60 &
kimxogus marked this conversation as resolved.
Show resolved Hide resolved
wait $!
done
env:
kimxogus marked this conversation as resolved.
Show resolved Hide resolved
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- end }}