aphex
aphex

Reputation: 3412

Pass multiple variables in helm template

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

Upvotes: 18

Views: 29180

Answers (1)

edbighead
edbighead

Reputation: 6334

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 -}}

Upvotes: 42

Related Questions