Skip to content

Commit

Permalink
Add persistentVolumeClaimRetentionPolicy variable to values.yaml (#965)
Browse files Browse the repository at this point in the history
This variable is used to set the persistentVolumeClaimRetentionPolicy
value in the server-statefulset.yaml template, which is used to
configure the retention policy for the PVCs used by the server
statefulset.
  • Loading branch information
alemuro authored Nov 13, 2023
1 parent 2bb6994 commit ad64f92
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

Features:

* server: Support setting `persistentVolumeClaimRetentionPolicy` on the StatefulSet [GH-965](https://github.com/hashicorp/vault-helm/pull/965)

Improvements:

* Support exec in the server liveness probe [GH-971](https://github.com/hashicorp/vault-helm/pull/971)
Expand Down
3 changes: 3 additions & 0 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ spec:
replicas: {{ template "vault.replicas" . }}
updateStrategy:
type: {{ .Values.server.updateStrategyType }}
{{- if and (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) (.Values.server.persistentVolumeClaimRetentionPolicy) }}
persistentVolumeClaimRetentionPolicy: {{ toYaml .Values.server.persistentVolumeClaimRetentionPolicy | nindent 4 }}
{{- end }}
selector:
matchLabels:
app.kubernetes.io/name: {{ template "vault.name" . }}
Expand Down
67 changes: 67 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,73 @@ load _helpers
[ "${actual}" = "OnDelete" ]
}

#--------------------------------------------------------------------
# persistentVolumeClaimRetentionPolicy

@test "server/standalone-StatefulSet: persistentVolumeClaimRetentionPolicy not set by default when kubernetes < 1.23" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--kube-version "1.22" \
. | tee /dev/stderr |
yq -r '.spec.persistentVolumeClaimRetentionPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/standalone-StatefulSet: unset persistentVolumeClaimRetentionPolicy.whenDeleted when kubernetes < 1.23" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--kube-version "1.22" \
--set 'server.persistentVolumeClaimRetentionPolicy.whenDeleted=Delete' \
. | tee /dev/stderr |
yq -r '.spec.persistentVolumeClaimRetentionPolicy.whenDeleted' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/standalone-StatefulSet: unset persistentVolumeClaimRetentionPolicy.whenScaled when kubernetes < 1.23" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--kube-version "1.22" \
--set 'server.persistentVolumeClaimRetentionPolicy.whenScaled=Delete' \
. | tee /dev/stderr |
yq -r '.spec.persistentVolumeClaimRetentionPolicy.whenScaled' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/standalone-StatefulSet: persistentVolumeClaimRetentionPolicy not set by default when kubernetes >= 1.23" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--kube-version "1.23" \
. | tee /dev/stderr |
yq -r '.spec.persistentVolumeClaimRetentionPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/standalone-StatefulSet: can set persistentVolumeClaimRetentionPolicy.whenDeleted when kubernetes >= 1.23" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--kube-version "1.23" \
--set 'server.persistentVolumeClaimRetentionPolicy.whenDeleted=Delete' \
. | tee /dev/stderr |
yq -r '.spec.persistentVolumeClaimRetentionPolicy.whenDeleted' | tee /dev/stderr)
[ "${actual}" = "Delete" ]
}

@test "server/standalone-StatefulSet: can set persistentVolumeClaimRetentionPolicy.whenScaled when kubernetes >= 1.23" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--kube-version "1.23" \
--set 'server.persistentVolumeClaimRetentionPolicy.whenScaled=Delete' \
. | tee /dev/stderr |
yq -r '.spec.persistentVolumeClaimRetentionPolicy.whenScaled' | tee /dev/stderr)
[ "${actual}" = "Delete" ]
}

#--------------------------------------------------------------------
# replicas

Expand Down
11 changes: 11 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@
}
}
},
"persistentVolumeClaimRetentionPolicy": {
"type": "object",
"properties": {
"whenDeleted": {
"type": "string"
},
"whenScaled": {
"type": "string"
}
}
},
"dev": {
"type": "object",
"properties": {
Expand Down
8 changes: 8 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,14 @@ server:
# Annotations to apply to the PVC
annotations: {}

# Persistent Volume Claim (PVC) retention policy
# ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention
# Example:
# persistentVolumeClaimRetentionPolicy:
# whenDeleted: Retain
# whenScaled: Retain
persistentVolumeClaimRetentionPolicy: {}

# This configures the Vault Statefulset to create a PVC for audit
# logs. Once Vault is deployed, initialized, and unsealed, Vault must
# be configured to use this for audit logs. This will be mounted to
Expand Down

0 comments on commit ad64f92

Please sign in to comment.