gpt4 book ai didi

kubernetes - 在 helm 模板中传递多个变量

转载 作者:行者123 更新时间:2023-12-04 11:51:10 30 4
gpt4 key购买 nike

有没有办法在 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 -}}

我感谢您的帮助。谢谢

最佳答案

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

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

关于kubernetes - 在 helm 模板中传递多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60636775/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com