Adding sleep in the preStop lifecycle step (#188)

Aims to make vault pod termination more graceful with respect to user
requests.
This commit is contained in:
Theron Voran 2020-01-30 09:39:08 -08:00 committed by GitHub
parent 7a6e8c3648
commit 45c9118782
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View file

@ -127,7 +127,13 @@ spec:
# from Consul (zombie services).
preStop:
exec:
command: ["/bin/sh","-c","kill -SIGTERM $(pidof vault)"]
command: [
"/bin/sh", "-c",
# Adding a sleep here to give the pod eviction a
# chance to propagate, so requests will not be made
# to this pod while it's terminating
"sleep {{ .Values.server.preStopSleepSeconds }} && kill -SIGTERM $(pidof vault)",
]
{{- if .Values.server.extraContainers }}
{{ toYaml .Values.server.extraContainers | nindent 8}}
{{- end }}

View file

@ -841,3 +841,24 @@ load _helpers
yq -r '.spec.template.spec.containers[0].args[0]' | tee /dev/stderr)
[[ "${actual}" = *"foobar"* ]]
}
#--------------------------------------------------------------------
# preStop
@test "server/standalone-StatefulSet: preStop sleep duration default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].lifecycle.preStop.exec.command[2]' | tee /dev/stderr)
[[ "${actual}" = "sleep 5 &&"* ]]
}
@test "server/standalone-StatefulSet: preStop sleep duration 10" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.preStopSleepSeconds=10' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].lifecycle.preStop.exec.command[2]' | tee /dev/stderr)
[[ "${actual}" = "sleep 10 &&"* ]]
}

View file

@ -135,6 +135,9 @@ server:
path: "/v1/sys/health?standbyok=true"
initialDelaySeconds: 60
# Used to set the sleep time during the preStop step
preStopSleepSeconds: 5
# extraEnvironmentVars is a list of extra enviroment variables to set with the stateful set. These could be
# used to include variables required for auto-unseal.
extraEnvironmentVars: {}