Skip to content

Commit

Permalink
support exec in server liveness probe (#971)
Browse files Browse the repository at this point in the history
Co-authored-by: Theron Voran <[email protected]>
  • Loading branch information
thyton and tvoran authored Nov 9, 2023
1 parent 36dafa0 commit 2bb6994
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

Improvements:

* Support exec in the server liveness probe [GH-971](https://github.com/hashicorp/vault-helm/pull/971)

## 0.26.1 (October 30, 2023)

Bugs:
Expand Down
8 changes: 8 additions & 0 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,18 @@ spec:
{{- end }}
{{- if .Values.server.livenessProbe.enabled }}
livenessProbe:
{{- if .Values.server.livenessProbe.execCommand }}
exec:
command:
{{- range (.Values.server.livenessProbe.execCommand) }}
- {{ . | quote }}
{{- end }}
{{- else }}
httpGet:
path: {{ .Values.server.livenessProbe.path | quote }}
port: {{ .Values.server.livenessProbe.port }}
scheme: {{ include "vault.scheme" . | upper }}
{{- end }}
failureThreshold: {{ .Values.server.livenessProbe.failureThreshold }}
initialDelaySeconds: {{ .Values.server.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.server.livenessProbe.periodSeconds }}
Expand Down
35 changes: 35 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,41 @@ load _helpers
[ "${actual}" = "100" ]
}

@test "server/standalone-StatefulSet: liveness exec disabled by default" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.livenessProbe.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].livenessProbe' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.exec' | tee /dev/stderr)
[ "${actual}" = "null" ]

local actual=$(echo $object |
yq -r '.httpGet' | tee /dev/stderr)
[ ! "${actual}" = "null" ]
}

@test "server/standalone-StatefulSet: liveness exec can be set" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.livenessProbe.enabled=true' \
--set='server.livenessProbe.execCommand={/bin/sh,-c,sleep}' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].livenessProbe' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.exec.command[0]' | tee /dev/stderr)
[ "${actual}" = "/bin/sh" ]

local actual=$(echo $object |
yq -r '.httpGet' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

#--------------------------------------------------------------------
# args
@test "server/standalone-StatefulSet: add extraArgs" {
Expand Down
6 changes: 6 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,12 @@
"path": {
"type": "string"
},
"port": {
"type": "integer"
},
"execCommand": {
"type": "array"
},
"periodSeconds": {
"type": "integer"
},
Expand Down
8 changes: 7 additions & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,14 @@ server:
# Used to enable a livenessProbe for the pods
livenessProbe:
enabled: false
# Used to define a liveness exec command. If provided, exec is preferred to httpGet (path) as the livenessProbe handler.
execCommand: []
# - /bin/sh
# - -c
# - /vault/userconfig/mylivenessscript/run.sh
# Path for the livenessProbe to use httpGet as the livenessProbe handler
path: "/v1/sys/health?standbyok=true"
# Port number on which livenessProbe will be checked.
# Port number on which livenessProbe will be checked if httpGet is used as the livenessProbe handler
port: 8200
# When a probe fails, Kubernetes will try failureThreshold times before giving up
failureThreshold: 2
Expand Down

0 comments on commit 2bb6994

Please sign in to comment.