Is there a way to pass multiple variables in template
or a function using include
? In my case I iterate over a list of items, but in the template I also need the .Release.Name
variable.
Is there a way to add to $client
the .Release.Name
? I tried something like {{ $client.Name := .Release.Name }}
, but it throws an error..
I have the following template:
{{- range $client := .Values.global.clients }}
{{- with $ }}
search.service-{{ $client.clientId }}.cfg: |
{{ include "rest-api.search" $client | indent 4}}
{{- end}}
{{- end}}
The rest-api.search function:
{{- define "rest-api.search" -}}
client.id={{ .clientId }}
id={{ .clientId }}
uri=http://{{ .Release.Name }}:11666/{index}/ws/{configuration}
default.index=quicksearch
default.configuration=form
query.sort=
query.filter=
query.dsf=word
query.lower=0
query.max=10
query.locale=de
query.query=*
# Index mapping
index.COMMON=quicksearch
index.REF=quicksearch
supportObjectGroup=true
# authorization scheme
authScheme=NONE
{{- end -}}
I appreciate your help. Thanks
In Helm templates, a variable is a named reference to another object. It follows the form $name . Variables are assigned with a special assignment operator: := . We can rewrite the above to use a variable for Release.Name .
Using the --values flag You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.
The $_ is used to suppress undesired output as "set" returns the new dictionary. The above returns: - name: mongod-none. Any values added to the dictionary will live beyond the call. If you want to avoid polluting an existing dictionary you can force a deep copy with: {{- $d := merge (dict) . -}}
Apply the variables to the Helm chart by combining them with the helm install command: [chart name] is the name of the Helm chart you are using. [chart path] is the path to the Helm chart you are using. If you want to test the new settings out before applying them, use the dry run mode: 1.
If you need to include this in another variable, Helm provides an include function that acts just like template except that it's an "expression" rather than something that outputs directly. { {- $url := printf "%s://google.com" (include "scheme" .)
Create a file named env-values.yaml and store the above key-value map inside it. Helm template can be made dynamic by using values.yaml. Using values.yaml you can store the parameters in the form of maps. After creating the en-values.yaml, let’s see how to access the env-values.yaml.
Helm charts are a convenient and efficient way to collect Kubernetes resources and build application clusters. They can also use environment variables on local machines to define values for your Kubernetes deployment to use. This tutorial will cover different ways you can include environment variables in your Kubernetes deployment.
You can pass client object alongside release object in a dict
values.yaml
global:
clients:
- name: test
clientId: test-123
configmap.yaml
{{- range $client := .Values.global.clients }}
{{$data := dict "client" $client "release" $.Release }}
search.service-{{ .clientId }}.cfg: |
{{ include "mychart.search" $data | indent 4}}
{{- end}}
_helpers.tpl
{{- define "mychart.search" -}}
client.id={{ .client.clientId }}
id={{ .client.clientId }}
uri=http://{{ .release.Name }}:11666/{index}/ws/{configuration}
default.index=quicksearch
{{- end -}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With