From 3b4a5508c1bbca4729487b8e95fffaa6791c5f45 Mon Sep 17 00:00:00 2001
From: Nacho Barrientos <nacho.barrientos@cern.ch>
Date: Tue, 25 Feb 2025 10:47:27 +0100
Subject: [PATCH] [MONIT-4147] Make tenant credentials mandatory
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With this patch the chart will fail to install if either tenant.name
or tenant.password are not set if they're necessary, example:

```
λ helm -n monitoring diff upgrade kubernetes-monitoring . -f values.yaml -f ibarrien.yaml
Error: Failed to render chart: exit status 1: Error: execution error at (cern-it-monitoring-kubernetes/templates/fluentbit-metrics/configmap.yaml:22:13): Tenand password is required
```

If no fluentbit forwarding is configured, i.e.:

```yaml
metrics:
  fluentbit:
    enabled: false

logs:
  fluentbit:
    enabled: false
```

then the chart installs fine as they're note required in that case.
---
 docs/values.md |  4 ++--
 values.yaml    | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/docs/values.md b/docs/values.md
index 4d3d066..a8aea77 100644
--- a/docs/values.md
+++ b/docs/values.md
@@ -81,8 +81,8 @@ This file contains the markdown version of the default values that this chart ta
 | metrics.alertmanager.nodeSelector | Hash | `{}` | node selector configuration for the alertmanager |
 | 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 | `"nil"` | username used for authenitcating in the MONIT infrastructure |
-| tenant.password | string | `"nil"` | password (plain) used for authenitcating in the MONIT infrastructure |
+| tenant.name | string | - | username used for authenitcating in the MONIT infrastructure |
+| tenant.password | string | - | password (plain) used for authenitcating in the MONIT infrastructure |
 | crds.enabled | bool | `true` | whether to install Prometheus operator's CRDs |
 
 ----------------------------------------------
diff --git a/values.yaml b/values.yaml
index a755779..7c6e0c8 100644
--- a/values.yaml
+++ b/values.yaml
@@ -10,12 +10,12 @@ otlp:
   port: 4319
 
 # Tenant configuration. Username and Password are provided via CERN Central IT
-# Monitoring service.
-tenant:
+# Monitoring service. This bit is required if fluentbit is enabled (default)
+# tenant:
   # -- username used for authenitcating in the MONIT infrastructure
-  name: nil
+  # name: example
   # -- password (plain) used for authenitcating in the MONIT infrastructure
-  password: nil
+  # password: example
 
 # Kubernetes configuration.
 kubernetes:
@@ -220,8 +220,8 @@ metrics:
         traces_uri: /v1/traces
         tls: on
         tls.verify: off
-        http_user: {{ .Values.tenant.name }}
-        http_passwd: {{ .Values.tenant.password }}
+        http_user: {{ required "Tenant name is required" (.Values.tenant).name }}
+        http_passwd: {{ required "Tenant password is required" (.Values.tenant).password }}
         storage.total_limit_size: {{ .Values.metrics.fluentbit.diskMaxCache }}
         header: User-Agent {{ .Chart.Name }}/{{ .Chart.Version }}
 
@@ -414,8 +414,8 @@ logs:
           traces_uri /v1/traces
           tls on
           tls.verify off
-          http_user {{ .Values.tenant.name }}
-          http_passwd {{ .Values.tenant.password }}
+          http_user {{ required "Tenant name is required" (.Values.tenant).name }}
+          http_passwd {{ required "Tenant password is required" (.Values.tenant).password }}
           header tag monit
           header log_type kubernetes
           header User-Agent {{ .Chart.Name }}/{{ .Chart.Version }}
-- 
GitLab