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
1
vote
0 answers

Html template parse with sprig does not work in go

I am very new to golang and trying to use sprig package with html/template. I am converting the template to PDF. I get a blank response in postman when I use the below code(parseFiles). tempPath variable is just a string with the path to my html…
girish
  • 302
  • 1
  • 5
  • 17
1
vote
3 answers

How to call toYaml and exclude particular key?

Inside the template I have a fragment like this: props: {{- toYaml .Values.myApp.container.props }} currently props contains 4 children: ... container: props: a: ... b: ... c: ... d: ... But I want to…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
1
vote
0 answers

Helm has/merge option for overrides

I am trying to create a template whereby values have a default set of service names, unless they are overriden. example: default: service: - name: nginx1 service: "dev-nginx1" port: 8080 - name: nginx2 service:…
Rygo
  • 159
  • 1
  • 8
1
vote
1 answer

In Go templates/Sprig, how to modify a captured group in a regular expression before replacing it?

I'd like to write a Go template which takes in a URL with a query parameter earliest which represents a relative time, e.g. earliest=-15m, and converts it to an absolute time relative to now as a Unix timestamp. So for example,…
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
1
vote
1 answer

helm chart / go-template | Translate environment variables from string

I have a general helm chart in my Kubernetes cluster taking a multiline text field with environment variables (identified by KEY=VALUE), translating them into the deployment.yaml like this: Inside the Rancher dialog: In the deployment.yaml: {{- if…
1
vote
2 answers

How do I conditionally declare variables in go templates?

I am working on helmfile and stuck at the point where I want the conditional variable declaration. Roughly like this but in go standard templates. ENV = "prod" folder = "" if ENV == "prod": folder = "production" elif ENV == "qa" folder ==…
yogen48
  • 111
  • 1
  • 3
1
vote
1 answer

Evaluate condition from value file in Helm template

When I have a line in my values.yaml file: condition: "eq .Release.Namespace dev" Can I evaluate this in the template somehow? {{- if .condition }} status: "development" {{- end }} I've tried to do the above but that is not working, is there…
Ravenix
  • 1,010
  • 4
  • 15
  • 40
1
vote
1 answer

Is there a way to define custom Go Template Actions

Is there a way to define custom "Actions" (like range, if, block, etc) with either text or html go templates. I would like to achieve something like the following: {{ component "blog_post" . }} {{ template "title" . }} {{ component "content" .…
1
vote
1 answer

How to access individual element from a list inside a helm chart

I am trying to access the individual value from an array available in values.yaml file from my helmchart. My values.yaml file content peer_cidr: - x - y - z Accessing from helm chart : {{- $dn_count := len .Values.no_of_peers }} …
Balaganesh.V
  • 85
  • 1
  • 9
1
vote
1 answer

Not able to refer the index inside the range function in yaml files

I am trying dynamically assigning the values from separate values.yaml file to a variable. My values.yaml file content peer_cidr1 = x peer_cidr2 = y peer_cidr3 = z Yaml file: {{- $root := . -}} {{ range $i, $dn := until (atoi (printf "%d"…
1
vote
1 answer

Helm sprig template pipe and/or negatate

I'm trying to create my config map in helm using the following code: api: "{{ .Values.global.api }}", demo: {{ .Values.global.api | contains "demo" }}, other: ...., I would like to set other as true if Values.global.api NOT contains "demo" and…
Fabry
  • 1,498
  • 4
  • 23
  • 47
1
vote
1 answer

loop thru lines of plain text file passed by --set-file helm option then parse each line by column

I have a cron file and i am trying to pass it thru --set-file option. I want to loop thru the cron file lines and create for each line new Kubernetes Object of kind CronJob. I used it like this helm instal ... --set-file crons.file=mycron where…
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
1
vote
1 answer

How do you pass a variable value to .Files.Glob in a Helm chart?

The invocation of .Files.Glob below needs to be from a variable supplied as a value from .Values.initDBFilesGlob. The value is getting set properly, but the if condition is not evaluating to truthy, even though .Values.initDBConfigMap is empty. How…
Matthew Adams
  • 2,059
  • 2
  • 21
  • 31
1
vote
1 answer

Make sure path in Go template always ends with slash

I am writing a Helm chart for a bunch of deployments. I am supplying a value which can be: my_value: "/opt/my-path"or my_value: "/opt/my-path/" Now I would want to make sure that there is always a single / at the end of the path. How do I do this…
Hedge
  • 16,142
  • 42
  • 141
  • 246
1
vote
2 answers

Helm3 - Reading json file into configmap produces a string?

Problem: I want to read a json file into a configmap so it looks like: apiVersion: v1 kind: ConfigMap metadata: name: json-test data: test.json: |- { "key": "val" } Instead I get apiVersion: v1 kind: ConfigMap metadata: name:…