Helm-是否可以将引号添加到其模板上列表中的所有项目?
假设我正在创建一个舵机模板,我希望最终的部署能够执行自己的喜好。对于此示例,我将使用touch
命令。
在我的模板文件中,我会这样写下来:
templates.yaml
...
foo:
{{- if .Values.foo.command }}
exec:
command: {{ .Values.foo.command }}
{{- end }}
...
然后,我将拥有我的值文件:
values.yaml
...
foo:
command: ["touch", "bar.txt"]
...
当我检查上述结果的模板时,该命令被模板为:
foo:
exec:
command: [touch bar.txt]
因此,没有引号/逗号在其命令中。这仍然会按预期执行?或为此而要执行的逗号和引号。
谢谢!
Let's say I'm creating a helm template in which I want the eventual deployments to be able to execute a command to their liking. For this example, I'll use use the touch
command.
In my templates file, I'd write it down like this:
templates.yaml
...
foo:
{{- if .Values.foo.command }}
exec:
command: {{ .Values.foo.command }}
{{- end }}
...
Then following that, I'd have my values file:
values.yaml
...
foo:
command: ["touch", "bar.txt"]
...
When I'm checking the resulting template of the above, the command gets templated as:
foo:
exec:
command: [touch bar.txt]
Thus, there are no quotes/commas in its command. Would this still execute as intended? Or are commas and quotes necessary in order for this to execute.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将无法正常工作。您显示的输出语法是有效的YAML列表,但仅包含一个单个shell Word,因此它正在寻找一个名为
touch bar.txt
的命令,其中该空间将成为文件名的一部分/usr/bin
。Helm使用的GO文本/模板引擎并不特别了解YAML。当您直接写出这样的值时,它会使用并非特别有用的默认格式。 Helm有几个略有文献记录的扩展名,以更有用的格式写出值。对于您的示例,我可能会使用:
这应该写出来:
您可以适合
命令:{{tojson .values.foo.command}}}}
中。无论哪种情况,它都可能没有value.yaml
文件中的确切格式,因为Helm在启动时会解析YAML,然后写出等效结构。This will not work as expected. The output syntax you show is a valid YAML list, but only containing a single shell word, and so it is looking for a command named
touch bar.txt
, where the space would be part of the filename in/usr/bin
.The Go text/template engine that Helm uses isn't especially aware of YAML. When you directly write out a value like this, it uses a default formatting that's not especially useful. Helm has a couple of lightly-documented extensions to write out values in a more useful format. For your example I might use:
This should write out:
You may be able to fit
command: {{ toJson .Values.foo.command }}
into a single line. In either case it may not have the exact formatting that's in thevalues.yaml
file, since Helm parses the YAML at startup time and then writes out the equivalent structure.