Просмотр исходного кода

feat(charts): allow specifying namespace for grafana dashboard ConfigMap (#6919) (#6920)

Mirrors serviceMonitor.namespace: grafanaDashboard.namespace falls back to the chart namespace (namespaceOverride, then release namespace).

Signed-off-by: Oliver Wilkins <okwilkins@googlemail.com>
Co-authored-by: Alexander Chernov <alexander@chernov.it>
Oli Wilkins 6 дней назад
Родитель
Сommit
29a136efbf

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

@@ -161,6 +161,7 @@ The command removes all the Kubernetes components associated with the chart and
 | 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.namespace | string | `""` | Namespace where the dashboard ConfigMap should be created. Resolution order: grafanaDashboard.namespace, then namespaceOverride, then the release namespace. |
 | 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. |
 | hostAliases | list | `[]` | Specifies `hostAliases` to deployment |

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

@@ -3,7 +3,7 @@ apiVersion: v1
 kind: ConfigMap
 metadata:
   name: {{ include "external-secrets.fullname" . }}-dashboard
-  namespace: {{ include "external-secrets.namespace" . }}
+  namespace: {{ .Values.grafanaDashboard.namespace | default (include "external-secrets.namespace" .) | quote }}
   labels:
     {{ .Values.grafanaDashboard.sidecarLabel }}: {{ .Values.grafanaDashboard.sidecarLabelValue | quote }}
     {{- include "external-secrets.labels" . | nindent 4 }}

+ 41 - 1
deploy/charts/external-secrets/tests/grafana_dashboard_test.yaml

@@ -91,4 +91,44 @@ tests:
       - hasDocuments:
           count: 1
       - exists:
-          path: data["external-secrets.json"]
+          path: data["external-secrets.json"]
+  - it: should default namespace to release namespace
+    set:
+      grafanaDashboard.enabled: true
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.namespace
+          value: NAMESPACE
+  - it: should override namespace
+    set:
+      grafanaDashboard.enabled: true
+      grafanaDashboard.namespace: monitoring
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.namespace
+          value: monitoring
+  - it: should use namespaceOverride when grafanaDashboard.namespace is unset
+    set:
+      grafanaDashboard.enabled: true
+      namespaceOverride: override-ns
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.namespace
+          value: override-ns
+  - it: should prefer grafanaDashboard.namespace over namespaceOverride
+    set:
+      grafanaDashboard.enabled: true
+      grafanaDashboard.namespace: monitoring
+      namespaceOverride: override-ns
+    asserts:
+      - hasDocuments:
+          count: 1
+      - equal:
+          path: metadata.namespace
+          value: monitoring

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

@@ -558,6 +558,9 @@
                 "extraLabels": {
                     "type": "object"
                 },
+                "namespace": {
+                    "type": "string"
+                },
                 "sidecarLabel": {
                     "type": "string"
                 },

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

@@ -389,6 +389,10 @@ grafanaDashboard:
   # -- If true creates a Grafana dashboard.
   enabled: false
 
+  # -- Namespace where the dashboard ConfigMap should be created.
+  # Resolution order: grafanaDashboard.namespace, then namespaceOverride, then the release namespace.
+  namespace: ""
+
   # -- Label that ConfigMaps should have to be loaded as dashboards.
   sidecarLabel: "grafana_dashboard"