fix(templating): fix wrong YAML separator parsing for post-renderers#31941
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns the post-renderer merge/annotate path with Helm’s existing manifest-splitting behavior by switching from a custom YAML separator “fixer” to releaseutil.SplitManifests, and updates tests/documentation to reflect the legacy separator leniency.
Changes:
- Remove
fixDocSeparatorsand split per-file content viareleaseutil.SplitManifestsbefore feeding documents intokio.ParseAll. - Add/expand
annotateAndMergetests to cover glued separators and dash-heavy YAML/JSON values. - Add an explanatory (Chart API v3–oriented) note to
releaseutil.SplitManifests’s doc comment.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/release/v1/util/manifest.go | Adds a note explaining legacy SplitManifests regex behavior and future Chart API v3 expectations. |
| pkg/action/action.go | Changes post-renderer document parsing to use releaseutil.SplitManifests instead of a custom separator-repair function. |
| pkg/action/action_test.go | Removes tests for the deleted helper and adds new annotateAndMerge cases for separator/dash edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
adce562 to
51dd826
Compare
|
FYI this issue's impact is quite wide on the post renderers code path. In Flux, this code path runs for 100% of the HelmReleases, so we forked Helm to ship a patch today. |
|
We've identified an issue with this fix when it comes to multi-line string values in the YAML template, see fluxcd/helm-controller#1448 for an example. |
|
The root cause is the combined behavior of |
|
I don't think this is related to the parsing behaviour. Rather, this is introduced directly by the use of So any user of |
|
@marvin-roesch I was just able to reproduce this in Helm CLI 4.0.0, but not in Helm CLI 3.20.0 using |
|
Ah, I think there indeed are two separate issues at play here. I was not able to reproduce your case with Helm 4 on the templates that exhibit the issue for us. Do your template files have a final newline? Ours do and Helm 4.1.3 renders it correctly (with post-renderer), but if I remove the final newline, I can see the same difference in behaviour that you do. Arguably the new behaviour is more correct since it correctly renders the YAML from the template without trailing newline. Helm 3 would insert additional newlines where they weren't supposed to be. I'll raise a separate issue about this regression regardless, but this PR introduces additional breakage for files that do have a trailing newline. And that is due to the behaviour of Sorry if I caused confusion, my editor will automatically use a trailing newline by default, so this never showed in my testing. I do think this PR still needs adjustment, however. |
If the
I'm not sure, it looks like
What would you suggest for this PR? My only intention here is to align the post-renderer code path with non-post-renderer code path, nothing else. The fact that Helm 4 introduced |
|
By the way, I'm not saying Helm 4 should not fix this, just saying that it should be a separate PR. |
|
I've separately raised #31948 to address this difference in behaviour. I personally think Helm 4 with a post-renderer is more accurate here as any YAML parser would agree with this interpretation of the block literal in the absence of a trailing newline.
I think it makes sense to adjust |
|
This PR fixes critical bugs in Helm post render that breaks most charts out there. I would not delay a patch release with this fix due to Helm v4 preserving final newlines, this newline issue originates in v4.0.0 and is not a related to this PR IMO. |
|
@stefanprodan, unfortunately due to the interplay with #31948 this fix (from the Helm fork shipped with the Flux Helm controller) has also caused issues for us already and could potentially cause way more charts to be broken due to trailing newlines being eliminated. As for how to address the issue in this PR: The simplest would be to change the use of The regex used by |
This would not fix the example I posted above, where there's no newline at the end of |
|
Hmm but I guess |
A proper and full resolution for this situation would need to be addressed in #31948. Right now I am only concerned with not breaking things further with this PR, however. I've locally played with the changes in this PR and using {
name: "mixed glued and proper separators",
files: map[string]string{
"templates/mixed.yaml": `
apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
data:
multi-line-1: |
test
test1
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm2
data:
multi-line-2: |
test
test1
---apiVersion: v1
kind: ConfigMap
metadata:
name: cm3
data:
multi-line-3: |
test
test1
`,
},
expected: `apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
annotations:
postrenderer.helm.sh/postrender-filename: 'templates/mixed.yaml'
data:
multi-line-1: |-
test
test1
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm2
annotations:
postrenderer.helm.sh/postrender-filename: 'templates/mixed.yaml'
data:
multi-line-2: |-
test
test1
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm3
annotations:
postrenderer.helm.sh/postrender-filename: 'templates/mixed.yaml'
data:
multi-line-3: |
test
test1
`,
},The And now that I think about it, the changes from this PR would further meddle with currently working documents that are properly formatted. Before these changes, the above test case (if the separator before apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
annotations:
postrenderer.helm.sh/postrender-filename: 'templates/mixed.yaml'
data:
multi-line-1: |
test
test1
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm2
annotations:
postrenderer.helm.sh/postrender-filename: 'templates/mixed.yaml'
data:
multi-line-2: |
test
test1
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm3
annotations:
postrenderer.helm.sh/postrender-filename: 'templates/mixed.yaml'
data:
multi-line-3: |
test
test1
That is everything would have had its whitespace correctly preserved. One resolution that would also address #31948 in the sense of restoring Helm 3 behaviour is the following: Trim all whitespace in |
|
@marvin-roesch I opened #31952 to address your concerns (and hence fix #31948) using this PR as base. I asked the maintainers to review and merge this one first, as is. I got to the bottom of how |
|
Thanks @matheuscscp! I was holding off on submitting something myself since I wanted to wait for Helm maintainers to chime in on the issue itself, but having a PR to discuss on is also good. |
|
@banjoh @TerryHowe @matheuscscp can we get this backported to v4.1? Or is that minor EOL already? |
Fixes: #31935
Supersedes: #31936
This PR fixes all these bugs:
Context
The first fix we tried (#31868) introduced a new function for parsing and fixing the YAML separators. Turns out this was a dumb solution, Helm has a function for doing this since 8 years now:
helm/pkg/releaseutil/manifest.go
Lines 36 to 60 in 301108e
So in this PR I'm deleting the new function added in #31868, I'm reusing the function above, and I'm adding comments to remove this behavior in Chart API v3 (cc @scottrigby).