21

I'm using Helm 3 and microk8s. When I try a dry run:

microk8s.helm install <...> --dry-run --debug

I see errors like

Error: YAML parse error on ./templates/deployment.yaml: error converting YAML to JSON: yaml: mapping values are not allowed in this context
helm.go:76: [debug] error converting YAML to JSON: yaml: mapping values are not allowed in this context
YAML parse error on ./templates/deployment.yaml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
    /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:129
helm.sh/helm/v3/pkg/releaseutil.SortManifests
    /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:98
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
    /home/circleci/helm.sh/helm/pkg/action/install.go:455
helm.sh/helm/v3/pkg/action.(*Install).Run
    /home/circleci/helm.sh/helm/pkg/action/install.go:214
main.runInstall
...

I found several questions with a similar error, but the answer is usually just asking for read a chart code. I have a large chart and need to debug this error on my own. And guessing which line it complains about doesn't seem meaningful.

Is there a way to know what exactly is wrong in the config?

Yann
  • 2,426
  • 1
  • 16
  • 33
  • 1
    I ran into this issue. I don't have a solution, but a recommendation. I solved it by getting the template back to a state where I knew it worked, then slowly introducing more templating until it got to a point where it broke. By doing this I was able to pin point 10 lines which were troublesome. Within those lines was a variable that had been renamed, and hence wasn't defined. – foxyblue May 18 '20 at 22:05
  • 2
    This is a great question. Helm 's `--debug` flag seems more directed at Helm developers debugging the Helm code, rather than users trying to figure out what the problem is with their chart, which is time-consuming using trial-and-error as @foxyblue describes. What's needed is a way to *see* that intermediate YAML that can't be converted to JSON.... – Ed Randall Jun 14 '20 at 08:14
  • Something I'm trying: a template which checks for a known list of required variables being set, in order to give a quick clear failure rather than the obscure one that sometimes happens when an unset value is referenced. `{{- define "assertions" -}} {{- range $key := (list "varName1" "varName2" "etc" ) }} {{- $ERRMSG := printf "ERROR: Missing required value for: .Values.%s" $key }} {{- $nop := required $ERRMSG (index $ $key) }} {{- end }} {{- end -}}` Use it in the top of each template.yaml file: `{{- template "assertions" .Values -}}` – Ed Randall Jun 14 '20 at 14:27
  • That's due to indenting problem of your helper file. – PPShein Sep 25 '20 at 15:27

1 Answers1

6

Try: helm template ... --debug > foo.yaml

This'll output the rendered chart to foo.yaml (and the helm error stacktrace to stderr). Then find the template filename in question from the helm error and look through the rendered chart for a line like # Source: the-template-name.yaml. YAML to JSON conversion is done separately for each YAML object, so you may have multiple instances of the same # Source: the-template-name.yaml.

Look n lines below each # Source: ... comment for an error, where n is the line number of the error reported by Helm render.

Eric Schoen
  • 668
  • 9
  • 16
  • I've just released an open source tool for debugging template issues like this directly in your browser: https://helm-playground.com – Martti Laine Dec 20 '21 at 11:15
  • Great answer. I was finally able to get my chart working! It appears that, if the file in question has multiple YAML documents (separated by `---` lines), you have to count `n` lines from the top of each sub-document. Even then, the line numbers are not exact. – Charlie Reitzel May 05 '22 at 19:29