问题描述
我有一张舵图用于部署具有YAML格式的配置文件的应用程序.目前,我的头盔图表使用以下代码:
I have an helm chart used to deploy an application that have configuration file in YAML format.Currently, my helm chart use the following code:
values.yaml
databaseUser: "dbuser"
configFiles:
db_config_file.yaml: |-
databaseUser: {{ .Values.databaseUser }}
databasePort: 1234
[...]
[...]
templates/configmap.yaml
data:
{{- range $name, $config := .Values.configFiles }}
{{ $name }}: |-
{{ tpl $config $ | indent 4 }}
{{- end }}
此代码使我可以轻松地从值中更改 databaseUser
,但是问题是,如果我想更改 databasePort
的值,则必须重写整个这样的配置:
This code allow me to change easily the databaseUser
from values, but the problem is that if I want to change the value of databasePort
, I have to rewrite the entire configuration like that:
configFiles:
db_config_file.yaml: |-
databaseUser: {{ .Values.databaseUser }}
databasePort: 9876
这很不方便.之所以这样工作,是因为将 db_config_file.yaml
内容解释为字符串,因为我将其提供给仅接受字符串的 tpl
函数.
which is inconvenient. It works like that because the db_config_file.yaml
content is interpreted as string because I give it to the tpl
function which only accept strings.
所以我的问题是,有没有一种方法可以将YAML转换为Helm模板中的字符串并获得以下信息:
So my question is, is there a way to convert the YAML to string in a Helm template and get the following things:
databaseUser: "dbuser"
configFiles:
db_config_file.yaml: # Content is not a string block
databaseUser: {{ .Values.databaseUser }}
databasePort: 1234
[...]
[...]
data:
{{- range $name, $config := .Values.configFiles }}
{{ $name }}: |-
{{ tpl (<a toString function> $config) $ | indent 4 }}
{{- end }}
推荐答案
您是否也考虑将 databasePort
模板化并将值用双引号引起来?
Did you consider templating databasePort
as well and wrapping your values in double quotes?
values.yaml
databaseUser: "dbuser"
databasePort: 1234
configFiles:
db_config_file.yaml: |-
databaseUser: "{{ .Values.databaseUser }}"
databasePort: "{{ .Values.databasePort }}"
这篇关于将YAML转换为Helm中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!