Helm Config-Map with yaml file

5/22/2019

I am trying to access a file inside my helm templates as a config map, like below. I get an error as below.

However, it works when my application.yml doesn't have nested objects (Eg - name: test). Any ideas on what I could be doing wrong?

config-map.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
 name: {{ .Release.Name }}-configmap

data:
 {{.Files.Get “application.yml”}}

application.yml:

some-config:
 application:
   name: some-application-name

ERROR:

*ConfigMap in version “v1" cannot be handled as a ConfigMap: v1.ConfigMap.Data: ReadString: expects ” or n, but found {, error found in #10 byte of ...|ication”* 
-- zooes
kubernetes
kubernetes-helm

2 Answers

5/24/2019

As per documentation:

Templates should be indented using two spaces (never tabs). Template directives should have whitespace after the opening braces and before the closing braces.

finally it should looks like:

{{ .Files.Get "application.yml" | nindent 2 }}
or 
{{- .Files.Get "application.yml" | nindent 2 }}
to chomp whitespace on the left
-- Hanx
Source: StackOverflow

5/22/2019

Looks like you have an indentation issue on your application.yaml file. Perhaps invalid YAML? If I try your very same files I get the following:

  helm template ./mychart -x templates/configmap.yaml
---
# Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
 name: release-name-configmap
data:
  some-config:
 application:
   name: some-application-name
-- Rico
Source: StackOverflow