helm: Error converting YAML to JSON could not find expected ':'

I have just run into very curious bug with (.Files.Glob "configOverrides/*").AsConfig Suddenly one of my services charts started to fail on helm upgrade with obscure

Error: UPGRADE FAILED: YAML parse error on web/templates/config.yaml: error converting YAML to JSON: yaml: line 12: could not find expected ':'

But the weird thing was that other almost identical chart was succeeding. Both of them have pretty standard

kind: ConfigMap
apiVersion: v1
metadata:
  name: {{.Chart.Name}}
  labels:
    app: {{.Values.Application}}
    release: "{{.Release.Name}}"
    component: {{.Chart.Name}}
    version: "{{.Chart.Version}}"
data:
  {{ (.Files.Glob "configOverrides/*").AsConfig | indent 2 }}

both of them incude appconfig.json file that is valid json and encoded with UTF-8 without BOM and the only difference in appconfig.json file that I was able to find was one “space” in it. After some testing: Even having config file as simple as

{<LF>
  "x": "x"<LF>
}

is failing with error above but as soon as I add space at the end of if

{<LF>
  "x": "x" <LF>
}

it works fine… also it works fine if config has no space but <CRLF> instead of <LF>

Env: Helm version 2.2 running in ubuntu 16.04 based docker container

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (4 by maintainers)

Most upvoted comments

For what it’s worth, I found that I no longer get an error with multi-line files if I change my ConfigMap template to the following:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}-configs
data:
  config.properties: |-
{{ .Files.Get "config.properties" | indent 4 }}

Notice that {{ .Files.Get "config.properties" | indent 4 }} is outdented to the same level as the data key.

Is there a way to have helm output the bad yaml so we can debug?

Happens due to a minor indent (1 instead of two, or two instead of four), in a wrong place.

I haven’t seen it for a while, so I am closing this

I’m having a similar issue. When I have a ConfigMap template defined as follows:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}-configs
data:
  config.properties: |-
  {{ .Files.Get "config.properties" | indent 2 }}

And, config.properties contains multiple lines:

property1=some property value
property2=some other property value
property3=yet another property value

I receive the following error: Error: UPGRADE FAILED: YAML parse error on my-chart/templates/my-configs.yaml: error converting YAML to JSON: yaml: line 8: could not find expected ':'

However, it works fine if config.properties contains only one line, as follows:

property1=some property value

I don’t know whether this helps

test.json

{
    "asdfasdfasdf": "asd"
}

This return error converting YAML to JSON: yaml: line 8: did not find expected key

apiVersion: v1
kind: ConfigMap
metadata:
  name: profile
data:
  token: |-
    {{ .Files.Get "files/test.json" }}

This return same error

apiVersion: v1
kind: ConfigMap
metadata:
  name: profile
data:
  token: |-
  {{ .Files.Get "files/test.json" | indent 2}}

This works

apiVersion: v1
kind: ConfigMap
metadata:
  name: profile
data:
  token: |-
{{ .Files.Get "files/test.json" | indent 4}}

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: mysql spec: selector: matchLabels: app: mysql8 strategy: type: Recreate template: metadata: labels: app: mysql8 spec: containers:

  • image: mysql:8.0 name: mysql imagePullPolicy: Never env:
  • name: MYSQL_ROOT_PASSWORD value: .sweetpwd.
  • name: MYSQL_DATABASE value: my_db
  • name: MYSQL_USER value: db_user
  • name: MYSQL_PASSWORD value: .mypwd args: [“–default-authentication-plugin=mysql_native_password”] ports:
    • containerPort: 3306 name: mysql8

I got this error while writing config maps object using Helm . This error had nothing to do with YAML but more with quotations

I was getting following

 error converting YAML to JSON: yaml: line 12: did not find expected key

Debugging:

I ran helm in debug and dry-run mode to see what was the property file format getting outputted

helm install --debug --name my-release-name ./my-superawesome-chart --dry-run

Solution:

Use quote method in the templates/your-config-map-definition.yaml


$ cat templates/your-config-map-definition.yaml

 ---
apiVersion: v1
kind: ConfigMap
metadata:
 name: my-superawesome-app
data:
 application.properties: {{ .Files.Get "application.properties" | quote }}

It happen when i didn’t add metadata section in the nested template object, namely with cronjob (spec > jobTemplate > spec > template > spec) :

The error appeared when it was :

kind: CronJob
metadata:
  name: scheduler-{{ include "laravel.fullname" . }}
  labels:
    {{- include "laravel.labels" . | nindent 4 }}
spec:
  schedule: "{{ .Values.scheduler.schedule }}"
  jobTemplate:
    spec:
      template:
        spec:
          # containers: ...

And the error disappears when it is :

kind: CronJob
metadata:
  name: scheduler-{{ include "laravel.fullname" . }}
  labels:
    {{- include "laravel.labels" . | nindent 4 }}
spec:
  schedule: "{{ .Values.scheduler.schedule }}"
  jobTemplate:
    metadata:
      labels:
        {{- include "laravel.labels" . | nindent 8 }}
    spec:
      template:
        metadata:
          labels:
            {{- include "laravel.labels" . | nindent 12 }}
        spec:
          # containers: ...

this seems to work , but how do i make application.properties per environment ? example dev has different contents , qa has different and prod has different

$ cat templates/config-map.yaml


apiVersion: v1
kind: ConfigMap
metadata:
  name: my-schooltest-app
data:
  config_dev.json: |-
{{ .Files.Get "conf/config_dev.json" | indent 4}}
  config_qa.json: |-
{{ .Files.Get "conf/config_qa.json" | indent 4}}    

config_dev.json (same as config_qa.json)

{
  "students": [
    {
      "name": "test1",
      "proffesion": "Engineer",
      "subjectCodes": [
        "SOCIAL",
        "SCIENCE",
        "MATHS"
      ]
    },
    {
      "name": "test2",
      "proffesion": "Engineer",
      "subjectCodes": [
        "ENGLISH",
        "TAMIL"
      ]
    }
  ],
  "allowedSubjects": [
    "SOCIAL",
    "SCIENCE",
    "MATHS",
    "ENGLISH",
	"TAMIL"
  ],
  "school": "trm",
  "headmaster": [
    "Test5"
  ]
}

I am having an issue in update the config file using the below command

kubectl apply -f helm/templates/config-map.yaml -n $NAMESPACE

**

error: error parsing helm/templates/config-map.yaml: error converting YAML to JSON: yaml: line 8: could not find expected ‘:’

**

Note: When I do the helm install deployment, it works fine. But my requirement is update the configmap without restarting the pod Tried : is outdented to the same level as the data key as well

The error message in my case was quite cryptic, it was just complaining about a “line 8” without saying what file to look into. Like this basically: Error: UPGRADE FAILED: yaml: line 8: could not find expected ':'

I solved by running helm lint on it which was a lot more verbose in my case and it helped me identify the “bad” line.

The output with the lint was:

$ helm lint reducers
==> Linting reducers
[INFO] Chart.yaml: icon is recommended
[ERROR] templates/: render error in "reducers/templates/configmap.yaml": template: reducers/templates/configmap.yaml:24:27: executing "reducers/templates/configmap.yaml" at <.Values.global.kafka...>: can't evaluate field kafkaUrl in type interface {}

Error: 1 chart(s) linted, 1 chart(s) failed

Which of course has nothing to do with any line 8 but it definitely highlighted the right problem 👍