From 92e6c3d0f05f6a08c54f59b60f91784d0d4fa78e Mon Sep 17 00:00:00 2001 From: Nelson Alfonso <45660392+Dashing-Nelson@users.noreply.github.com> Date: Thu, 13 Nov 2025 10:22:49 +0000 Subject: [PATCH 1/3] feat(monitoring): add support for additional labels in PodMonitor configuration Signed-off-by: Nelson Alfonso <45660392+Dashing-Nelson@users.noreply.github.com> --- charts/cluster/templates/cluster.yaml | 6 ++++++ charts/cluster/values.schema.json | 3 +++ charts/cluster/values.yaml | 3 +++ 3 files changed, 12 insertions(+) diff --git a/charts/cluster/templates/cluster.yaml b/charts/cluster/templates/cluster.yaml index bb9ea770cc..93c3c45437 100644 --- a/charts/cluster/templates/cluster.yaml +++ b/charts/cluster/templates/cluster.yaml @@ -141,5 +141,11 @@ spec: {{- toYaml . | nindent 6 }} {{ end }} {{- end }} + {{- if not (empty .Values.cluster.monitoring.podMonitor.labels) }} + {{- with .Values.cluster.monitoring.podMonitor.labels }} + podMonitorAdditionalLabels: + {{- toYaml . | nindent 6 }} + {{ end }} + {{- end }} {{ include "cluster.bootstrap" . | nindent 2 }} {{ include "cluster.backup" . | nindent 2 }} diff --git a/charts/cluster/values.schema.json b/charts/cluster/values.schema.json index 8890226868..d49975eca5 100644 --- a/charts/cluster/values.schema.json +++ b/charts/cluster/values.schema.json @@ -244,6 +244,9 @@ "metricRelabelings": { "type": "array" }, + "labels": { + "type": "object" + }, "relabelings": { "type": "array" } diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index 3d5f11dc1a..5a1f36c2e9 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -309,6 +309,9 @@ cluster: podMonitor: # -- Whether to enable the PodMonitor enabled: true + # -- Additional labels to set on the generated PodMonitor resource. + # Add labels your monitoring stack requires (for example `team-name`). + labels: {} # --The list of relabelings for the PodMonitor. # Applied to samples before scraping. relabelings: [] From 37ff723dd7616665ec63ef92447cbd1e4d0931d0 Mon Sep 17 00:00:00 2001 From: Nelson Alfonso <45660392+Dashing-Nelson@users.noreply.github.com> Date: Fri, 14 Nov 2025 10:55:04 +0000 Subject: [PATCH 2/3] feat(monitoring): disable PodMonitor by default and add PodMonitor template Signed-off-by: Nelson Alfonso <45660392+Dashing-Nelson@users.noreply.github.com> --- charts/cluster/templates/cluster.yaml | 20 +--------- charts/cluster/templates/podmonitor.yaml | 48 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 charts/cluster/templates/podmonitor.yaml diff --git a/charts/cluster/templates/cluster.yaml b/charts/cluster/templates/cluster.yaml index 93c3c45437..26bb43ade1 100644 --- a/charts/cluster/templates/cluster.yaml +++ b/charts/cluster/templates/cluster.yaml @@ -116,7 +116,7 @@ spec: {{- end }} monitoring: - enablePodMonitor: {{ and .Values.cluster.monitoring.enabled .Values.cluster.monitoring.podMonitor.enabled }} + enablePodMonitor: false disableDefaultQueries: {{ .Values.cluster.monitoring.disableDefaultQueries }} {{- if not (empty .Values.cluster.monitoring.customQueries) }} customQueriesConfigMap: @@ -129,23 +129,5 @@ spec: {{- toYaml . | nindent 6 }} {{ end }} {{- end }} - {{- if not (empty .Values.cluster.monitoring.podMonitor.relabelings) }} - {{- with .Values.cluster.monitoring.podMonitor.relabelings }} - podMonitorRelabelings: - {{- toYaml . | nindent 6 }} - {{ end }} - {{- end }} - {{- if not (empty .Values.cluster.monitoring.podMonitor.metricRelabelings) }} - {{- with .Values.cluster.monitoring.podMonitor.metricRelabelings }} - podMonitorMetricRelabelings: - {{- toYaml . | nindent 6 }} - {{ end }} - {{- end }} - {{- if not (empty .Values.cluster.monitoring.podMonitor.labels) }} - {{- with .Values.cluster.monitoring.podMonitor.labels }} - podMonitorAdditionalLabels: - {{- toYaml . | nindent 6 }} - {{ end }} - {{- end }} {{ include "cluster.bootstrap" . | nindent 2 }} {{ include "cluster.backup" . | nindent 2 }} diff --git a/charts/cluster/templates/podmonitor.yaml b/charts/cluster/templates/podmonitor.yaml new file mode 100644 index 0000000000..10cd04b29f --- /dev/null +++ b/charts/cluster/templates/podmonitor.yaml @@ -0,0 +1,48 @@ +# +# Copyright © contributors to CloudNativePG, established as +# CloudNativePG a Series of LF Projects, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# +{{- if and .Values.cluster.monitoring.enabled .Values.cluster.monitoring.podMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ include "cluster.fullname" . }} + namespace: {{ include "cluster.namespace" . }} + labels: + {{- include "cluster.labels" . | nindent 4 }} + {{- with .Values.cluster.monitoring.podMonitor.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.cluster.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + matchLabels: + cnpg.io/cluster: {{ include "cluster.fullname" . }} + podMetricsEndpoints: + - port: metrics + {{- with .Values.cluster.monitoring.podMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.cluster.monitoring.podMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} From 4bf46cd1e16be870fd4adf92497bf89d7123ddee Mon Sep 17 00:00:00 2001 From: Nelson Alfonso <45660392+Dashing-Nelson@users.noreply.github.com> Date: Fri, 14 Nov 2025 10:58:23 +0000 Subject: [PATCH 3/3] feat(monitoring): add support for additional labels in PodMonitor configuration Signed-off-by: Nelson Alfonso <45660392+Dashing-Nelson@users.noreply.github.com> --- charts/cluster/README.md | 1 + charts/cluster/examples/pgbouncer.yaml | 2 ++ .../cluster/test/monitoring/01-monitoring_cluster-assert.yaml | 3 +++ charts/cluster/test/monitoring/01-monitoring_cluster.yaml | 3 +++ 4 files changed, 9 insertions(+) diff --git a/charts/cluster/README.md b/charts/cluster/README.md index d042268365..bf853c9a30 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -169,6 +169,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | cluster.monitoring.disableDefaultQueries | bool | `false` | Whether the default queries should be injected. Set it to true if you don't want to inject default queries into the cluster. | | cluster.monitoring.enabled | bool | `false` | Whether to enable monitoring | | cluster.monitoring.podMonitor.enabled | bool | `true` | Whether to enable the PodMonitor | +| cluster.monitoring.podMonitor.labels | object | `{}` | Additional labels to set on the generated PodMonitor resource. Add labels your monitoring stack requires (for example `team-name`). | | cluster.monitoring.podMonitor.metricRelabelings | list | `[]` | The list of metric relabelings for the PodMonitor. Applied to samples before ingestion. | | cluster.monitoring.podMonitor.relabelings | list | `[]` | The list of relabelings for the PodMonitor. Applied to samples before scraping. | | cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts | diff --git a/charts/cluster/examples/pgbouncer.yaml b/charts/cluster/examples/pgbouncer.yaml index 94d4987e68..75755e2a28 100644 --- a/charts/cluster/examples/pgbouncer.yaml +++ b/charts/cluster/examples/pgbouncer.yaml @@ -7,6 +7,8 @@ cluster: enabled: true podMonitor: enabled: true + # labels: + # team-name: my-team backups: enabled: false diff --git a/charts/cluster/test/monitoring/01-monitoring_cluster-assert.yaml b/charts/cluster/test/monitoring/01-monitoring_cluster-assert.yaml index 92ac447b5e..9086c7b1f4 100644 --- a/charts/cluster/test/monitoring/01-monitoring_cluster-assert.yaml +++ b/charts/cluster/test/monitoring/01-monitoring_cluster-assert.yaml @@ -36,6 +36,9 @@ apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: name: monitoring-cluster + labels: + team-name: test-team + environment: test spec: selector: matchLabels: diff --git a/charts/cluster/test/monitoring/01-monitoring_cluster.yaml b/charts/cluster/test/monitoring/01-monitoring_cluster.yaml index 314fccfb22..9e07374dc9 100644 --- a/charts/cluster/test/monitoring/01-monitoring_cluster.yaml +++ b/charts/cluster/test/monitoring/01-monitoring_cluster.yaml @@ -21,6 +21,9 @@ cluster: usage: GAUGE description: "Cache hit ratio" podMonitor: + labels: + team-name: test-team + environment: test relabelings: - targetLabel: environment replacement: test