Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size list with helm

Simple question is it possible to get size list with helm and sprig function ?

My list :

list:
 - a
 - b
 - c

I tried like this :

{{ .Values.list | len }}
{{ .Values.list | size }}
{{ .Values.list | length }}
like image 302
M.Hol Avatar asked May 13 '26 16:05

M.Hol


1 Answers

See this 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.

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

So you can use len function from go-template (text/template package).

Example:

values.yaml contents:

list:
  - a
  - b
  - c

template/list.yaml contents:

kind: List
spec:
  len: {{ len .Values.list }}
  items:
{{- range $item := .Values.list }}
    - {{ $item }}
{{- end }}
like image 59
Shudipta Sharma Avatar answered May 15 '26 09:05

Shudipta Sharma