Skip to content

Commit

Permalink
Add labels for PVC template (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
alantang888 authored Nov 16, 2023
1 parent e77dce3 commit 3e16e05
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Features:

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

Improvements:

Expand Down
32 changes: 32 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ storage might be desired by the user.
- metadata:
name: data
{{- include "vault.dataVolumeClaim.annotations" . | nindent 6 }}
{{- include "vault.dataVolumeClaim.labels" . | nindent 6 }}
spec:
accessModes:
- {{ .Values.server.dataStorage.accessMode | default "ReadWriteOnce" }}
Expand All @@ -303,6 +304,7 @@ storage might be desired by the user.
- metadata:
name: audit
{{- include "vault.auditVolumeClaim.annotations" . | nindent 6 }}
{{- include "vault.auditVolumeClaim.labels" . | nindent 6 }}
spec:
accessModes:
- {{ .Values.server.auditStorage.accessMode | default "ReadWriteOnce" }}
Expand Down Expand Up @@ -782,6 +784,21 @@ Sets VolumeClaim annotations for data volume
{{- end }}
{{- end -}}
{{/*
Sets VolumeClaim labels for data volume
*/}}
{{- define "vault.dataVolumeClaim.labels" -}}
{{- if and (ne .mode "dev") (.Values.server.dataStorage.enabled) (.Values.server.dataStorage.labels) }}
labels:
{{- $tp := typeOf .Values.server.dataStorage.labels }}
{{- if eq $tp "string" }}
{{- tpl .Values.server.dataStorage.labels . | nindent 4 }}
{{- else }}
{{- toYaml .Values.server.dataStorage.labels | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}
{{/*
Sets VolumeClaim annotations for audit volume
*/}}
Expand All @@ -797,6 +814,21 @@ Sets VolumeClaim annotations for audit volume
{{- end }}
{{- end -}}
{{/*
Sets VolumeClaim labels for audit volume
*/}}
{{- define "vault.auditVolumeClaim.labels" -}}
{{- if and (ne .mode "dev") (.Values.server.auditStorage.enabled) (.Values.server.auditStorage.labels) }}
labels:
{{- $tp := typeOf .Values.server.auditStorage.labels }}
{{- if eq $tp "string" }}
{{- tpl .Values.server.auditStorage.labels . | nindent 4 }}
{{- else }}
{{- toYaml .Values.server.auditStorage.labels | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}
{{/*
Set's the container resources if the user has set any.
*/}}
Expand Down
46 changes: 46 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2000,3 +2000,49 @@ load _helpers
yq -r '.spec.template.spec.containers[0].livenessProbe.httpGet.port' | tee /dev/stderr)
[ "${actual}" = "8200" ]
}

#--------------------------------------------------------------------
# labels
@test "server/standalone-StatefulSet: auditStorage volumeClaim labels string" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.auditStorage.enabled=true' \
--set 'server.auditStorage.labels=vaultIsAwesome: true' \
. | tee /dev/stderr |
yq -r '.spec.volumeClaimTemplates[1].metadata.labels["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/standalone-StatefulSet: dataStorage volumeClaim labels string" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.dataStorage.enabled=true' \
--set 'server.dataStorage.labels=vaultIsAwesome: true' \
. | tee /dev/stderr |
yq -r '.spec.volumeClaimTemplates[0].metadata.labels["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/standalone-StatefulSet: auditStorage volumeClaim labels yaml" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.auditStorage.enabled=true' \
--set 'server.auditStorage.labels.vaultIsAwesome=true' \
. | tee /dev/stderr |
yq -r '.spec.volumeClaimTemplates[1].metadata.labels["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/standalone-StatefulSet: dataStorage volumeClaim labels yaml" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.dataStorage.enabled=true' \
--set 'server.dataStorage.labels.vaultIsAwesome=true' \
. | tee /dev/stderr |
yq -r '.spec.volumeClaimTemplates[0].metadata.labels["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
12 changes: 12 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@
"string"
]
},
"labels": {
"type": [
"object",
"string"
]
},
"enabled": {
"type": [
"boolean",
Expand Down Expand Up @@ -599,6 +605,12 @@
"string"
]
},
"labels": {
"type": [
"object",
"string"
]
},
"enabled": {
"type": [
"boolean",
Expand Down
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ server:
accessMode: ReadWriteOnce
# Annotations to apply to the PVC
annotations: {}
# Labels to apply to the PVC
labels: {}

# Persistent Volume Claim (PVC) retention policy
# ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention
Expand Down Expand Up @@ -796,6 +798,8 @@ server:
accessMode: ReadWriteOnce
# Annotations to apply to the PVC
annotations: {}
# Labels to apply to the PVC
labels: {}

# Run Vault in "dev" mode. This requires no further setup, no state management,
# and no initialization. This is useful for experimenting with Vault without
Expand Down

0 comments on commit 3e16e05

Please sign in to comment.