给定以下值。yaml
configurations:
endpoints:
- firstEndpoint
- firstPath
- secondPath
- secondEndpoint
- thirdPath
- fourthPath
我需要通过以下方式从这些值生成不同的资源:
- name: firstEndpoint
paths:
- firstPath
- secondPath
- name: secondEndpoint
paths:
- thirdPath
- fourthPath
如果";端点";是一个映射,而不是一个列表/数组,但在这种情况下,我需要";端点";作为端点列表;路径";为每个端点的路径列表。
这是如何实现的?
正如David Maze所说。您建议的终结点:无效。
你可以试试这个:
values.yaml
configurations:
endpoints:
- firstEndpoint:
- firstPath
- secondPath
- secondEndpoint:
- thirdPath
- fourthPath
(注意firstEndpoint
和secondEndpoint
之后的:
(
template/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