helm 迭代列表列表

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

给定以下值.yaml

configurations:
  endpoints:
    - firstEndpoint
      - firstPath
      - secondPath
    - secondEndpoint
      - thirdPath
      - fourthPath

我需要通过以下方式从这些值生成不同的资源:

- name: firstEndpoint
  paths:
    - firstPath
    - secondPath

- name: secondEndpoint
  paths:
    - thirdPath
    - fourthPath

如果“端点”是一个地图,而不是一个列表/数组,我可以这样做,但在这种情况下,我需要“端点”是端点列表,“路径”是路径列表每个端点。

如何实现这一目标?

kubernetes-helm
1个回答
1
投票

正如大卫梅兹所说。您建议的端点:无效。

你可以试试这个:

values.yaml

configurations:
  endpoints:
    - firstEndpoint:
      - firstPath
      - secondPath
    - secondEndpoint:
      - thirdPath
      - fourthPath

(注意

:
firstEndpoint
后面的
secondEndpoint

模板/cm.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  test: |-
    {{- range $_, $item := .Values.configurations.endpoints }}
    {{- range $k, $v := . }}
    - name: {{ $k }}
      path:
      {{- range $_, $path := $v }}
        - {{ $path }}
      {{- end }}
    {{- end }}
    {{- end }}

输出

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  test: |-
    - name: firstEndpoint
      path:
        - firstPath
        - secondPath
    - name: secondEndpoint
      path:
        - thirdPath
        - fourthPath
© www.soinside.com 2019 - 2024. All rights reserved.