【发布时间】:2022-01-08 15:11:40
【问题描述】:
我正在尝试制作另一个使用现有辅助函数但似乎不起作用的辅助函数。
我在 _helpers.tpl 文件中有以下功能:
{{- define "redis.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 30 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 30 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
现在我正在尝试添加另一个函数来使用上述函数为 redis 构建连接字符串:
{{ - define "redis.connection_string" -}}
{{ - printf "redis://%s:%s/" include "redis.fullname" .Value.port -}} # This line is important. Can we use above function like this?
{{ -end -}}
这是我的 _helpers.tpl 文件的最终内容:
{{- define "redis.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 30 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 30 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{ - define "redis.connection_string" -}}
{{ - printf "redis://%s:%s/" include "redis.fullname" .Value.port -}}
{{ - end -}}
GO 和 Helm 对我来说都是新手,所以即使它可能也无法找出正确的语法。 (这就是我们在同一个帮助文件中编写 2 个函数的方式吗?)任何人都可以在这里提供帮助。
【问题讨论】:
标签: go kubernetes-helm helper helm3