fix: preserve pvc template labels#2
Conversation
📝 WalkthroughWalkthroughThe PR implements PVC label preservation during Helm upgrades. The StatefulSet template now looks up existing volumeClaimTemplates labels and reuses them instead of applying fresh chart-generated labels, preventing mutations to immutable PVC metadata. The chart version is incremented to 0.2.1 and the upgrade guarantee is documented. ChangesPVC Label Preservation Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
templates/statefulset.yaml (1)
5-7: ⚡ Quick winUse name-based PVC template lookup instead of index
0.
index $existingVolumeClaimTemplates 0assumes the first template is alwaysdata. If another template is added/reordered, this can pull the wrong labels and trigger immutable StatefulSet update failures again. Match bymetadata.name: databefore extracting labels.Proposed change
{{- $existingVolumeClaimTemplates := dig "spec" "volumeClaimTemplates" (list) $existingStatefulSet -}} -{{- if gt (len $existingVolumeClaimTemplates) 0 -}} -{{- $volumeClaimTemplateLabels = dig "metadata" "labels" (dict) (index $existingVolumeClaimTemplates 0) -}} -{{- end -}} +{{- range $tpl := $existingVolumeClaimTemplates -}} +{{- if eq (dig "metadata" "name" "" $tpl) "data" -}} +{{- $volumeClaimTemplateLabels = dig "metadata" "labels" (dict) $tpl -}} +{{- end -}} +{{- end -}}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@templates/statefulset.yaml` around lines 5 - 7, The code uses index $existingVolumeClaimTemplates 0 to grab labels which assumes the first PVC template is the data PVC; change this to search $existingVolumeClaimTemplates for the template whose metadata.name equals "data" and then set $volumeClaimTemplateLabels from that found item (instead of using index 0). Specifically, replace the index lookup with logic that iterates or filters $existingVolumeClaimTemplates to find the entry with metadata.name == "data" and only then call dig "metadata" "labels" on that item to populate $volumeClaimTemplateLabels, leaving dig and $existingVolumeClaimTemplates variable names intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@templates/statefulset.yaml`:
- Around line 5-7: The code uses index $existingVolumeClaimTemplates 0 to grab
labels which assumes the first PVC template is the data PVC; change this to
search $existingVolumeClaimTemplates for the template whose metadata.name equals
"data" and then set $volumeClaimTemplateLabels from that found item (instead of
using index 0). Specifically, replace the index lookup with logic that iterates
or filters $existingVolumeClaimTemplates to find the entry with metadata.name ==
"data" and only then call dig "metadata" "labels" on that item to populate
$volumeClaimTemplateLabels, leaving dig and $existingVolumeClaimTemplates
variable names intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a1ad425c-1f4c-4597-8e89-9f898e6fe47b
📒 Files selected for processing (3)
Chart.yamlREADME.mdtemplates/statefulset.yaml
Summary
Why
Local control-plane iteration of gitkb-stack auth found that upgrading an existing release from chart 0.1.0 to 0.2.0 failed before Service labels could apply:
The immutable diff came from the versioned
helm.sh/chartlabel insidespec.volumeClaimTemplates.Validation
The server-side dry run preserved the existing PVC template label
helm.sh/chart: gitkb-server-0.1.0while rendering the new Service waypoint labels.Summary by CodeRabbit
Chores
Bug Fixes
Documentation