Helm 遍历对象数组

问题描述 投票:0回答:1

我有以下对象数组

--------------------------
customizedFactorImplVolume:
  - name: PasswordAuthn
    customFactorProviderDir: PasswordDir

  - name: FaceIdAuthn
    customFactorProviderDir: FaceIdDir 
--------------

当它作为“helm install --name jenkins -f my-values.yaml”传递时,我可以使用 deployment.yaml 中的“range”对其进行迭代。但是当我使用“--set”头盔选项传递值时无法读取它时:

--设置 customfactor.customizedFactorImplVolume[0].customFactorProviderDir=PasswordAuthentication --set customfactor.customizedFactorImplVolume[0].name=密码 --set customfactor.customizedFactorImplVolume[1].customFactorProviderDir=FaceIdAuthn --set customfactor.customizedFactorImplVolume[1].name=faceid

不确定“--set”有什么问题(“range helm api 正在获取空值)。任何帮助将不胜感激。

arrays loops kubernetes-helm
1个回答
4
投票

这是引用数组元素的问题。

values.yaml

customizedFactorImplVolume:
  - name: PasswordAuthn
    customFactorProviderDir: PasswordDir

  - name: FaceIdAuthn
    customFactorProviderDir: FaceIdDir 

模板/cfg.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  {{- range $v := .Values.customizedFactorImplVolume }}
  - name: {{ $v.name }}
    customFactorProviderDir: {{ $v.customFactorProviderDir }}
  {{- end }}

命令

helm template test . --set customizedFactorImplVolume.0.name=n0 --set customizedFactorImplVolume.0.customFactorProviderDir=d0 --set customizedFactorImplVolume.1.name=n1 --set customizedFactorImplVolume.1.customFactorProviderDir=d1

输出

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  - name: n0
    customFactorProviderDir: d0
  - name: n1
    customFactorProviderDir: d1
© www.soinside.com 2019 - 2024. All rights reserved.