值文件中的舵连接列表

Mat*_*att 7 kubernetes-helm

我正在寻找一种解决方案,将我的 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)

谢谢

Nic*_*lay 8

双引号应该在.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)


Loi*_*cAG 5

我是这样解决的:

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)