From 05a227ac1b46e62050637248742051989a90d210 Mon Sep 17 00:00:00 2001
From: Nacho Barrientos <nacho.barrientos@cern.ch>
Date: Tue, 4 Mar 2025 15:03:59 +0100
Subject: [PATCH] [MONIT-4165] Allow configuring mounts in Alertmanager

---
 docs/values.md                           |  2 +
 templates/alertmanager/alertmanager.yaml | 10 +++-
 tests/alertmanager/alertmanager.yaml     | 61 ++++++++++++++++++++++++
 values.yaml                              |  2 +
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 tests/alertmanager/alertmanager.yaml

diff --git a/docs/values.md b/docs/values.md
index 5d9ac77..5f7fee9 100644
--- a/docs/values.md
+++ b/docs/values.md
@@ -79,6 +79,8 @@ This file contains the markdown version of the default values that this chart ta
 | metrics.alertmanager.ingress.hosts | Array | `[]` | list of hosts for the alertmanager ingress |
 | metrics.alertmanager.ingress.tls | Hash | `{}` | tls configuration for the alertmanager ingress |
 | metrics.alertmanager.nodeSelector | Hash | `{}` | node selector configuration for the alertmanager |
+| metrics.alertmanager.volumes | Array | `[]` | list of volumes to be declared |
+| metrics.alertmanager.volumeMounts | Array | `[]` | list of volumes to be mounted |
 | otlp.endpoint | string | `"monit-otlp.cern.ch"` | otlp endpoint where the otlp receivers are listening |
 | otlp.port | int | `4319` | otlp port where the otlp receivers are listening |
 | tenant.name | string | - | username used for authenitcating in the MONIT infrastructure |
diff --git a/templates/alertmanager/alertmanager.yaml b/templates/alertmanager/alertmanager.yaml
index d8b31bd..af4e7c6 100644
--- a/templates/alertmanager/alertmanager.yaml
+++ b/templates/alertmanager/alertmanager.yaml
@@ -13,4 +13,12 @@ spec:
   forceEnableClusterMode: true
   alertmanagerConfigSelector: {}
   alertmanagerConfigNamespaceSelector: {}
-{{- end -}}
\ No newline at end of file
+  {{- if .Values.metrics.alertmanager.volumes }}
+  volumes:
+    {{- toYaml .Values.metrics.alertmanager.volumes | nindent 4 }}
+  {{- end }}
+  {{- if .Values.metrics.alertmanager.volumeMounts  }}
+  volumeMounts:
+    {{- toYaml .Values.metrics.alertmanager.volumeMounts | nindent 4 }}
+  {{- end }}
+{{- end -}}
diff --git a/tests/alertmanager/alertmanager.yaml b/tests/alertmanager/alertmanager.yaml
new file mode 100644
index 0000000..327d621
--- /dev/null
+++ b/tests/alertmanager/alertmanager.yaml
@@ -0,0 +1,61 @@
+suite: test alertmanager alertmanager
+templates:
+  - alertmanager/alertmanager.yaml
+tests:
+  - it: should not be deployed if metrics are disabled
+    set:
+      metrics.enabled: false
+    asserts:
+      - containsDocument:
+          kind: Alertmanager
+          apiVersion: "monitoring.coreos.com/v1"
+          name: it-monit-alertmanager
+        not: true
+  - it: should not be deployed if alertmanager is not enabled
+    set:
+      metrics.enabled: true
+      metrics.alertmanager.enabled: false
+    asserts:
+      - containsDocument:
+          kind: Alertmanager
+          apiVersion: "monitoring.coreos.com/v1"
+          name: it-monit-alertmanager
+        not: true
+  - it: should be deployed if metrics and alertmanager are enabled
+    set:
+      metrics.enabled: true
+      metrics.alertmanager.enabled: true
+    asserts:
+      - containsDocument:
+          kind: Alertmanager
+          apiVersion: "monitoring.coreos.com/v1"
+          name: it-monit-alertmanager
+  - it: should be deployed with volumes and volumeMounts if configured
+    set:
+      metrics.enabled: true
+      metrics.alertmanager.enabled: true
+      metrics.alertmanager.volumes:
+        - name: test-volume
+          secret:
+            secretName: test-secret
+      metrics.alertmanager.volumeMounts:
+        - mountPath: /foo
+          name: test-volume
+    asserts:
+      - containsDocument:
+          kind: Alertmanager
+          apiVersion: "monitoring.coreos.com/v1"
+          name: it-monit-alertmanager
+      - contains:
+          path: spec.volumes
+          count: 1
+          content:
+            name: test-volume
+            secret:
+              secretName: test-secret
+      - contains:
+          path: spec.volumeMounts
+          count: 1
+          content:
+            mountPath: /foo
+            name: test-volume
diff --git a/values.yaml b/values.yaml
index d9f8842..9e9af9c 100644
--- a/values.yaml
+++ b/values.yaml
@@ -273,6 +273,8 @@ metrics:
     # If given will override the defaultNodeSelector and install the component
     # only on the nodes that match the given condition.
     nodeSelector: {}
+    volumes: []
+    volumeMounts: []
 
   apiServer:
     serviceMonitor:
-- 
GitLab