Questions tagged [go-templates]

Go language supports built-in template functionality. Packages with this support include 1) text/template and; 2) html/template.

go-templates
Filter by
Sorted by
Tagged with
1 vote
1 answer
681 views

Helm default value throws error converting YAML to JSON

I have a basic kubernetes helm template like below apiVersion: v1 kind: ConfigMap metadata: name: test namespace: {{ .Release.Namespace }} labels: app.kubernetes.io/version: {{ .Chart....
anish's user avatar
  • 7,114
1 vote
0 answers
269 views

In a Helm template function, how can I iterate through a dictionary, and return the value of a key?

I have the following values.yaml file # Default region and repository aws_region: us-east-1 repository: 01234567890.dkr.ecr.us-east-1.amazonaws.com repositories: us-east-1: 01234567890.dkr.ecr.us-...
Chris F's user avatar
  • 15.5k
0 votes
1 answer
446 views

Pagination in hugo is not working as expected

I only want 5 post summaries to be displayed, per page, in my hugo theme In my config.toml file I have placed the following value: pagination = 5 My themes/<theme_name>/layouts/_default/list....
Molenpad's user avatar
  • 943
0 votes
1 answer
139 views

How to create helm variable with a comma

I'm wanting to create a helm variable with just a comma. I'm not sure how I'd do it? I ran into syntax issues with the below. {{- $asterisk := "*" }} {{- $comma := ",\" }} The ...
Albert's user avatar
  • 430
2 votes
1 answer
77 views

What is the difference between running a function in a .go file and invoking it in Go template?

With template.FuncMap from the text/template package, you can directly access functions from within your Go template files. Suppose the following scenario: In your handler for a user overview page, ...
nwtnsqrd's user avatar
0 votes
1 answer
386 views

Helm template syntax when using subcharts?

I asked Use one Helm chart for ALL microservices? and now I'm trying to implement the answer I accepted, i.e., using sub charts. (Note: If there's a better answer for that post, please put it in that ...
Chris F's user avatar
  • 15.5k
0 votes
1 answer
201 views

Prometheus go templating: error calling first: first() called on vector with no elements

I'm trying to query a label within annotations. Though I don't know how to handle empty vectors. The query works when there are existing results for the query but I cannot call first on empty vector. ...
simPod's user avatar
  • 12.5k
1 vote
0 answers
540 views

How to use regex in the Grafana Message Template and replace it

When an alert occurs, I want to create a template using Prometheus metric and value. There was no problem when the value string is 1 array string, but there is a problem when there are N. e.g) ...
Rightly's user avatar
  • 31
0 votes
1 answer
375 views

Is there a way to store arithmetic results into a helm variable?

I have a variable say : {{- $var := 7 -}} I need to perform an arithmetic operation involving this variable and store the result back into the same i.e for example var = var + 2 I tried doing : {{- $...
Aditya Vashist's user avatar
3 votes
1 answer
1k views

How to parse an embedded template in Go?

I'm trying to write a Go program that generates code and to use the embed package together with ParseFS to parse the template. The code should ultimately satisfy the requirement that it can be run ...
Kurt Peek's user avatar
  • 54.6k
0 votes
1 answer
504 views

Helm: render variable in a block inserted with toYaml

I have a variable block configuring triggers in a Keda scaled object like so: # [...] autoscaling: enabled: true triggers: - type: prometheus metadata: ...
Michael Niemand's user avatar
0 votes
1 answer
1k views

How to replace dot in Helm template string

I'm trying to replace all the dot characters in a helm template string with \., like so: {{- regexReplaceAllLiteral "\." "https://endpoint.index.up" "\\\." -}} I want ...
covfefe's user avatar
  • 2,575
1 vote
2 answers
2k views

go template split string by the second to last character

I am trying to split a string only by the second to last character, for example: Having this string xxx-xxx-xxx-xxx-xxx I would like to get only this xxx-xxx-xxx and remove the last part after the ...
Arnau Amargant Domene's user avatar
1 vote
1 answer
1k views

How to add an HTML Tag Attribute in GoLang Template

I have the following code: {{range . }} <td {{ if not .IsDisabled }}onclick="return toggle_active($(this))"{{ end }}> [x] </td> {{end}} This works, it puts the ...
CodeLikeBeaker's user avatar
0 votes
1 answer
19 views

Cannot access list elements outside for loop

If someElements is not empty, endList in the last line of code, should equal someElements. It works ok. If someElements is empty, endList in the last line of code, should contain elements appended in ...
Michał Konik's user avatar
1 vote
1 answer
93 views

Idiomatic way of mapping over list with go templates/helm

So let's assume I have the following values.yaml: services: - MyService1 - MyService2 - MyService3 I want to have a way to render the following: someStringField: "myservice1_cert,...
caeus's user avatar
  • 3,394
2 votes
2 answers
225 views

Usage of variables in a nested template which is also defined as a variable in a go template?

The idea is to define a variable for a go template which is also a template using variables (a nested template) like this: package main import ( "os" "text/template" ) ...
Adam Bogdan Boczek's user avatar
0 votes
1 answer
2k views

helm using argument in template to check if value exists in Values.yaml

The problem is following: I want to check if field in Values.yaml exists based on argument given to the template in _helpers.tpl: {{- define "example-name" -}} {{- $objectRef := index . 0 -}}...
mateusz.gorski123's user avatar
2 votes
0 answers
422 views

Print with escape characters in go templates

Assuming I have a parameter whose value is a string with a series of escape characters: strct.Data = "{ \"hello\": \"ok\", \r\n \"text\": \"value\" }" ...
Rafael Smith's user avatar
0 votes
1 answer
50 views

How to configure github.com/jinliming2/vscode-go-template to accept a custom file extension?

According to https://marketplace.visualstudio.com/items?itemName=jinliming2.vscode-go-template, this VS Code extension should support Go template language syntax highlighting for any custom file ...
Kurt Peek's user avatar
  • 54.6k
1 vote
2 answers
319 views

Not getting the right value that was specified in the values.yaml file

Secret value is returning NIL When i run the command below to check the values in the secret kubectl get secret cred2 -n service-b -o jsonpath='{.data.*}' | base64 -d It returns a Nil value. How do i ...
D-bwoy's user avatar
  • 21
-1 votes
1 answer
774 views

Indentation and text formatting with go templates

Given the below template: {{ range $item := . }} {{ if $item.IsA}} Ok {{ else }} Fine {{ end }} {{ end }} Done! When I render it using: t := template.New("test"...
Arnold Zahrneinder's user avatar
1 vote
1 answer
954 views

Create kubernetes docker-registry secret from yaml file for each lookup namespaces?

I am trying to dynamic lookup available namespaces and able to create secrets in the namespaces using below helm chart. templates/secrets.yaml {{ range $index, $namespace := (lookup "v1" &...
Ade's user avatar
  • 23
1 vote
0 answers
39 views

Go HTML page repeats the content inside it on each reload

I'm in the process of creating a go package that's a mix of django, express and gin and I'm already having many difficulties but it's one that's been so annoying for the past couple days. When ...
dpouris's user avatar
  • 13
1 vote
1 answer
663 views

Helm template - integer value is always rendered as 0

I see somewhat strange behaviour of helm template: My tpl function does this: {{- define "spark-k8s-application.maxExecutors" -}} ... {{- printf "%d" .Values.application....
eugen-fried's user avatar
  • 2,163
0 votes
1 answer
448 views

Hugo: How to set dict value by interpolation?

In Go (Hugo) templates, how can I set the value of a single entry in a dict? In this example, I start with a pre-populated dict $vitality and maybe a string .Params.vitality. If the string has ...
Merchako's user avatar
  • 851
0 votes
1 answer
804 views

consul-template expand new lines from env var

In consul-template I want to pass a ENV var with with new lines that will be expanded so "hello\nworld" is shown as: hello world command: VARIABLE="hell\nworld" consul-template -...
henry.oswald's user avatar
  • 5,394
2 votes
2 answers
3k views

Helm chart render string with special characters

I want to render following line as string in helm chart. It contain special characters. text: '{{ template "slack.template.text" . }}'
Akshay Gopani's user avatar
0 votes
1 answer
499 views

How do I generate labels in a Kubernetes YAML using the range in Go template?

Given this YAML config, I need to create multiple labels based on the number of elements in the labels array. template: metadata: name: '{{name}}' labels: '{{range .labels}}' ...
maheshbaliga's user avatar
0 votes
1 answer
195 views

Is there a native way to access the scope inside a range from inside a function?

In my template I use a range with a param like this: {{- range $key, $value := .Values.myParam }} --- fieldOne: $value.fieldOne fieldTwo: $value.fieldTwo myFunc: {{- include "myFunc" $ }} {{ ...
red888's user avatar
  • 29.7k
2 votes
1 answer
186 views

Use Random Int for a Photo in Go Template

I have a simple random integer in my code that I am passing to the template min := 1 max := 1563 Photo := rand.Intn(max - min + 1) fmt.Println(Photo) ...
devnull's user avatar
  • 2,812
1 vote
1 answer
503 views

Helm - only create if nested values are set

I am wondering if there is a more efficient way to exclude any yaml keys which do not have a value set. My current approach is to wrap each key in an if statement... container: spec: {{- if ...
xiz91x's user avatar
  • 11
2 votes
2 answers
937 views

Computing time/duration in Golang templates

I have a structure that gets rendered via template. e.g.: type Foo struct { Created time.Time ... } I pass this value to a template, and I'd like to this rendered see: Created at 2022-11-22 9:...
Marco's user avatar
  • 588
1 vote
2 answers
717 views

Go text/template: how to convert bool to int 0/1?

With Go text/template language, how can I convert a bool to an int (false=0, true=1)? Here is an example using my own goproc tool that allows to execute template from the command line: $ echo false | ...
dolmen's user avatar
  • 8,456
0 votes
1 answer
551 views

Expand helm template variables to lookup named-template/sub-template in _helpers.tpl

Trying to do the following in helm template but it's not expanding $key and giving an error cannot find template $key . Is this even possible? values.yaml app: env: - AAAA _helpers.tpl {{- define ...
Ryan's user avatar
  • 219
1 vote
1 answer
1k views

How to Return Part of another YAML file in Helm Go Template

I have a Yaml file in a folder as abc.yaml and the content is metadata: test1: apple test2: banana test3: cat container: image: foo text: xyz variables: ojb: one meta: two and I have ...
Prabhu Vignesh Rajagopal's user avatar
0 votes
1 answer
3k views

range can't iterate over list [x y]

I have this template in my helm chart: {{ $appEnvs := list "dev" "uat" }} {{- range $env := $appEnvs }} ... {{- end }} I am getting this error : <$appEnvs>: range can't ...
Abdennour TOUMI's user avatar
1 vote
1 answer
761 views

Helm template for Vault annotation

I'm trying to nest one template into another, namely I have a k8s deployment.yaml which should be templated by helm. However, it is already using Vault template in annotation field responsible for ...
Murakami's user avatar
  • 3,634
2 votes
1 answer
419 views

Golang: Custom template "block" functions?

I'm wondering if it's possible to use a custom function as a template block with Golang templates. The code below shows an example. {{ custom_func . }} This is content that "custom_func" ...
Andre's user avatar
  • 1,302
0 votes
1 answer
1k views

Grafana Alert Value String Templating

I'm creating a Grafana alert with the Elastic datasource. The condition operator is grouping all meaningful labels from my alert. [ var='A0' metric='' labels={header_host=hostname1.com value=1496 ], [ ...
Brandon Kauffman's user avatar
0 votes
1 answer
258 views

Go text/template Form handling, with custom FuncMap - function returning blank string outputs garbage

Using Go html/template functionality, with custom FuncMap. The custom function I've defined "isChecked(checkName string, form url.Values)" returns the string "checked" if the ...
crizzo's user avatar
  • 3
0 votes
1 answer
1k views

How do I print the metadata.labels information in go template in Kubernetes?

How do I print the metadata label information from the Kubernetes Pod? Given, this is the pod configuration apiVersion: v1 kind: Pod metadata: annotations: kubernetes.io/psp: eks.privileged ...
Mohit Sharma's user avatar
0 votes
0 answers
31 views

Passing elements from range loop to a html block [duplicate]

I defined this block using go HTML templates: {{define "button"}}<button> . </button>{{end}} I would like to use this block as a nested block and I would like to pass arguments ...
KeyB0rys's user avatar
  • 442
1 vote
1 answer
306 views

Is there function in helm similar to 'tpl' but don't fail if variable is not found

Let say I have file like it is my text file with name. It contains: {{ var1 }} and {{ var2 }} Let's say i have values.yaml var2: some_value If I try to do {{ (tpl (.Files.Glob "myfile.txt&...
gstackoverflow's user avatar
2 votes
1 answer
509 views

How to concat string to result of .AsConfig in helm?

I have config like this: {{- with .Files.Glob "files/my-files/*.json" }} {{ .AsConfig | indent 2 }} {{- end }} In the end of each file I want to add "FIHISHED!" How can I achieve ...
gstackoverflow's user avatar
2 votes
1 answer
250 views

Why when I ignore the template.New() the program can run successfully?

I am trying to use html/template to parse a JSON in struct format. func handler(w http.ResponseWriter, r *http.Request) { var issueList = template.Must(template.New("template01")....
aaa11384's user avatar
0 votes
1 answer
2k views

Helm escape string in nested json

I am using helm to deploy apps on kubernetes. And I'm trying to figure out how to include an escaped multiline string in a nested json generated in a kubernetes secret. The goal is to inline a ...
Sylvan LE DEUNFF's user avatar
1 vote
1 answer
95 views

How to change dynamic variable in Revel Template

In my revel project, i have a select option that need to get selected after clicking submit button. If i do it like this it works because .OptionType is a string so i need to compare it with string &...
Michael Halim's user avatar
0 votes
1 answer
2k views

Go template: is there any item in list of objects with a specific attribute value?

I'm using helm (sprig, go templates). I'm trying to build guards to selectively include stuff in my helm chart, but only if one of the components needs them. So, I have a list: - name: foo flag1: ...
Jon O's user avatar
  • 6,572
0 votes
0 answers
496 views

Golang-templates > How to update the result web page as soon as the template file (html) is changed

I'm learning Golang and having some trouble with the web (html) templates. Whenever I change the template file, it does not reflect in showing the result in the browser. The result shows the same ...
Nitin Nanivadekar's user avatar

1 2
3
4 5
17