Helm Error converting YAML to JSON: yaml: line 20: did not find expected key

13,364

Solution 1

Here this problem happens because of indent. You can resolve by updating

env: {{- include "envs.var" .Values.secret.data | nindent 12  }}

Solution 2

Simplest way to resolve this kind of issues is to use tools.

These are mostly indentation issues, and can be resolved very easily using the right tool

 npm install -g yaml-lint

yaml-lint is one such tool

 PS E:\vsc-workspaces\grafana-1> yamllint .\grafana.yaml
× YAML Lint failed for C:/Users/mnadeem6/vsc-workspaces/grafana-1/grafana.yaml
× bad indentation of a mapping entry at line 137, column 11:
          restartPolicy: Always
          ^
PS E:\vsc-workspaces\grafana-1> yamllint .\grafana.yaml
√ YAML Lint successful.
Share:
13,364
Juan.
Author by

Juan.

Updated on June 09, 2022

Comments

  • Juan.
    Juan. almost 2 years

    I don't really know what is the error here, is a simple helm deploy with a _helpers.tpl, it doesn't make sense and is probably a stupid mistake, the code:

    deploy.yaml

    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    {{ include "metadata.name" . }}-deploy
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 2 # tells deployment to run 2 pods matching the template
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.14.2
            ports:
            - containerPort: 80
            vars: {{- include "envs.var" .Values.secret.data }}
    

    _helpers.tpl

    {{- define "envs.var"}}
    {{- range $key := . }}
    - name: {{ $key | upper | quote}}
      valueFrom:
        secretKeyRef:
          key: {{ $key | lower }}
          name: {{ $key }}-auth
    {{- end }}
    {{- end }}
    

    values.yaml

    secret:
      data:
        username: root
        password: test
    

    the error

    Error: YAML parse error on mychart/templates/deploy.yaml: error converting YAML to JSON: yaml: line 21: did not find expected key
    
    • Will R.O.F.
      Will R.O.F. almost 4 years
      can you confirm if the solution provided below worked for you?
  • Juan.
    Juan. almost 4 years
    i cant believe the mistake was as stupid as using a wrong word, i guess i really was burned out, fixed it recently and then remembered about this question, thanks for the help anyway