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)
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:
Notice that
{{ .Files.Get "config.properties" | indent 4 }}
is outdented to the same level as thedata
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:
And,
config.properties
contains multiple lines: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:https://github.com/technosophos/helm-template
I don’t know whether this helps
test.json
This return
error converting YAML to JSON: yaml: line 8: did not find expected key
This return same error
This works
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:
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
Debugging:
I ran helm in debug and dry-run mode to see what was the property file format getting outputted
Solution:
Use quote method in the templates/your-config-map-definition.yaml
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 :
And the error disappears when it is :
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
config_dev.json (same as config_qa.json)
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:Which of course has nothing to do with any line 8 but it definitely highlighted the right problem 👍