From 1b6e36f1baf9c479fe8fb138b2a4e3b9e540156d Mon Sep 17 00:00:00 2001 From: Gavin Williams Date: Thu, 23 Apr 2026 22:19:32 +0100 Subject: [PATCH 1/2] 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 --- charts/sourcebot/templates/pvc.yaml | 9 +++++++-- charts/sourcebot/tests/basic_test.yaml | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/charts/sourcebot/templates/pvc.yaml b/charts/sourcebot/templates/pvc.yaml index 2d5ddef..4478231 100644 --- a/charts/sourcebot/templates/pvc.yaml +++ b/charts/sourcebot/templates/pvc.yaml @@ -1,4 +1,5 @@ {{- if and .Values.sourcebot.persistence.enabled (not .Values.sourcebot.persistence.existingClaim) }} +{{- $volumeName := printf "%s-%s" (include "sourcebot.fullname" .) "data" -}} --- apiVersion: v1 kind: PersistentVolumeClaim @@ -7,10 +8,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 }} @@ -25,6 +27,9 @@ spec: {{- else }} storageClassName: {{ .Values.sourcebot.persistence.storageClass }} {{- end }} + {{- if (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $volumeName) }} + volumeName: {{ (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $volumeName).spec.volumeName }} + {{- end }} {{- 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 From f4b119ce58059220f5af53b32012c0802822b4a3 Mon Sep 17 00:00:00 2001 From: Gavin Williams Date: Thu, 23 Apr 2026 22:27:08 +0100 Subject: [PATCH 2/2] Address CodeRabbit review comments. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- charts/sourcebot/templates/pvc.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/charts/sourcebot/templates/pvc.yaml b/charts/sourcebot/templates/pvc.yaml index 4478231..504e0cc 100644 --- a/charts/sourcebot/templates/pvc.yaml +++ b/charts/sourcebot/templates/pvc.yaml @@ -1,5 +1,6 @@ {{- if and .Values.sourcebot.persistence.enabled (not .Values.sourcebot.persistence.existingClaim) }} -{{- $volumeName := printf "%s-%s" (include "sourcebot.fullname" .) "data" -}} +{{- $pvcName := printf "%s-%s" (include "sourcebot.fullname" .) "data" -}} +{{- $existingPvc := (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $pvcName) -}} --- apiVersion: v1 kind: PersistentVolumeClaim @@ -27,9 +28,9 @@ spec: {{- else }} storageClassName: {{ .Values.sourcebot.persistence.storageClass }} {{- end }} - {{- if (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $volumeName) }} - volumeName: {{ (lookup "v1" "PersistentVolumeClaim" $.Release.Namespace $volumeName).spec.volumeName }} {{- end }} + {{- if and $existingPvc $existingPvc.spec.volumeName }} + volumeName: {{ $existingPvc.spec.volumeName }} {{- end }} {{- end }}