Questions tagged [sprig-template-functions]

Questions about using the Sprig template functions. These are extensions to the Go text/template syntax that provide a variety of common support functions, including string and list manipulation. They are included in tools like Helm.

Sprig is a set of extension functions to the system. These support Go data types such as slices (lists) and maps (dictionaries), and provide a set of basic string-manipulation and arithmetic functions.

For example, a chart could be configured with a list of options that needs to be passed as a comma-separated list. In the core Go text/template language, you would need a complex range loop, but you can directly use the Sprig join function instead:

- name: OPTIONS
  value: {{ .Values.options | join "," }}
  #                           ^^^^

Use this tag on questions that use the language and specifically involve the Sprig extensions. Questions with this tag will almost always also be tagged with , and generally also with the main tool being used such as or .

46 questions
30
votes
2 answers

go-template split string by delimiter

I have my own helm chart and I'm trying to perform split without using the _helpers.tpl in one line my values.yaml file content: deployment: domain: my.domain I need to split domain name in my template file: my.domain I have tried to perform…
dsaydon
  • 4,421
  • 6
  • 48
  • 52
11
votes
1 answer

Alternative for .Release.Time in Helm v3

Since Helm v3 built-in object .Release.Time is removed. What is the preferred way of injecting a release time into a template now?
Aleksandr Erokhin
  • 1,904
  • 3
  • 17
  • 32
10
votes
3 answers

Helm chart fails with "nil pointer evaluating interface {}" when trying to evaluate a missing nested key

I am writing a Helm 3 library chart and would like to create a YAML with default values. However, when trying to set a default value for a nested key that does not exist, Helm fails with the following error message: nil pointer evaluating interface…
mittelmania
  • 3,393
  • 4
  • 23
  • 48
6
votes
1 answer

helm - replace special chars with underscore

New to k8s & helm. Trying to declare a field in a deployment using the {{ .Release.Name }}, that must not contain characters other than letters (upper + lower), digits and _. Excluded characters should be replaced with _, for…
NI6
  • 2,477
  • 5
  • 17
  • 28
6
votes
3 answers

Creating a filtered list using helm template helpers

I'm trying to use a helm template helper to filter out values from a list in my values.yaml file, based on the value of one of the keys in each list member. My chart is currently comprised of these files - values.yaml - namespaces: - name: filter …
6
votes
1 answer

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 }}
M.Hol
  • 365
  • 2
  • 4
  • 15
5
votes
2 answers

Combining two if conditions into one

The below works {{- if hasKey (index $envAll.Values.policy) "type" }} {{- if has "two-wheeler" (index $envAll.Values.policy "type") }} {{- end }} {{- end }} while the below fails with "runtime error: invalid memory address or nil…
Hem
  • 619
  • 13
  • 26
4
votes
4 answers

Convert yaml to property file in helm template

I would like to convert a part of the structure in values.yaml to properties file in a config map. Is it possible to convert a yaml structure like: field1: value1 field2: field21: value21 field22:…
abinet
  • 2,552
  • 1
  • 15
  • 24
3
votes
1 answer

How do I concatenate strings inside a variable assignment?

I'm trying to assign the output of a function to a var and append to the string at the same time but can't figure out the right syntax. None of these examples work: {{- $myvar := include "mychart.helper" . "-myprefix" -}} {{- $myvar := {{include…
red888
  • 27,709
  • 55
  • 204
  • 392
3
votes
1 answer

Use Helm to Loop thru lines of dotenv file and render as key-value pair in ConfigMap

I have this .env file : REACT_APP_API_ENDPOINT=http://api.app:8080 REACT_APP_GOOGLE_ANALY=xyz1234ezyz I want to build a configmap out of this .env file which looks like : apiVersion: v1 kind: ConfigMap metadata: name: frontend-config data: …
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
3
votes
0 answers

How to merge 2 lists together (of containers) in helm?

I'm trying to create my own chart library from tutorial: https://helm.sh/docs/topics/library_charts/ . In the tutorial, there is really nice function, which merges 2 yamls together: {{- define "libchart.util.merge" -}} {{- $top := first . -}} {{-…
sacherus
  • 1,614
  • 2
  • 20
  • 27
3
votes
1 answer

Encode integer in Helm template

I am working on a set of Helm templates for a web service, which takes as part of it's configuration an integer Id. That Id becomes part of the service endpoints, encoded to a web-safe base64 character set: 0=A 1=B 2=C ... 26=a ... 63=_ Within my…
superstator
  • 3,005
  • 1
  • 33
  • 43
3
votes
1 answer

Add suffix to each list member in helm template

I'm trying to iterate over a list in a helm template, and add a suffix to each member. I currently have this block of code that does exactly that: {{- range $host := .Values.ingress.hosts }} {{- $subdomain := initial (initial (splitList "."…
Yaron Idan
  • 6,207
  • 5
  • 44
  • 66
2
votes
1 answer

Regex to match n times for helm

To match these examples: 1-10-1 1-7-3 10-8-5 1-7-14 11-10-12 This regex works: ^[\\d]{1,2}-[\\d]{1,2}-[\\d]{1,2}$ How could this be written in a way that just matches something like "[\d]{1,2}-?" three (n) times?
carrotcakeslayer
  • 809
  • 2
  • 9
  • 33
2
votes
1 answer

What does the syntax `default (dict) .Values.outer.inner` mean in a helm template?

Given values.yaml: outer: inner: someKey: false What does the following syntax in a helm template file mean? {{- if index (default (dict) .Values.outer.inner) "someKey" }} {{- .... }} {{- end }} From context, I can infer what I think…
jordanpg
  • 6,386
  • 4
  • 46
  • 70
1
2 3 4