go-templates

How to set environment related values.yaml in Helm subcharts?

点点圈 提交于 2020-06-24 14:15:48
问题 I am currently deploying my applications in a Kubernetes cluster using Helm. Now I also need to be able to modify some parameter in the values.yaml file for different environments. For simple charts with only one level this is easy by having different values-local.yaml and values-prod.yaml and add this to the helm install flag, e.g. helm install --values values-local.yaml . But if I have a second layer of subcharts, which also need to distinguish the values between multiple environments, I

How to set environment related values.yaml in Helm subcharts?

一世执手 提交于 2020-06-24 14:15:20
问题 I am currently deploying my applications in a Kubernetes cluster using Helm. Now I also need to be able to modify some parameter in the values.yaml file for different environments. For simple charts with only one level this is easy by having different values-local.yaml and values-prod.yaml and add this to the helm install flag, e.g. helm install --values values-local.yaml . But if I have a second layer of subcharts, which also need to distinguish the values between multiple environments, I

In Go templates, accessing parent/global pipeline within range

北城余情 提交于 2020-06-08 04:36:53
问题 Is it possible, within a {{range pipeline}} T1 {{end}} action in the text/template package to access the pipelines value prior to the range action, or the parent/global pipeline passed as an argument to Execute? Working example that shows what I try to do: package main import ( "os" "text/template" ) // .Path won't be accessible, because dot will be changed to the Files element const page = `{{range .Files}}<script src="{{html .Path}}/js/{{html .}}"></script>{{end}}` type scriptFiles struct {

Go template and function

我只是一个虾纸丫 提交于 2020-03-01 03:19:41
问题 In my go code I often use if like this if user && user.Registered { } equivalent code in go templates would be {{ if and .User .User.Registered }} {{ end }} Unfortunately code in the template fails, if .User is nil :/ Is it possible to achieve the same thing in go templates? 回答1: The template and function does not do short circuit evaluation like the Go && operator. The arguments to the and function are evaluated before the function is called. The expression .User.Registered is always

How to access value of first index of array in Go templates

情到浓时终转凉″ 提交于 2020-02-21 10:39:03
问题 So I have and html template when using this I get the object: <div>Foobar {{ index .Doc.Users 0}}</div> Output: <div>Foobar {MyName my@email.com}</div> I just want to use the Name field I have tried many iterations without success: {{ index .Doc.Users.Name 0}} {{ index .Doc.Users 0 .Name}} {{ .Name index .Quote.Clients 0}} ... What is the correct syntax for just getting .Name field ( .Doc.Users[0].Name ) of the first element in my array? 回答1: Simply group the expression and apply the .Name

How to access value of first index of array in Go templates

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-21 10:35:46
问题 So I have and html template when using this I get the object: <div>Foobar {{ index .Doc.Users 0}}</div> Output: <div>Foobar {MyName my@email.com}</div> I just want to use the Name field I have tried many iterations without success: {{ index .Doc.Users.Name 0}} {{ index .Doc.Users 0 .Name}} {{ .Name index .Quote.Clients 0}} ... What is the correct syntax for just getting .Name field ( .Doc.Users[0].Name ) of the first element in my array? 回答1: Simply group the expression and apply the .Name

How to access value of first index of array in Go templates

你离开我真会死。 提交于 2020-02-21 10:35:27
问题 So I have and html template when using this I get the object: <div>Foobar {{ index .Doc.Users 0}}</div> Output: <div>Foobar {MyName my@email.com}</div> I just want to use the Name field I have tried many iterations without success: {{ index .Doc.Users.Name 0}} {{ index .Doc.Users 0 .Name}} {{ .Name index .Quote.Clients 0}} ... What is the correct syntax for just getting .Name field ( .Doc.Users[0].Name ) of the first element in my array? 回答1: Simply group the expression and apply the .Name

Iterating through map in template

烈酒焚心 提交于 2020-01-30 14:04:01
问题 I am trying to display a list gym classes (Yoga, Pilates etc). For each class type there are several classes, so I want to group all the Yoga classes, and all the Pilates classes and so on. I made this function to take a slice and make a map of it func groupClasses(classes []entities.Class) map[string][]entities.Class { classMap := make(map[string][]entities.Class) for _, class := range classes { classMap[class.ClassType.Name] = append(classMap[class.ClassType.Name], class) } return classMap

Iterating through map in template

做~自己de王妃 提交于 2020-01-30 14:03:08
问题 I am trying to display a list gym classes (Yoga, Pilates etc). For each class type there are several classes, so I want to group all the Yoga classes, and all the Pilates classes and so on. I made this function to take a slice and make a map of it func groupClasses(classes []entities.Class) map[string][]entities.Class { classMap := make(map[string][]entities.Class) for _, class := range classes { classMap[class.ClassType.Name] = append(classMap[class.ClassType.Name], class) } return classMap

Define values for each namespace

家住魔仙堡 提交于 2020-01-30 08:07:46
问题 values.yaml replicas: { test: 1, stage: 2, prod: 3 } Here I am trying to use Helm templates to define number of replicas per namespace but am unsure of the proper syntax and pattern: deployment.yaml replicas: {{ .Values.replicas.{{ .Release.Namespace }} }} So if this were deployed to --namespace=prod , I would expect the template to return: # .Values.replicas.prod replicas: 3 回答1: All of the template functions provided by the standard Go text/template library are available. In particular,