Search code examples
kuberneteskubernetes-helmgo-templates

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


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

Solution

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

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