2018-06-05 19:23:47 +08:00
apiVersion : v1
kind : ConfigMap
metadata :
name : {{ template "grafana.fullname" . }}
labels :
app : {{ template "grafana.name" . }}
chart : {{ template "grafana.chart" . }}
release : {{ .Release.Name }}
heritage : {{ .Release.Service }}
data :
2018-10-07 16:39:59 +08:00
{{- if .Values.plugins }}
plugins : {{ join "," .Values.plugins }}
2018-06-05 19:23:47 +08:00
{{- end }}
grafana.ini : |
{{- range $key, $value := index .Values "grafana.ini" }}
[ {{ $key }}]
{{- range $elem, $elemVal := $value }}
{{ $elem }} = {{ $elemVal }}
{{- end }}
{{- end }}
{{- if .Values.datasources }}
{{- range $key, $value := .Values.datasources }}
{{ $key }} : |
{{ toYaml $value | indent 4 }}
{{- end -}}
{{- end -}}
{{- if .Values.dashboardProviders }}
{{- range $key, $value := .Values.dashboardProviders }}
{{ $key }} : |
{{ toYaml $value | indent 4 }}
{{- end -}}
{{- end -}}
{{- if .Values.dashboards }}
download_dashboards.sh : |
#!/usr/bin/env sh
set -euf
2018-10-07 16:39:59 +08:00
{{- if .Values.dashboardProviders }}
{{- range $key, $value := .Values.dashboardProviders }}
{{- range $value.providers }}
mkdir -p {{ .options.path }}
{{- end }}
{{- end }}
{{- end }}
{{- range $provider, $dashboards := .Values.dashboards }}
{{- range $key, $value := $dashboards }}
{{- if (or (hasKey $value "gnetId") (hasKey $value "url")) }}
2018-06-05 19:23:47 +08:00
curl -sk \
--connect-timeout 60 \
--max-time 60 \
-H "Accept: application/json" \
-H "Content-Type: application/json;charset=UTF-8" \
{{- if $value.url -}}{{ $value.url }}{{- else -}} https://grafana.com/api/dashboards/{{ $value.gnetId }}/revisions/{{- if $value.revision -}}{{ $value.revision }}{{- else -}}1{{- end -}}/download{{- end -}}{{ if $value.datasource }}| sed 's|\"datasource\":[^,]*|\"datasource\": \"{{ $value.datasource }}\"|g'{{ end }} \
2018-10-07 16:39:59 +08:00
> /var/lib/grafana/dashboards/{{ $provider }}/{{ $key }}.json
{{- end }}
2018-06-05 19:23:47 +08:00
{{- end }}
{{- end }}
{{- end }}