将YAML转换为JSON时出现错误:YAML:第24行:没有找到期望的键



获取错误Postgres服务部署失败。用yamllint检查yaml,它是有效的,但仍然得到错误。部署文件包含ServiceAccount、Service和statfulset。

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. 是否有任何无效的yaml语法?
  2. 是否缺少缩进?
  3. 这里缺少哪个节点?
{{- 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 }}

helm(和它的golang文本/模板对等体)中的模板必须是一个令牌,否则yaml认为{打开一个字典,然后{试图打开一个字典,就像在JSON中一样,这不是一个有效的结构

所以你需要:

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