From 8d095b58f94874489a3ffa5574bb9bfa2de03003 Mon Sep 17 00:00:00 2001 From: Alex Lebens Date: Sun, 17 May 2026 20:22:44 -0500 Subject: [PATCH] feat: move podmonitor to template in advance of depreciation --- charts/postgres-cluster/Chart.yaml | 2 +- charts/postgres-cluster/README.md | 3 ++- .../postgres-cluster/templates/cluster.yaml | 21 +++++++------------ .../templates/pod-monitor.yaml | 18 ++++++++++++++++ .../templates/prometheus-rule.yaml | 1 + charts/postgres-cluster/values.yaml | 1 + 6 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 charts/postgres-cluster/templates/pod-monitor.yaml diff --git a/charts/postgres-cluster/Chart.yaml b/charts/postgres-cluster/Chart.yaml index cfb746e..15bab83 100644 --- a/charts/postgres-cluster/Chart.yaml +++ b/charts/postgres-cluster/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: postgres-cluster -version: 7.12.1 +version: 7.13.0 description: Cloudnative-pg Cluster keywords: - database diff --git a/charts/postgres-cluster/README.md b/charts/postgres-cluster/README.md index 1cdd384..c518e62 100644 --- a/charts/postgres-cluster/README.md +++ b/charts/postgres-cluster/README.md @@ -1,6 +1,6 @@ # postgres-cluster -![Version: 7.12.1](https://img.shields.io/badge/Version-7.12.1-informational?style=flat-square) ![AppVersion: v1.29.0](https://img.shields.io/badge/AppVersion-v1.29.0-informational?style=flat-square) +![Version: 7.13.0](https://img.shields.io/badge/Version-7.13.0-informational?style=flat-square) ![AppVersion: v1.29.0](https://img.shields.io/badge/AppVersion-v1.29.0-informational?style=flat-square) Cloudnative-pg Cluster @@ -42,6 +42,7 @@ Cloudnative-pg Cluster | cluster.monitoring.podMonitor.enabled | bool | `true` | Whether to enable the PodMonitor | | 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 | object | `{"enabled":true,"excludeRules":["CNPGClusterLastFailedArchiveTimeWarning"]}` | Prometheus rule | | cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts | | cluster.monitoring.prometheusRule.excludeRules | list | `["CNPGClusterLastFailedArchiveTimeWarning"]` | Exclude specified rules | | cluster.postgresUID | int | `-1` | The UID and GID of the postgres user inside the image, defaults to 26 | diff --git a/charts/postgres-cluster/templates/cluster.yaml b/charts/postgres-cluster/templates/cluster.yaml index f6a40b7..252cad9 100644 --- a/charts/postgres-cluster/templates/cluster.yaml +++ b/charts/postgres-cluster/templates/cluster.yaml @@ -35,7 +35,7 @@ spec: {{- with .Values.cluster.resources }} resources: {{- toYaml . | nindent 4 }} - {{ end }} + {{- end }} {{- with .Values.cluster.affinity }} affinity: {{- toYaml . | nindent 4 }} @@ -43,7 +43,6 @@ spec: {{- if .Values.cluster.priorityClassName }} priorityClassName: {{ .Values.cluster.priorityClassName }} {{- end }} - primaryUpdateMethod: {{ .Values.cluster.primaryUpdateMethod }} primaryUpdateStrategy: {{ .Values.cluster.primaryUpdateStrategy }} logLevel: {{ .Values.cluster.logLevel }} @@ -57,7 +56,6 @@ spec: name: {{ . }} {{ end }} enablePDB: {{ .Values.cluster.enablePDB }} - postgresql: {{- if .Values.cluster.postgresql.shared_preload_libraries }} shared_preload_libraries: @@ -85,7 +83,6 @@ spec: parameters: {{- toYaml . | nindent 6 }} {{- end }} - {{- if not (and (empty .Values.cluster.roles) (empty .Values.cluster.services)) }} managed: {{- with .Values.cluster.services }} @@ -97,14 +94,12 @@ spec: {{- toYaml . | nindent 6 }} {{ end }} {{- end }} - {{- with .Values.cluster.serviceAccountTemplate }} serviceAccountTemplate: {{- toYaml . | nindent 4 }} {{- 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: @@ -127,9 +122,9 @@ spec: {{- with .Values.cluster.monitoring.podMonitor.metricRelabelings }} podMonitorMetricRelabelings: {{- toYaml . | nindent 6 }} - {{ end }} {{- end }} - + {{- end }} + {{- if not (empty .Values.backup.objectStore) -}} plugins: {{- range $objectStore := .Values.backup.objectStore }} - name: barman-cloud.cloudnative-pg.io @@ -146,7 +141,7 @@ spec: {{- else }} serverName: "{{ include "cluster.name" $ }}-backup-{{ $objectStore.index }}" {{- end }} - {{- end }} - - {{ include "cluster.bootstrap" . | nindent 2 }} - {{ include "cluster.externalClusters" . | nindent 2 }} + {{- end -}} + {{- end -}} + {{- include "cluster.bootstrap" . | nindent 2 -}} + {{- include "cluster.externalClusters" . | nindent 2 -}} diff --git a/charts/postgres-cluster/templates/pod-monitor.yaml b/charts/postgres-cluster/templates/pod-monitor.yaml new file mode 100644 index 0000000..4d083a9 --- /dev/null +++ b/charts/postgres-cluster/templates/pod-monitor.yaml @@ -0,0 +1,18 @@ +{{- if and .Values.cluster.monitoring.enabled .Values.cluster.monitoring.podMonitor.enabled -}} +--- +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ include "cluster.name" $ }} + namespace: {{ include "cluster.namespace" $ }} + labels: + app.kubernetes.io/name: {{ include "cluster.name" $ }} + {{- include "cluster.labels" $ | nindent 4 }} +spec: + selector: + matchLabels: + cnpg.io/cluster: {{ include "cluster.name" $ }} + cnpg.io/podRole: instance + podMetricsEndpoints: + - port: metrics +{{- end -}} diff --git a/charts/postgres-cluster/templates/prometheus-rule.yaml b/charts/postgres-cluster/templates/prometheus-rule.yaml index 46c477c..beb0d59 100644 --- a/charts/postgres-cluster/templates/prometheus-rule.yaml +++ b/charts/postgres-cluster/templates/prometheus-rule.yaml @@ -1,4 +1,5 @@ {{- if and .Values.cluster.monitoring.enabled .Values.cluster.monitoring.prometheusRule.enabled -}} +--- apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: diff --git a/charts/postgres-cluster/values.yaml b/charts/postgres-cluster/values.yaml index af81d30..ce17882 100644 --- a/charts/postgres-cluster/values.yaml +++ b/charts/postgres-cluster/values.yaml @@ -127,6 +127,7 @@ cluster: # Applied to samples before ingestion. metricRelabelings: [] + # -- Prometheus rule prometheusRule: # -- Whether to enable the PrometheusRule automated alerts