Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sleep in the preStop lifecycle step #188

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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