From 42153168182e6e8eb1aaa4873c39a42d46ea0159 Mon Sep 17 00:00:00 2001 From: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> Date: Thu, 28 May 2020 14:53:46 -0400 Subject: [PATCH] Add postStart lifecycle hook (#315) * Add postStart lifecycle hook * Update values.yaml Co-authored-by: Theron Voran Co-authored-by: Theron Voran --- templates/server-statefulset.yaml | 8 ++++++++ test/unit/server-statefulset.bats | 21 +++++++++++++++++++++ values.yaml | 8 ++++++++ 3 files changed, 37 insertions(+) diff --git a/templates/server-statefulset.yaml b/templates/server-statefulset.yaml index 96aaf7572..69a925f2f 100644 --- a/templates/server-statefulset.yaml +++ b/templates/server-statefulset.yaml @@ -159,6 +159,14 @@ spec: # to this pod while it's terminating "sleep {{ .Values.server.preStopSleepSeconds }} && kill -SIGTERM $(pidof vault)", ] + {{- if .Values.server.postStart }} + postStart: + exec: + command: + {{- range (.Values.server.postStart) }} + - {{ . | quote }} + {{- end }} + {{- end }} {{- if .Values.server.extraContainers }} {{ toYaml .Values.server.extraContainers | nindent 8}} {{- end }} diff --git a/test/unit/server-statefulset.bats b/test/unit/server-statefulset.bats index 5bdc25f0d..7e7678c44 100755 --- a/test/unit/server-statefulset.bats +++ b/test/unit/server-statefulset.bats @@ -1048,3 +1048,24 @@ load _helpers yq '.spec.template.spec | .priorityClassName == "armaggeddon"' | tee /dev/stderr) [ "${actual}" = "true" ] } + +#-------------------------------------------------------------------- +# postStart +@test "server/standalone-StatefulSet: postStart disabled by default" { + cd `chart_dir` + local actual=$(helm template \ + --show-only templates/server-statefulset.yaml \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].lifecycle.postStart' | tee /dev/stderr) + [ "${actual}" = "null" ] +} + +@test "server/standalone-StatefulSet: postStart can be set" { + cd `chart_dir` + local actual=$(helm template \ + --show-only templates/server-statefulset.yaml \ + --set='server.postStart={/bin/sh,-c,sleep}' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].lifecycle.postStart.exec.command[0]' | tee /dev/stderr) + [ "${actual}" = "/bin/sh" ] +} diff --git a/values.yaml b/values.yaml index d315c87c2..d1bbaf4b0 100644 --- a/values.yaml +++ b/values.yaml @@ -188,6 +188,14 @@ server: # Used to set the sleep time during the preStop step preStopSleepSeconds: 5 + # Used to define commands to run after the pod is ready. + # This can be used to automate processes such as initialization + # or boostrapping auth methods. + postStart: [] + # - /bin/sh + # - -c + # - /vault/userconfig/myscript/run.sh + # 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: {}