头盔尺寸表

时间:2019-04-18 07:52:55

标签: go kubernetes-helm go-templates sprig

一个简单的问题,是否可以通过头盔和小树枝功能获得尺寸列表?

我的列表:

list:
 - a
 - b
 - c

我尝试过这样:

{{ .Values.list | len }}
{{ .Values.list | size }}
{{ .Values.list | length }}

1 个答案:

答案 0 :(得分:3)

请参阅此How to compare the length of a list in html/template in golang?

  

尽管我们谈论“头盔模板语言”   头盔专用,实际上是Go模板的组合   语言,一些额外的功能以及各种包装器   模板的某些对象。 Go模板上的许多资源可能   在学习模板方面会有所帮助。

ref:https://helm.sh/docs/chart_template_guide/#template-functions-and-pipelines

因此,您可以使用lengo-template包)中的text/template函数。

示例:

values.yaml内容:

list:
  - a
  - b
  - c

template/list.yaml内容:

kind: List
spec:
  len: {{ len .Values.list }}
  items:
{{- range $item := .Values.list }}
    - {{ $item }}
{{- end }}