【问题标题】:Size list with helm带掌舵的尺码表
【发布时间】:2019-04-18 07:52:54
【问题描述】:

简单的问题是否可以使用 helm 和 sprig 函数获取大小列表?

我的清单:

list:
 - a
 - b
 - c

我试过这样:

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

【问题讨论】:

  • 发生了什么?

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


【解决方案1】:

看到这个How to compare the length of a list in html/template in golang?

当我们谈论“Helm 模板语言”时,好像它是 Helm-specific,它实际上是 Go 模板的组合 语言,一些额外的功能,以及各种要公开的包装器 模板的某些对象。 Go 模板上的许多资源可能 在您学习模板时会有所帮助。

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

所以你可以使用go-templatetext/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 }}

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 2017-04-08
    • 2018-12-11
    • 2019-10-07
    • 2022-12-02
    • 2021-03-11
    • 2018-06-02
    • 2020-11-07
    • 2021-06-13
    相关资源
    最近更新 更多