Helm Chart configmap from yml file

2/19/2019

I created ConfigMap in helm

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
    {{- $root := . -}}
    {{- range $path, $bytes := .Files.Glob "*.yml"}}
    {{ $path }}: '{{ $root.Files.Get $path }}'
    {{- end }}

When I run kubectl get configmaps, the yml file format changed to a different file format adding "\" to the yml file. How can I prevent helm from changing the file format ?

-- Lumine
configmap
kubernetes-helm

1 Answer

2/20/2019
apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
    {{- $root := . -}}
    {{- range $path, $bytes := .Files.Glob "*.yml"}}
    {{- $value := $root.Files.Get $path -}}
    {{- printf "\n" | nindent 2 -}}
    {{ $path | nindent 2 }}: {{- toYaml $value | nindent 4 }}
    {{- end }}

You can use something like above.

What I've done:

  • save the file content in $value variable.
  • later pass $value variable to toYaml function and nindent with 4
  • use toYaml template function, so that helm doesn't change the file content.
-- Abu Hanifa
Source: StackOverflow