Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range inside of an include adds extra newline #322

Open
burkempers opened this issue Nov 22, 2023 · 2 comments
Open

Range inside of an include adds extra newline #322

burkempers opened this issue Nov 22, 2023 · 2 comments

Comments

@burkempers
Copy link

burkempers commented Nov 22, 2023

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 burkempers changed the title Range inside of a include adds extra newline Range inside of an include adds extra newline Nov 22, 2023
@burkempers
Copy link
Author

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
Copy link

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

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

No branches or pull requests

2 participants