From c6c3db2867805f78e6079c53cadff50db821c93e Mon Sep 17 00:00:00 2001
From: Guillermo Facundo Colunga <guillermo.facundo.colunga@cern.ch>
Date: Tue, 21 Jan 2025 14:38:09 +0100
Subject: [PATCH] [MONIT-4106] fluentbit/metrics: add support for user provided
 lua scripts

While doing trying to mimic the OpenShift logging setup with the current
Helm chart we noticed that they were using the lua scripts input from
the fluent bit official Helm chart. In our case this was not possible
and had to be done by adding secrets one by one.

We agreed to mimic this behaviour and had our own helm chart have the
option to add lua scripts to the fluent bit via helm chart values.

This commit modifies the configmap used to create the lua script that
we required for the timestampt in such a way that now it creates this
first lua script but also creates any other provided by the users via
the values of the helm chart.

Reported-at: https://its.cern.ch/jira/browse/MONIT-4106
Signed-off-by: Guillermo Facundo Colunga <guillermo.facundo.colunga@gmail.com>
Signed-off-by: Guillermo Facundo Colunga <guillermo.facundo.colunga@cern.ch>
---
 .../fluentbit-metrics/configmap-luascripts.yaml      | 12 ++++++++++++
 templates/fluentbit-metrics/statefulset.yaml         |  5 +++++
 2 files changed, 17 insertions(+)
 create mode 100644 templates/fluentbit-metrics/configmap-luascripts.yaml

diff --git a/templates/fluentbit-metrics/configmap-luascripts.yaml b/templates/fluentbit-metrics/configmap-luascripts.yaml
new file mode 100644
index 0000000..9f8c1c9
--- /dev/null
+++ b/templates/fluentbit-metrics/configmap-luascripts.yaml
@@ -0,0 +1,12 @@
+{{- if and .Values.metrics.enabled .Values.metrics.fluentbit.enabled -}}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: it-monit-metrics-collector-fluentbit-scripts
+data:
+  {{- if .Values.metrics.fluentbit.luaScripts -}}
+  {{ range $key, $value := .Values.metrics.fluentbit.luaScripts }}
+  {{ $key }}: {{ $value | quote }}
+  {{ end }}
+  {{ end }}
+{{- end -}}
\ No newline at end of file
diff --git a/templates/fluentbit-metrics/statefulset.yaml b/templates/fluentbit-metrics/statefulset.yaml
index 32eff77..e7cbd5c 100644
--- a/templates/fluentbit-metrics/statefulset.yaml
+++ b/templates/fluentbit-metrics/statefulset.yaml
@@ -33,6 +33,8 @@ spec:
           volumeMounts:
             - name: config
               mountPath: /fluent-bit/etc/conf
+            - name: scripts
+              mountPath: /fluent-bit/etc/scripts
             - name: fluentbit
               mountPath: /flb-storage/
           {{- if .Values.metrics.fluentbit.extraVolumeMounts }}
@@ -46,6 +48,9 @@ spec:
         - name: config
           configMap: 
             name: it-monit-metrics-collector-fluentbit
+        - name: scripts
+          configMap:
+            name: it-monit-metrics-collector-fluentbit-scripts
         - name: fluentbit
           emptyDir:
             sizeLimit: {{ .Values.metrics.fluentbit.diskMaxCache }}
-- 
GitLab