Skip to content

fix: preserve pvc template labels#2

Merged
patrickleet merged 1 commit into
mainfrom
fix/preserve-pvc-template-labels
Jun 10, 2026
Merged

fix: preserve pvc template labels#2
patrickleet merged 1 commit into
mainfrom
fix/preserve-pvc-template-labels

Conversation

@patrickleet

@patrickleet patrickleet commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve existing StatefulSet volumeClaimTemplates labels during Helm upgrades
  • bump chart to 0.2.1
  • document why PVC template labels are preserved

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:

StatefulSet.apps "gitkb-gitkb-server" is invalid: spec: Forbidden: updates to statefulset spec for fields other than ... are forbidden

The immutable diff came from the versioned helm.sh/chart label inside spec.volumeClaimTemplates.

Validation

  • helm lint ./xrs/charts/gitkb-server
  • helm template gitkb ./xrs/charts/gitkb-server --namespace gitkb -f -
  • helm --kube-context pat-local -n gitkb upgrade gitkb ./xrs/charts/gitkb-server --dry-run=server --debug --reuse-values --set service.labels."istio\.io/use-waypoint"=gitkb-waypoint --set-string service.labels."istio\.io/ingress-use-waypoint"=true
  • git diff --check

The server-side dry run preserved the existing PVC template label helm.sh/chart: gitkb-server-0.1.0 while rendering the new Service waypoint labels.

Summary by CodeRabbit

  • Chores

    • Helm chart version updated to 0.2.1
  • Bug Fixes

    • Fixed an issue where persistent volume claim template labels were overwritten during upgrades; existing labels are now preserved as expected
  • Documentation

    • Added documentation on persistent volume claim template label preservation behavior during chart upgrades

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

PVC Label Preservation Feature

Layer / File(s) Summary
StatefulSet PVC label preservation implementation
templates/statefulset.yaml
StatefulSet template logic extracts labels from the existing StatefulSet's first volumeClaimTemplates entry and applies them during rendering, with fallback to default gitkb-server.labels when none exist.
Documentation and version release
README.md, Chart.yaml
README documents that chart upgrades preserve existing volumeClaimTemplates labels to avoid mutating immutable PVC templates, and chart version is bumped to 0.2.1.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A label preserved, no mutations in sight,
StatefulSet templates now get it just right,
PVCs stay steady through upgrade's long flight,
From 0.2.0 to 0.2.1's delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: preserve pvc template labels' directly and concisely describes the main change: preserving PVC template labels during upgrades to prevent immutable field errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/preserve-pvc-template-labels

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
templates/statefulset.yaml (1)

5-7: ⚡ Quick win

Use name-based PVC template lookup instead of index 0.

index $existingVolumeClaimTemplates 0 assumes the first template is always data. If another template is added/reordered, this can pull the wrong labels and trigger immutable StatefulSet update failures again. Match by metadata.name: data before 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

📥 Commits

Reviewing files that changed from the base of the PR and between 16aaa43 and 1b5ab1f.

📒 Files selected for processing (3)
  • Chart.yaml
  • README.md
  • templates/statefulset.yaml

@patrickleet patrickleet merged commit f33fc72 into main Jun 10, 2026
2 checks passed
@patrickleet patrickleet deleted the fix/preserve-pvc-template-labels branch June 10, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant