【问题标题】:Check if files/dirs/ used in templates exists检查模板中使用的文件/目录/是否存在
【发布时间】:2018-06-08 01:36:02
【问题描述】:

给定以下 json:

    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ template "something.server.fullname" . }}
    data:
    {{ (.Files.Glob "dashboards/*.json").AsConfig | indent 2 }}
    {{ (.Files.Glob "datasources/*.json").AsConfig | indent 2 }}

如何检查文件夹是否存在且不为空?

目前,如果文件夹丢失或没有任何文件,helm install 将中止并显示以下消息:

Error: YAML parse error on domething/charts/grafana/templates/dashboards-configmap.yaml: error converting YAML to JSON: yaml: line 6821: could not find expected ':'

【问题讨论】:

标签: kubernetes kubernetes-helm


【解决方案1】:

您可以将 Glob 拉出到变量中,然后移动 if 块内的所有内容,例如:

{{- $globdash := .Files.Glob "dashboards/*.json" }}
{{ if $globdash }}
{{- $globdata := .Files.Glob "datasources/*.json" }}
{{ if $globdata }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "something.server.fullname" . }}
data:
{{ ($globdash).AsConfig | indent 2 }}
{{ ($globdata).AsConfig | indent 2 }}
{{ end }}
{{ end }}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2015-07-09
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    相关资源
    最近更新 更多