Skip to content

Regression with post-renderer and multi-line strings in template files without trailing newline #31948

Description

@marvin-roesch

What happened?

When running helm template with a post-renderer on a chart containing the following template:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  value: |
    my value
    with multiple lines<EOF>

(<EOF> here is supposed to indicate that the template file ends there, so there is no trailing newline) Helm 4 will output the following:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  value: |-
    my value
    with multiple lines

Note the |- on the value, indicating that trailing whitespace is trimmed.

This behaviour does not occur when not using a post-renderer.

I think technically the behaviour of the version with the post-renderer is more accurate, as the resulting manifest reflects what a compliant YAML parser would make of the template without any involvement of Helm. However, this should be consistent rather than dependent on the use of a post-renderer. Furthermore, this does not match Helm 3.

What did you expect to happen?

In Helm 3, the same template with a post renderer would output the following:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  value: |
    my value
    with multiple lines

Note the trailing newline which gets preserved by the | multi-line string literal.

How can we reproduce it (as minimally and precisely as possible)?

Use a template like the above #without a trailing newline# where the end of the file coincides with the end of a multi-line string literal. Then template that chart with some post-renderer.

Helm version

Details
$ helm version
version.BuildInfo{Version:"v4.1.3", GitCommit:"c94d381b03be117e7e57908edbf642104e00eb8f", GitTreeState:"clean", GoVersion:"go1.25.8", KubeClientVersion:"v1.35"}
Note that this occurs on all 4.x releases of Helm.

Kubernetes version

Details
$ kubectl version
Client Version: v1.34.3
Kustomize Version: v5.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions