How to import custom dashboards to grafana using helm
I partially figured it out. I can load dashboards from a configmap. Not from separate json files yet but it'a progress.
For anyone interested I put this on my github page: https://github.com/tretos53/notes/blob/master/Grafana/Readme.MD
You can find a good example of how to do this in the charts for prometheus-operator here:
https://github.com/helm/charts/tree/master/stable/prometheus-operator/templates/grafana
It is a ConfigMapList that gets all JSONs from a given directory and stores them into ConfigMaps which are read by Grafana.
{{- $files := .Files.Glob "dashboards/*.json" }}{{- if $files }}apiVersion: v1kind: ConfigMapListitems:{{- range $path, $fileContents := $files }}{{- $dashboardName := regexReplaceAll "(^.*/)(.*)\\.json$" $path "${2}" }}- apiVersion: v1 kind: ConfigMap metadata: name: {{ printf "%s-%s" (include "prometheus-operator.fullname" $) $dashboardName | trunc 63 | trimSuffix "-" }} namespace: {{ template "prometheus-operator.namespace" . }} labels: {{- if $.Values.grafana.sidecar.dashboards.label }} {{ $.Values.grafana.sidecar.dashboards.label }}: "1" {{- end }} app: {{ template "prometheus-operator.name" $ }}-grafana{{ include "prometheus-operator.labels" $ | indent 6 }} data: {{ $dashboardName }}.json: {{ $.Files.Get $path | toJson }}{{- end }}{{- end }}
Mind that the size of a ConfigMap might be limited:https://stackoverflow.com/a/53015758/4252480