From f3994971b46f42f35263046dba3177641d965921 Mon Sep 17 00:00:00 2001 From: Anthony Rabbito Date: Wed, 1 Nov 2023 21:13:49 -0400 Subject: [PATCH 1/3] feat(kps): install service monitors in same namespace when ignoreNamespaceSelectors Signed-off-by: Anthony Rabbito --- .../templates/exporters/core-dns/servicemonitor.yaml | 4 ++++ .../templates/exporters/kube-api-server/servicemonitor.yaml | 4 ++++ .../exporters/kube-controller-manager/servicemonitor.yaml | 4 ++++ .../templates/exporters/kube-dns/servicemonitor.yaml | 4 ++++ .../templates/exporters/kube-etcd/servicemonitor.yaml | 4 ++++ .../templates/exporters/kube-proxy/servicemonitor.yaml | 4 ++++ .../templates/exporters/kube-scheduler/servicemonitor.yaml | 4 ++++ .../templates/exporters/kubelet/servicemonitor.yaml | 4 ++++ charts/kube-prometheus-stack/values.yaml | 1 + 9 files changed, 33 insertions(+) diff --git a/charts/kube-prometheus-stack/templates/exporters/core-dns/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/core-dns/servicemonitor.yaml index 5447fde4c561..cf7e80dd128d 100644 --- a/charts/kube-prometheus-stack/templates/exporters/core-dns/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/core-dns/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-coredns + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: kube-system + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-coredns {{- with .Values.coreDns.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kube-api-server/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kube-api-server/servicemonitor.yaml index 9ae03e5b0f40..a140d4554a7f 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kube-api-server/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kube-api-server/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-apiserver + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: default + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-apiserver {{- with .Values.kubeApiServer.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kube-controller-manager/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kube-controller-manager/servicemonitor.yaml index 4c30636a6575..0f64844cbaf9 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kube-controller-manager/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kube-controller-manager/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-kube-controller-manager + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: kube-system + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-kube-controller-manager {{- with .Values.kubeControllerManager.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kube-dns/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kube-dns/servicemonitor.yaml index ffb5d04c3190..260ad1ed3840 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kube-dns/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kube-dns/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-kube-dns + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: kube-system + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-kube-dns {{- with .Values.kubeDns.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kube-etcd/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kube-etcd/servicemonitor.yaml index 2336753ea08c..f5048531aca9 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kube-etcd/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kube-etcd/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-kube-etcd + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: kube-system + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-kube-etcd {{- with .Values.kubeEtcd.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kube-proxy/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kube-proxy/servicemonitor.yaml index 33a30ee71bee..0a01a7f8b903 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kube-proxy/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kube-proxy/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-kube-proxy + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: kube-system + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-kube-proxy {{- with .Values.kubeProxy.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kube-scheduler/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kube-scheduler/servicemonitor.yaml index a8a8d0bc004f..6849340c494a 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kube-scheduler/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kube-scheduler/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-kube-scheduler + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: kube-system + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-kube-scheduler {{- with .Values.kubeScheduler.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/templates/exporters/kubelet/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/exporters/kubelet/servicemonitor.yaml index 001e8fb1f518..f27f232abf94 100644 --- a/charts/kube-prometheus-stack/templates/exporters/kubelet/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/exporters/kubelet/servicemonitor.yaml @@ -3,7 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "kube-prometheus-stack.fullname" . }}-kubelet + {{- if .Values.prometheus.prometheusSpec.ignoreNamespaceSelectors }} + namespace: {{ .Values.kubelet.namespace }} + {{- else }} namespace: {{ template "kube-prometheus-stack.namespace" . }} + {{- end }} labels: app: {{ template "kube-prometheus-stack.name" . }}-kubelet {{- with .Values.kubelet.serviceMonitor.additionalLabels }} diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index c0eee10c9d76..8d9bbf0058f3 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -3505,6 +3505,7 @@ prometheus: ## IgnoreNamespaceSelectors if set to true will ignore NamespaceSelector settings from the podmonitor and servicemonitor ## configs, and they will only discover endpoints within their current namespace. Defaults to false. + ## When true servicemonitors will install in namespace .spec.namespaceSelector.matchNames.0 ignoreNamespaceSelectors: false ## EnforcedNamespaceLabel enforces adding a namespace label of origin for each alert and metric that is user created. From f3f7d3296b15fca6eb6f1669ae12123b7abafa3e Mon Sep 17 00:00:00 2001 From: Anthony Rabbito Date: Wed, 1 Nov 2023 21:19:39 -0400 Subject: [PATCH 2/3] fix: bump helm version Signed-off-by: Anthony Rabbito --- charts/kube-prometheus-stack/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index 067e65ddb41a..b50a9b703ed4 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -21,7 +21,7 @@ name: kube-prometheus-stack sources: - https://github.com/prometheus-community/helm-charts - https://github.com/prometheus-operator/kube-prometheus -version: 52.1.0 +version: 53.2.0 appVersion: v0.68.0 kubeVersion: ">=1.19.0-0" home: https://github.com/prometheus-operator/kube-prometheus From d2ce68e647b85cd3cc214e99e3d7b6d91cca007d Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Thu, 4 Jan 2024 10:44:47 +0100 Subject: [PATCH 3/3] Update charts/kube-prometheus-stack/values.yaml Co-authored-by: Gabriel Martinez <19713226+GMartinez-Sisti@users.noreply.github.com> Signed-off-by: Quentin Bisson --- charts/kube-prometheus-stack/values.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index 16389dbd290d..0fd229e4d1e5 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -3759,9 +3759,10 @@ prometheus: ## OverrideHonorTimestamps allows to globally enforce honoring timestamps in all scrape configs. overrideHonorTimestamps: false - ## IgnoreNamespaceSelectors if set to true will ignore NamespaceSelector settings from the podmonitor and servicemonitor - ## configs, and they will only discover endpoints within their current namespace. Defaults to false. - ## When true servicemonitors will install in namespace .spec.namespaceSelector.matchNames.0 + ## When ignoreNamespaceSelectors is set to true, namespaceSelector from all PodMonitor, ServiceMonitor and Probe objects will be ignored, + ## they will only discover targets within the namespace of the PodMonitor, ServiceMonitor and Probe object, + ## and servicemonitors will be installed in the default service namespace. + ## Defaults to false. ignoreNamespaceSelectors: false ## EnforcedNamespaceLabel enforces adding a namespace label of origin for each alert and metric that is user created.