是否可以在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 -}}
感谢您的帮助。谢谢
答案 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 -}}