fix: Preserve CRD location when patching charts (#2291) #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes helmfile/helmfile#2291
This PR fixes an issue where
strategicMergePatchescauses CRDs fromtemplates/crds/to be relocated to the rootcrds/directory, changing how Helm manages them and causinghelm diffto show CRDs being removed.Problem
When using strategicMergePatches with charts like KEDA that place CRDs in
templates/crds/:templates/crds/(managed as regular resources)crds/directory (Helm special handling)helm diffshows CRDs being removed, even though patches don't reference CRDsWhy This Matters
Chart authors intentionally use
templates/crds/instead of rootcrds/for:{{- if .Values.crds.install }}.Release.Namespace, labels, annotationshelm upgradeHelm's Different Treatment
templates/crds/crds/Root Cause
In
patch.go:342-364, CRDs were unconditionally relocated:Solution
Detect if CRDs originally came from
templates/crds/and preserve that location:Changes
patch.gofilepath.ToSlash()patch_test.go(new file)Added comprehensive test coverage:
TestPatch_PreserveCRDLocation: End-to-end scenariostemplates/crds/stay intemplates/crds/crds/go tocrds/TestPatch_CRDLocationDetection: Detection logic validationtemplates/crds/filesTestPatch_KEDA_RealWorld: Real-world KEDA scenarioTesting
Test Coverage
templates/crds/preserved in original locationcrds/use standard Helm 3/4 locationtemplates/crds/)Verification
A complete reproduction test case is available at
/tmp/keda-issue-test/with:verify-issue.sh)Backward Compatibility
✅ No breaking changes
crds/→ same behavior as beforetemplates/crds/→ now correctly preservedImpact
Affected Charts
Any chart with CRDs in
templates/subdirectories:Benefits
helm diffshowing incorrect CRD deletionsRelated Issues
/tmp/keda-issue-test/SUMMARY.mdfor complete analysis/tmp/keda-issue-test/ANALYSIS.mdfor technical deep-diveReviewers
Key areas to review:
templates/crds/filesfilepath.ToSlash()Ready for review ✅