From 6b6e75753e8cd6120144c6e78be885223800f926 Mon Sep 17 00:00:00 2001
From: Matteo Gazzetta <matteo_gazzetta@hotmail.it>
Date: Wed, 10 Nov 2021 18:06:44 +0100
Subject: [PATCH] Add namespace to service monitor (#186)

* Add namespace to service monitor
* Add namespace example to service monitor
* Update README.md
---
 Chart.yaml                    | 2 +-
 README.md                     | 1 +
 templates/servicemonitor.yaml | 5 ++++-
 values.yaml                   | 1 +
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/Chart.yaml b/Chart.yaml
index 3272694a..b213e807 100644
--- a/Chart.yaml
+++ b/Chart.yaml
@@ -1,7 +1,7 @@
 ---
 apiVersion: v2
 name: nifi
-version: 1.0.0
+version: 1.0.1
 appVersion: 1.14.0
 description: Apache NiFi is a software project from the Apache Software Foundation designed to automate the flow of data between software systems.
 keywords:
diff --git a/README.md b/README.md
index 9f9def16..579a3999 100644
--- a/README.md
+++ b/README.md
@@ -231,6 +231,7 @@ The following table lists the configurable parameters of the nifi chart and the
 | `metrics.prometheus.enabled`            | Enable prometheus to access nifi metrics endpoint                                                                                    | `false`                                                      |
 | `metrics.prometheus.port`              | Port where Nifi server will expose Prometheus metrics                                                                                  | `9092`                                                      |
 | `metrics.prometheus.serviceMonitor.enabled`       | If `true`, creates a Prometheus Operator ServiceMonitor (also requires `metrics.prometheus.enabled` to be `true`)                       | `false`                                        |
+| `metrics.prometheus.serviceMonitor.namespace`       | In which namespace the ServiceMonitor should be created                       | 
 | `metrics.prometheus.serviceMonitor.labels`       | Additional labels for the ServiceMonitor                       | `nil`                                        |
 
 ## Troubleshooting
diff --git a/templates/servicemonitor.yaml b/templates/servicemonitor.yaml
index d810ca64..4f3f18ff 100644
--- a/templates/servicemonitor.yaml
+++ b/templates/servicemonitor.yaml
@@ -4,6 +4,9 @@ apiVersion: monitoring.coreos.com/v1
 kind: ServiceMonitor
 metadata:
   name: {{ template "apache-nifi.fullname" . }}
+{{- with .Values.metrics.prometheus.serviceMonitor.namespace }}
+  namespace: {{ . }}
+{{- end }}
   labels:
     app: {{ include "apache-nifi.name" . | quote }}
     chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
@@ -34,4 +37,4 @@ spec:
   namespaceSelector:
     matchNames:
     - {{ .Release.Namespace | quote }}
-{{- end }}
\ No newline at end of file
+{{- end }}
diff --git a/values.yaml b/values.yaml
index a175e39c..88c7ccfb 100644
--- a/values.yaml
+++ b/values.yaml
@@ -367,5 +367,6 @@ metrics:
     serviceMonitor:
       # Enable deployment of Prometheus Operator ServiceMonitor resource
       enabled: false
+      # namespace: monitoring
       # Additional labels for the ServiceMonitor
       labels: {}