1

I can create a ConfigMap without issues with kubectl create configmap settings --from-file settings.yaml, but I don't want to manually create it but as part of a helm install.

So, I created a template file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.settingsConfigMap }}
data:
  settings.yaml: |-
{{ .Files.Get "settings.yaml" | indent 4}}

but whenever I run helm install I get an error saying that

invalid type for io.k8s.api.core.v1.ConfigMap.data: got "map", expected "string"

So, what can I do to create this ConfigMap with Helm loading the content from a YAML file?

UPDATE

It turns out the error mentioned above is related to some issues with the indentation. By removing the indent 4, I managed to get a step further, but now it's failing because all my settings are detected as unknown fields, for example:

unknown field "customers" in io.k8s.api.core.v1.ConfigMap, ValidationError(ConfigMap): unknown field "deploy_name" in io.k8s.api.core.v1.ConfigMap, ValidationError(ConfigMap): unknown field "system" in io.k8s.api.core.v1.ConfigMap

deploy_name, system and customers are the top level keys of my settings.yaml file.

2
  • Which helm version are you using? Can you try to update to newer? It works for me with v3.2.4 Commented Oct 13, 2020 at 9:31
  • @thomas version.BuildInfo{Version:"v3.3.4", GitCommit:"a61ce5633af99708171414353ed49547cf05013d", GitTreeState:"dirty", GoVersion:"go1.15.2"} Commented Oct 13, 2020 at 9:56

1 Answer 1

2

I found the answer.

The error mentioned in the update is the outcome of removing indent 4. By removing that, the YAML used by Helm is screwed up, hence that's why it doesn't understand those fields.

So, why did it fail when I had the indent 4? The reason is the missing white space before the }. With {{ .Files.Get "settings.yaml" | indent 4 }}, everything is good.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.