Skip to content

Commit

Permalink
feat(helm): Grafana dashboard using configmap and Grafana Operator (#213
Browse files Browse the repository at this point in the history
)

Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
  • Loading branch information
nlamirault authored Jul 16, 2024
1 parent 34ff919 commit 074311e
Showing 3 changed files with 65 additions and 2 deletions.
47 changes: 47 additions & 0 deletions charts/dragonfly-operator/templates/grafanadashboards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{ if .Values.grafanaDashboard.enabled -}}
{{- $files := .Files.Glob "dashboards/*.json" }}
{{- if $files }}
---
apiVersion: v1
kind: ConfigMapList
items:
{{- range $path, $fileContents := $files }}
{{- $dashboardName := regexReplaceAll "(^.*/)(.*)\\.json$" $path "${2}" | lower }}
- apiVersion: v1
kind: ConfigMap
metadata:
annotations:
{{ $.Values.grafanaDashboard.annotations.name }}: {{ $.Values.grafanaDashboard.folder }}
labels:
{{ $.Values.grafanaDashboard.labels.name }}: {{ $dashboardName }}
{{- include "dragonfly-operator.labels" $ | nindent 6 }}
app.kubernetes.io/component: dashboard
name: {{ printf "dashboard-dragonfly-operator-%s" $dashboardName | trunc 63 | trimSuffix "-" }}
data:
{{ $dashboardName }}.json: |-
{{ $.Files.Get $path | indent 6}}
{{- end }}
{{ if $.Values.grafanaDashboard.grafanaOperator.enabled -}}
{{- range $path, $fileContents := $files }}
{{- $dashboardName := regexReplaceAll "(^.*/)(.*)\\.json$" $path "${2}" | lower }}
---
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDashboard
metadata:
labels:
{{- include "dragonfly-operator.labels" $ | nindent 4 }}
app.kubernetes.io/component: dashboard
name: {{ printf "dragonfly-operator-%s" $dashboardName | trunc 63 | trimSuffix "-" }}
spec:
allowCrossNamespaceImport: {{ $.Values.grafanaDashboard.grafanaOperator.allowCrossNamespaceImport }}
folder: {{ $.Values.grafanaDashboard.folder }}
instanceSelector:
matchLabels:
{{- toYaml $.Values.grafanaDashboard.grafanaOperator.matchLabels | nindent 6 }}
configMapRef:
name: {{ printf "dashboard-dragonfly-operator-%s" $dashboardName | trunc 63 | trimSuffix "-" }}
key: {{ $dashboardName }}.json
{{- end }}
{{- end }}
{{- end }}
{{- end }}
19 changes: 17 additions & 2 deletions charts/dragonfly-operator/values.yaml
Original file line number Diff line number Diff line change
@@ -126,7 +126,6 @@ manager:
# values:
# - linux


serviceMonitor:
# When set true then use a ServiceMonitor to configure scraping
enabled: false
@@ -147,4 +146,20 @@ serviceMonitor:
# - sourceLabels: [dbinstance_identifier]
# action: replace
# replacement: mydbname
# targetLabel: dbname
# targetLabel: dbname

grafanaDashboard:
enabled: false
folder: database
# -- Grafana dashboard configmap annotations.
annotations:
name: grafana_folder
# -- Grafana dashboard configmap labels
labels:
name: grafana_dashboard
grafanaOperator:
enabled: false
allowCrossNamespaceImport: true
# -- Selected labels for Grafana instance
matchLabels:
dashboards: grafana

0 comments on commit 074311e

Please sign in to comment.