一个简单的问题,是否可以通过 helm 和 sprig 函数获取尺寸列表?
我的 list :
list:
- a
- b
- c
我试过这样的:
{{ .Values.list | len }}
{{ .Values.list | size }}
{{ .Values.list | length }}
最佳答案
查看此 How to compare the length of a list in html/template in golang? .
While we talk about the “Helm template language” as if it is Helm-specific, it is actually a combination of the Go template language, some extra functions, and a variety of wrappers to expose certain objects to the templates. Many resources on Go templates may be helpful as you learn about templating.
引用:https://helm.sh/docs/chart_template_guide/#template-functions-and-pipelines
因此您可以使用 go-template
(text/template
包)中的 len
函数。
示例:
values.yaml
内容:
list:
- a
- b
- c
template/list.yaml
内容:
kind: List
spec:
len: {{ len .Values.list }}
items:
{{- range $item := .Values.list }}
- {{ $item }}
{{- end }}
关于go - 带 Helm 的尺码表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55741463/