Skip to content

Commit

Permalink
Add persistentVolumeClaimRetentionPolicy variable to values.yaml
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 committed Nov 8, 2023
1 parent 2473937 commit c782cbb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
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
8 changes: 8 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,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 c782cbb

Please sign in to comment.