Helm 图表:引用一个秘密给名称:%!s(<nil>)-%!s(<nil>)

Helm chart: reference a secret gives name: %!s(<nil>)-%!s(<nil>)

我正在创建 Helm 图表。干 运行 时出现错误:

Error: YAML parse error on vstsagent/templates/vsts-buildrelease-agent.yaml: error converting YAML to JSON: yaml: line 28: found character that cannot start any token

干运行 还输出我创建的秘密和部署 YAML 文件。部署出错的部分显示:

      - name: ACCOUNT
        valueFrom:
          secretKeyRef:
            name: %!s(<nil>)-%!s(<nil>)
            key: ACCOUNT
      - name: TOKEN
        valueFrom:
          secretKeyRef:
            name:  %!s(<nil>)-%!s(<nil>)
            key: TOKEN

秘密的干燥 运行 的输出看起来不错。

我创建的模板:

apiVersion: v1
kind: Secret
metadata:
  name: {{ template "chart.fullname" . }}
type: Opaque
data:
 ACCOUNT: {{ .Values.chart.secret.account }}
 TOKEN: {{ .Values.chart.secret.token }}


apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "chart.fullname" . }}
  labels:
    app: {{ template "chart.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        release: {{ .Release.Name }}
        app: {{ template "chart.name" . }}
      annotations:
        agentVersion: {{ .Values.chart.image.tag }}
      spec:
        containers:
          - name: {{ template "chart.name" . }}
            image: {{ .Values.chart.image.name }}
            imagePullPolicy: {{ .Values.chart.image.pullPolicy }}
            env:
              - name: ACCOUNT
                valueFrom:
                  secretKeyRef:
                    name: {{ template "chart.fullname" }}
                    key: ACCOUNT
              - name: TOKEN
                valueFrom:
                  secretKeyRef:
                    name:  {{ template "chart.fullname" }}
                    key: TOKEN

_helper.tpl 看起来像这样:

{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "chart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "chart.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

我哪里错了?

我漏了 2 个点....

      - name: ACCOUNT
        valueFrom:
          secretKeyRef:
            name: {{ template "chart.fullname" . }}
            key: ACCOUNT
      - name: TOKEN
        valueFrom:
          secretKeyRef:
            name:  {{ template "chart.fullname" . }}
            key: TOKEN