在头盔模板中传递多个变量

时间:2020-03-11 13:06:57

标签: kubernetes devops kubernetes-helm

是否可以在template或使用include的函数中传递多个变量?就我而言,我遍历项目列表,但在模板中,我还需要.Release.Name变量。

是否可以将$client添加到.Release.Name?我尝试过类似{{ $client.Name := .Release.Name }}的操作,但是会引发错误。

我有以下模板:

{{- range $client := .Values.global.clients }}
{{- with $ }}
search.service-{{ $client.clientId }}.cfg: |
{{ include "rest-api.search" $client | indent 4}}
{{- end}}
{{- end}}

rest-api.search函数:

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

感谢您的帮助。谢谢

1 个答案:

答案 0 :(得分:4)

您可以在字典中将客户端对象与发布对象一起传递

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