go - 带 Helm 的尺码表

标签 go kubernetes-helm go-templates sprig-template-functions

一个简单的问题,是否可以通过 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/

相关文章:

go - 如何使用 gdb 调试 go 测试

yaml - 如何通过 CLI 覆盖 helm 环境变量?

通过 Helm 的 Postgresql 未安装

kubernetes - 对于 Helm chart ,有哪些版本可用?

file - 如何解决模板: pattern matches no files

Golang - 文本/模板返回键值

正则表达式一个或多个 vs n+1 匹配

go - 服务器未从 GO 中的 TCP 客户端接收数据

go - 如何比较go模板中的字符串?

kubernetes-helm - 如何在三元语句中连接变量?