Helm error converting YAML to JSON: yaml: line 24: did not find expected key

Viewed 2798

Getting error postgres deployment for service is getting fail. Checked yaml with yamllint and it is valid, but still getting the error. Deployment file contains ServiceAccount , Service and Statefulset.

install.go:158: [debug] Original chart version: ""
install.go:175: [debug] CHART PATH: /builds/xxx/xyxy/xyxyxy/xx/xxyy/src/main/helm
Error: YAML parse error on postgresdeployment.yaml: error converting YAML to JSON: yaml: line 24: did not find expected key
helm.go:75: [debug] error converting YAML to JSON: yaml: line 24: did not find expected key
YAML parse error on postgresdeployment.yaml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
    /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:146
helm.sh/helm/v3/pkg/releaseutil.SortManifests
    /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:106
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
    /home/circleci/helm.sh/helm/pkg/action/install.go:489
helm.sh/helm/v3/pkg/action.(*Install).Run
    /home/circleci/helm.sh/helm/pkg/action/install.go:230
main.runInstall
    /home/circleci/helm.sh/helm/cmd/helm/install.go:223
main.newUpgradeCmd.func1
    /home/circleci/helm.sh/helm/cmd/helm/upgrade.go:113
github.com/spf13/cobra.(*Command).execute
    /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:826
github.com/spf13/cobra.(*Command).ExecuteC
    /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914
github.com/spf13/cobra.(*Command).Execute
    /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
main.main
    /home/circleci/helm.sh/helm/cmd/helm/helm.go:74
runtime.main
    /usr/local/go/src/runtime/proc.go:203
runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1357
    

postgresdeployment.yaml

  1. Is there is any invalid yaml syntax?
  2. Any indentation is missing ?
  3. Which node is missing here?
{{- if contains "-dev" .Values.istio.suffix }}
# Postgre ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
  name: postgres
---
# PostgreSQL StatefulSet Service
apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  selector:
    app: postgres
  ports:
    - port: 5432
      targetPort: 5432
---
# Postgre StatefulSet
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: postgres
    spec:
        serviceAccountName: postgres
        securityContext:
          {{- toYaml .Values.securityContext | nindent 8 }}
        terminationGracePeriodSeconds: {{ default 60 .Values.terminationGracePeriodSeconds }}
        volumes:
        {{ include "xxx.volumes.logs.spec" . | indent 8 }}
        - emptyDir: { }
            name: postgres-disk
        containers:
          - name: postgres
            image: "{{ template "xxx.dockerRegistry.hostport" . }}/postgres:latest"
            imagePullPolicy: {{ .Values.image.pullPolicy }}
            ports:
              - name: postgres
                containerPort: 5432
            livenessProbe:
              tcpSocket:
                port: 5432
              failureThreshold: 3
              initialDelaySeconds: 240
              periodSeconds: 45
              timeoutSeconds: 5
            readinessProbe:
              tcpSocket:
                port: 5432
              failureThreshold: 2
              initialDelaySeconds: 180
              periodSeconds: 5
              timeoutSeconds: 20
            resources:
              {{ if .Values.lowResourceMode }}
                {{- toYaml .Values.resources.low | nindent 12 }}
                {{ else }}
                {{- toYaml .Values.resources.high | nindent 12 }}
                {{ end }}
            env:
              - name: PGDATA
                value: /var/lib/postgresql/data/pgdata
            volumeMounts:
              - name: postgres-disk
                mountPath: /var/lib/postgresql/data
{{- end }}
1 Answers

The templating mustaches in helm (and its golang text/template peer) must be one token, otherwise yaml believes that { opens a dict, and then { tries to open a child dict and just like in JSON that's not a valid structure

So you'll want:

        serviceAccountName: postgres
        securityContext:
          {{- toYaml .Values.securityContext | nindent 8 }}
Related