头盔切片未找到匹配项

zer*_*ing 7 kubernetes kubernetes-helm

我在 helm 中有以下define定义:

{{- define "svc.envVars" -}}
{{- range .Values.envVars.withSecret }}
- name: {{ .key }}
  valueFrom:
    secretKeyRef:
      name: {{ .secretName }}
      key: {{ .secretKey | quote }}
{{- end }}
{{- range .Values.envVars.withoutSecret }}
- name: {{ .name }}
  value: {{ .value | quote }}
{{- end }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)

我将用它deployment.yaml

  containers:
    - name: {{ .Release.Name }}
      image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
      imagePullPolicy: {{ .Values.image.pullPolicy }}
      {{- if .Values.envVars.enabled }}
      env:
      {{- include "svc.envVars" . | indent 10 }} 
      {{- end }}
      ports:
        - name: http
          containerPort: 8080
          protocol: TCP
      livenessProbe:
        httpGet:
          path: /
          port: http
      readinessProbe:
        httpGet:
          path: /
          port: http
      resources:
        {{- toYaml .Values.resources | nindent 12 }}
Run Code Online (Sandbox Code Playgroud)

其中values.yaml定义如下:

envVars:
  enabled: false
  withSecret: []
  withoutSecret: []
Run Code Online (Sandbox Code Playgroud)

然后我尝试渲染:

helm template --debug user-svc \
  --set image.tag=0.1.0 \
  --set image.repository=user-svc \
  --set envVars.enabled=true \
  --set envVars.withSecret[0].key=POSTGRES_URL,envVars.withSecret[0].secretName=postgres_name,envVars.withSecret[0].secretKey=postgres_pw \
  --set envVars.withSecret[1].key=MYSQL_URL,envVars.withSecret[1].secretName=mysql_name,envVars.withSecret[1].secretKey=mysql_pw \
  ./svc
Run Code Online (Sandbox Code Playgroud)

它向我展示:

zsh: no matches found: envVars.withSecret[0].key=POSTGRES_URL,envVars.withSecret[0].secretName=postgres_name,envVars.withSecret[0].secretKey=postgres_pw
Run Code Online (Sandbox Code Playgroud)

当我手动设置变量时values.yaml

envVars:
  enabled: false
  withSecret:
    - key: POSTGRES_URL
      secretName: postgres_name
      secretKey: postgres_pw
    - key: MYSQL_URL
      secretName: mysql_name
      secretKey: mysql_pw  
  withoutSecret:
    - name: NOT_SECRET
      value: "Value of not serect"
Run Code Online (Sandbox Code Playgroud)

然后渲染它:

helm template --debug user-svc \
  --set image.tag=0.1.0 \
  --set image.repository=user-svc \
  --set envVars.enabled=true \
  ./svc
Run Code Online (Sandbox Code Playgroud)

然后它按预期工作。

我究竟做错了什么?

Hor*_*ley 15

我遇到过同样的问题。由于事实上, \xc2\xb4[\xc2\xb4 和 \xc2\xb4]\xc2\xb4 由 zsh 解释。\n您可以使用noglob来禁用全局变量。因此, \xc2\xb4[\xc2\xb4 和 \xc2\xb4]\xc2\xb4 不会被解释。

\n
noglob helm template --set lorem[0].ipsum=1337\n
Run Code Online (Sandbox Code Playgroud)\n

在你的例子中:

\n
noglob helm template --debug user-svc \\\n  --set image.tag=0.1.0 \\\n  --set image.repository=user-svc \\\n  --set envVars.enabled=true \\\n  --set envVars.withSecret[0].key=POSTGRES_URL,envVars.withSecret[0].secretName=postgres_name,envVars.withSecret[0].secretKey=postgres_pw \\\n  --set envVars.withSecret[1].key=MYSQL_URL,envVars.withSecret[1].secretName=mysql_name,envVars.withSecret[1].secretKey=mysql_pw \\\n  ./svc\n
Run Code Online (Sandbox Code Playgroud)\n

资料来源:

\n\n