Browse Source

add extralabels for dashboard to be scraped by multiple grafana instances (#5138)

* add extralabels for dashboard to be scraped by multiple grafana instances

Signed-off-by: l1ghtman2k <aibek.zhylkaidarov@hpe.com>

* sync docs

Signed-off-by: l1ghtman2k <aibek.zhylkaidarov@hpe.com>

* add grafana tests

Signed-off-by: l1ghtman2k <aibek.zhylkaidarov@hpe.com>

---------

Signed-off-by: l1ghtman2k <aibek.zhylkaidarov@hpe.com>
Signed-off-by: Aibek <35672535+L1ghtman2k@users.noreply.github.com>
Aibek 7 months ago
parent
commit
5bc528ff86

+ 1 - 0
deploy/charts/external-secrets/README.md

@@ -116,6 +116,7 @@ The command removes all the Kubernetes components associated with the chart and
 | global.topologySpreadConstraints | list | `[]` |  |
 | grafanaDashboard.annotations | object | `{}` | Annotations that ConfigMaps can have to get configured in Grafana, See: sidecar.dashboards.folderAnnotation for specifying the dashboard folder. https://github.com/grafana/helm-charts/tree/main/charts/grafana |
 | grafanaDashboard.enabled | bool | `false` | If true creates a Grafana dashboard. |
+| grafanaDashboard.extraLabels | object | `{}` | Extra labels to add to the Grafana dashboard ConfigMap. |
 | grafanaDashboard.sidecarLabel | string | `"grafana_dashboard"` | Label that ConfigMaps should have to be loaded as dashboards. |
 | grafanaDashboard.sidecarLabelValue | string | `"1"` | Label value that ConfigMaps should have to be loaded as dashboards. |
 | hostNetwork | bool | `false` | Run the controller on the host network |

+ 3 - 0
deploy/charts/external-secrets/templates/grafana-dashboard.yaml

@@ -7,6 +7,9 @@ metadata:
   labels:
     {{ .Values.grafanaDashboard.sidecarLabel }}: {{ .Values.grafanaDashboard.sidecarLabelValue | quote }}
     {{- include "external-secrets.labels" . | nindent 4 }}
+    {{- with .Values.grafanaDashboard.extraLabels }}
+    {{- toYaml . | nindent 4 }}
+    {{- end }}
   {{- with .Values.grafanaDashboard.annotations }}
   annotations:
     {{- toYaml . | nindent 4 }}

+ 94 - 0
deploy/charts/external-secrets/tests/grafana_dashboard_test.yaml

@@ -0,0 +1,94 @@
+suite: test grafana dashboard
+templates:
+  - grafana-dashboard.yaml
+tests:
+  - it: should not render grafana dashboard when disabled
+    set:
+      grafanaDashboard.enabled: false
+    asserts:
+      - hasDocuments:
+          count: 0
+  - it: should render grafana dashboard when enabled
+    set:
+      grafanaDashboard.enabled: true
+    asserts:
+      - hasDocuments:
+          count: 1
+      - isKind:
+          of: ConfigMap
+      - equal:
+          path: metadata.name
+          value: RELEASE-NAME-external-secrets-dashboard
+      - equal:
+          path: metadata.labels["grafana_dashboard"]
+          value: "1"
+  - it: should include extraLabels when set
+    set:
+      grafanaDashboard.enabled: true
+      grafanaDashboard.extraLabels:
+        custom-label: custom-value
+        another-label: another-value
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.labels["custom-label"]
+          value: custom-value
+      - equal:
+          path: metadata.labels["another-label"]
+          value: another-value
+      - equal:
+          path: metadata.labels["grafana_dashboard"]
+          value: "1"
+  - it: should include annotations when set
+    set:
+      grafanaDashboard.enabled: true
+      grafanaDashboard.annotations:
+        custom-annotation: custom-value
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.annotations["custom-annotation"]
+          value: custom-value
+  - it: should override sidecarLabel and sidecarLabelValue
+    set:
+      grafanaDashboard.enabled: true
+      grafanaDashboard.sidecarLabel: custom-dashboard-label
+      grafanaDashboard.sidecarLabelValue: "custom-value"
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.labels["custom-dashboard-label"]
+          value: "custom-value"
+  - it: should combine extraLabels with default labels
+    set:
+      grafanaDashboard.enabled: true
+      grafanaDashboard.extraLabels:
+        environment: production
+        team: platform
+      fullnameOverride: my-external-secrets
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.labels["environment"]
+          value: production
+      - equal:
+          path: metadata.labels["team"]
+          value: platform
+      - equal:
+          path: metadata.labels["grafana_dashboard"]
+          value: "1"
+      - equal:
+          path: metadata.labels["app.kubernetes.io/name"]
+          value: external-secrets
+  - it: should include dashboard data
+    set:
+      grafanaDashboard.enabled: true
+    asserts:
+      - hasDocuments:
+          count: 1
+      - exists:
+          path: data["external-secrets.json"]

+ 3 - 0
deploy/charts/external-secrets/values.schema.json

@@ -366,6 +366,9 @@
                 "enabled": {
                     "type": "boolean"
                 },
+                "extraLabels": {
+                    "type": "object"
+                },
                 "sidecarLabel": {
                     "type": "string"
                 },

+ 3 - 0
deploy/charts/external-secrets/values.yaml

@@ -275,6 +275,9 @@ grafanaDashboard:
   # https://github.com/grafana/helm-charts/tree/main/charts/grafana
   annotations: {}
 
+  # -- Extra labels to add to the Grafana dashboard ConfigMap.
+  extraLabels: {}
+
 livenessProbe:
   # -- Enabled determines if the liveness probe should be used or not. By default it's disabled.
   enabled: false