cri*_*sti 5 kubernetes kubernetes-helm
鉴于以下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 }}
Run Code Online (Sandbox Code Playgroud)
如何检查文件夹是否存在且不为空?
目前,如果文件夹丢失或没有任何文件, 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 ':'
Run Code Online (Sandbox Code Playgroud)
eve*_*Mcc 17
您可以将 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 }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3975 次 |
| 最近记录: |