Skip to content

Commit 1997403

Browse files
authored
fix(pvc): prevent PV rebinding on upgrade and fix missing annotations block (#102)
* fix(pvc): prevent PV rebinding on upgrade and fix missing annotations block Add `helm.sh/resource-policy: keep` unconditionally so the PVC survives helm uninstall, fix the annotations block which was previously absent when no custom annotations were set, and use `lookup` to pin `volumeName` on upgrades to prevent the PVC from being re-bound to a different PV. Also add some test coverage. Fixes #74 * Address CodeRabbit review comments. - Renamed `$volumeName` → `$pvcName` (line 2) — accurately reflects it holds the PVC name - Extracted `lookup` into `$existingPvc` (line 3) at the top level — called once, outside the `storageClass` guard - Moved `volumeName` block (lines 32-34) outside the `storageClass` guard — now always evaluated regardless of whether `storageClass`` is set
1 parent 0171885 commit 1997403

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

charts/sourcebot/templates/pvc.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{{- if and .Values.sourcebot.persistence.enabled (not .Values.sourcebot.persistence.existingClaim) }}
2+
{{- $pvcName := printf "%s-%s" (include "sourcebot.fullname" .) "data" -}}
3+
{{- $existingPvc := (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $pvcName) -}}
24
---
35
apiVersion: v1
46
kind: PersistentVolumeClaim
@@ -7,10 +9,11 @@ metadata:
79
namespace: {{ $.Release.Namespace }}
810
labels:
911
{{- include "sourcebot.labels" . | nindent 4 }}
10-
{{- with .Values.sourcebot.persistence.annotations }}
1112
annotations:
13+
helm.sh/resource-policy: keep
14+
{{- with .Values.sourcebot.persistence.annotations }}
1215
{{- toYaml . | nindent 4 }}
13-
{{- end }}
16+
{{- end }}
1417
spec:
1518
accessModes:
1619
{{- range .Values.sourcebot.persistence.accessModes }}
@@ -26,5 +29,8 @@ spec:
2629
storageClassName: {{ .Values.sourcebot.persistence.storageClass }}
2730
{{- end }}
2831
{{- end }}
32+
{{- if and $existingPvc $existingPvc.spec.volumeName }}
33+
volumeName: {{ $existingPvc.spec.volumeName }}
34+
{{- end }}
2935
{{- end }}
3036

charts/sourcebot/tests/basic_test.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ tests:
181181
claimName: my-existing-pvc
182182
template: deployment.yaml
183183

184+
- it: should always have keep resource policy annotation on PVC
185+
values:
186+
- ../values.lint.yaml
187+
asserts:
188+
- equal:
189+
path: metadata.annotations["helm.sh/resource-policy"]
190+
value: keep
191+
template: pvc.yaml
192+
193+
- it: should merge custom annotations with helm resource policy on PVC
194+
values:
195+
- ../values.lint.yaml
196+
set:
197+
sourcebot.persistence.annotations:
198+
custom.io/annotation: "my-value"
199+
asserts:
200+
- equal:
201+
path: metadata.annotations["helm.sh/resource-policy"]
202+
value: keep
203+
template: pvc.yaml
204+
- equal:
205+
path: metadata.annotations["custom.io/annotation"]
206+
value: my-value
207+
template: pvc.yaml
208+
184209
- it: should set service type correctly
185210
values:
186211
- ../values.lint.yaml

0 commit comments

Comments
 (0)