我正在寻找一种解决方案,将我的 values.yaml 中的列表转换为逗号分隔的列表。
值.yaml
app:
logfiletoexclude:
- "/var/log/containers/kube*"
- "/var/log/containers/tiller*"
Run Code Online (Sandbox Code Playgroud)
_helpers.tpl:
{{- define "pathtoexclude" -}}
{{- join "," .Values.app.logfiletoexclude }}
{{- end -}}
Run Code Online (Sandbox Code Playgroud)
配置图:
<source>
@type tail
path /var/log/containers/*.log
exclude_path [{{ template "pathtoexclude" . }}]
...
...
</source>
Run Code Online (Sandbox Code Playgroud)
问题是我的结果中缺少引号
exclude_path [/var/log/containers/kube*,/var/log/containers/tiller*]
Run Code Online (Sandbox Code Playgroud)
我该如何修复它才能拥有:
exclude_path ["/var/log/containers/kube*","/var/log/containers/tiller*"]
Run Code Online (Sandbox Code Playgroud)
我试过:
{{- join "," .Values.app.logfiletoexclude | quote}}
Run Code Online (Sandbox Code Playgroud)
但这给了我:
exclude_path ["/var/log/containers/kube*,/var/log/containers/tiller*"]
Run Code Online (Sandbox Code Playgroud)
谢谢
双引号应该在.Values.app.logfiletoexclude值中转义。
values.yaml 是:
app:
logfiletoexclude:
- '"/var/log/containers/kube*"'
- '"/var/log/containers/tiller*"'
Run Code Online (Sandbox Code Playgroud)
_helpers.tpl 是:
{{- define "pathtoexclude" -}}
{{- join "," .Values.app.logfiletoexclude }}
{{- end -}}
Run Code Online (Sandbox Code Playgroud)
最后我们有:
exclude_path ["/var/log/containers/kube*","/var/log/containers/tiller*"]
Run Code Online (Sandbox Code Playgroud)
我是这样解决的:
在values.yaml(引号无关紧要):
elements:
- first element
- "second element"
- 'third element'
Run Code Online (Sandbox Code Playgroud)
在_helpers.tpl:
{{- define "mychart.commaJoinedQuotedList" -}}
{{- $list := list }}
{{- range .Values.elements }}
{{- $list = append $list (printf "\"%s\"" .) }}
{{- end }}
{{- join ", " $list }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)
在templates/mytemplate.yaml:
elements: {{ include "mychart.commaJoinedQuotedList" . }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15322 次 |
| 最近记录: |