diff --git a/charts/sourcebot/templates/pvc.yaml b/charts/sourcebot/templates/pvc.yaml index 2d5ddef..504e0cc 100644 --- a/charts/sourcebot/templates/pvc.yaml +++ b/charts/sourcebot/templates/pvc.yaml @@ -1,4 +1,6 @@ {{- if and .Values.sourcebot.persistence.enabled (not .Values.sourcebot.persistence.existingClaim) }} +{{- $pvcName := printf "%s-%s" (include "sourcebot.fullname" .) "data" -}} +{{- $existingPvc := (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $pvcName) -}} --- apiVersion: v1 kind: PersistentVolumeClaim @@ -7,10 +9,11 @@ metadata: namespace: {{ $.Release.Namespace }} labels: {{- include "sourcebot.labels" . | nindent 4 }} - {{- with .Values.sourcebot.persistence.annotations }} annotations: + helm.sh/resource-policy: keep + {{- with .Values.sourcebot.persistence.annotations }} {{- toYaml . | nindent 4 }} - {{- end }} + {{- end }} spec: accessModes: {{- range .Values.sourcebot.persistence.accessModes }} @@ -26,5 +29,8 @@ spec: storageClassName: {{ .Values.sourcebot.persistence.storageClass }} {{- end }} {{- end }} + {{- if and $existingPvc $existingPvc.spec.volumeName }} + volumeName: {{ $existingPvc.spec.volumeName }} + {{- end }} {{- end }} diff --git a/charts/sourcebot/tests/basic_test.yaml b/charts/sourcebot/tests/basic_test.yaml index 023da4c..ccdb3f8 100644 --- a/charts/sourcebot/tests/basic_test.yaml +++ b/charts/sourcebot/tests/basic_test.yaml @@ -159,6 +159,31 @@ tests: claimName: my-existing-pvc template: deployment.yaml + - it: should always have keep resource policy annotation on PVC + values: + - ../values.lint.yaml + asserts: + - equal: + path: metadata.annotations["helm.sh/resource-policy"] + value: keep + template: pvc.yaml + + - it: should merge custom annotations with helm resource policy on PVC + values: + - ../values.lint.yaml + set: + sourcebot.persistence.annotations: + custom.io/annotation: "my-value" + asserts: + - equal: + path: metadata.annotations["helm.sh/resource-policy"] + value: keep + template: pvc.yaml + - equal: + path: metadata.annotations["custom.io/annotation"] + value: my-value + template: pvc.yaml + - it: should set service type correctly values: - ../values.lint.yaml