Skip to content

Commit

Permalink
Adding sleep in the preStop lifecycle step (hashicorp#188)
Browse files Browse the repository at this point in the history
Aims to make vault pod termination more graceful with respect to user
requests.
  • Loading branch information
tvoran committed Jan 30, 2020
1 parent 5b41e5e commit 6f66053
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
21 changes: 21 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&"* ]]
}
3 changes: 3 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down

0 comments on commit 6f66053

Please sign in to comment.