From bc69a774fa91876b1ab2b5a720927b53e038a96a Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Mon, 24 Oct 2022 15:22:31 +0200 Subject: [PATCH] Helm: add Grafana Dashboard for Grafana operator --- .../dashboards/KubeInvadersDashboard.json | 1 + .../templates/grafanadashboard.yaml | 43 +++++++++++++++++++ helm-charts/kubeinvaders/values.yaml | 5 +++ 3 files changed, 49 insertions(+) create mode 120000 helm-charts/kubeinvaders/dashboards/KubeInvadersDashboard.json create mode 100644 helm-charts/kubeinvaders/templates/grafanadashboard.yaml diff --git a/helm-charts/kubeinvaders/dashboards/KubeInvadersDashboard.json b/helm-charts/kubeinvaders/dashboards/KubeInvadersDashboard.json new file mode 120000 index 000000000..f0716f328 --- /dev/null +++ b/helm-charts/kubeinvaders/dashboards/KubeInvadersDashboard.json @@ -0,0 +1 @@ +../../../grafana/KubeInvadersDashboard.json \ No newline at end of file diff --git a/helm-charts/kubeinvaders/templates/grafanadashboard.yaml b/helm-charts/kubeinvaders/templates/grafanadashboard.yaml new file mode 100644 index 000000000..4894a2ac5 --- /dev/null +++ b/helm-charts/kubeinvaders/templates/grafanadashboard.yaml @@ -0,0 +1,43 @@ +{{ if .Values.grafanaDashboard.enabled }} +{{ $currentScope := .}} +{{ range $path, $_ := .Files.Glob "dashboards/**.json" }} +{{ $dashboardName := regexReplaceAll "(^.*/)(.*)\\.json$" $path "${2}" }} +{{- with $currentScope}} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: "grafana-dashboards-{{ lower $dashboardName }}" + labels: + app.kubernetes.io/name: kubeinvaders + helm.sh/chart: {{ include "kubeinvaders.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.additionalLabels }} + {{- . | toYaml | nindent 4 }} + {{- end }} +data: + {{- (.Files.Glob $path).AsConfig | nindent 2 }} +--- +apiVersion: integreatly.org/v1alpha1 +kind: GrafanaDashboard +metadata: + name: "grafana-dashboards-{{ lower $dashboardName }}" + labels: + app.kubernetes.io/name: kubeinvaders + helm.sh/chart: {{ include "kubeinvaders.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.additionalLabels }} + {{- . | toYaml | nindent 4 }} + {{- end }} +spec: + datasources: + - inputName: "DS_PROMETHEUS" + datasourceName: "Prometheus" + configMapRef: + name: "grafana-dashboards-{{ lower $dashboardName }}" + key: {{ $dashboardName }}.json +{{- end }} +{{ end }} +{{ end }} diff --git a/helm-charts/kubeinvaders/values.yaml b/helm-charts/kubeinvaders/values.yaml index e22de5a29..8254836c0 100644 --- a/helm-charts/kubeinvaders/values.yaml +++ b/helm-charts/kubeinvaders/values.yaml @@ -67,3 +67,8 @@ route_host: "" serviceMonitor: enabled: false + +# Create Grafana Dashboard CRD and configmap for Grafana operator +grafanaDashboard: + enabled: false + labels: {} # Labels configured in Grafana operator as dashboardLabelSelector