Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 426
Juan. Avatar asked Sep 21 '25 08:09

Juan.


2 Answers

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

env: {{- include "envs.var" .Values.secret.data | nindent 12  }}
like image 157
hoque Avatar answered Sep 22 '25 21:09

hoque


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.
like image 40
craftsmannadeem Avatar answered Sep 22 '25 22:09

craftsmannadeem