apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: {{ template "grafana.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
  name: {{ template "grafana.server.fullname" . }}
data:
  {{- if .Values.serverDashboardFiles }}
{{ toYaml .Values.serverDashboardFiles | indent 2 }}
  {{ end }}
  {{- if .Values.keepOriginalDashboards }}
{{ (.Files.Glob "dashboards/k8s/*.json").AsConfig | indent 2 }}
  {{- end }}
  {{- if .Values.dataSource }}
{{ toYaml .Values.dataSource | indent 2 }}
  {{- end }}
  {{- if .Values.keepOriginalDatasources }}
  prometheus-datasource.json: |+
    {
      "access": "proxy",
      "basicAuth": false,
      "name": "prometheus",
      "type": "prometheus",
      "url": "http://{{ printf "%s-%s" .Release.Name "server" }}:{{ .Values.prometheusPort }}"
    }
  {{- end }}
