helm / community

Helm community content
https://helm.sh
421 stars 179 forks source link

Range inside of an include adds extra newline #322

Open burkempers opened 12 months ago

burkempers commented 12 months ago

There seems to be a bug with range inside of an include. It is a little hard to explain, so here is my test setup.

values.yaml:

array:
  - this
  - is
  - somthing

_helpers.tpl :

{{- define "test.range" -}}
  {{- range .Values.array }}
test2 {{ . }}
  {{- end }}
{{- end }}

{{- define "test.range.three" -}}
#comment
  {{- range .Values.array }}
test3 {{ . }}
  {{- end }}
{{- end }}

cm.yaml :

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  test.data: |-
    {{- range .Values.array }}
    test1 {{ . }}
    {{- end }}

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test2
data:
  test.data: |-
    {{- include "test.range" . | nindent 4 }}

---
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test3
data:
  test.data: |-
    {{- include "test.range.three" . | nindent 4 }}

In my mind all three configmaps should look the same, but when you do a helm template command with this setup the test2 confimap has an extra blank new line. This new line once pushed to kubernetes then screws up kubernetes output to yaml format.

I am going to guess that the whitespace deletion has a bug in it with this setup, since in test3 just adding some text before the range removes any extra whitespace. Or I might be missing something simple.

burkempers commented 12 months ago

helm template output:


---
# Source: testingHelm/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  test.data: |-
    test1 this
    test1 is
    test1 somthing
---
# Source: testingHelm/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test2
data:
  test.data: |-

    test2 this
    test2 is
    test2 somthing
---
# Source: testingHelm/templates/cm.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test3
data:
  test.data: |-
    #comment
    test3 this
    test3 is
    test3 somthing
gjenkins8 commented 10 months ago

Issues regarding Helm usage are best posted over on the helm software repo https://github.com/helm/helm. Please repost there. Thanks!