feat(postgres): hardcode PostgreSQL 17 for monitoring and add migration

Add migration 37 to backfill spec.version=v17 for existing PostgreSQL
resources without a version set.

Hardcode PostgreSQL 17.7 image in monitoring databases (Grafana and Alerta)
to ensure compatibility with monitoring queries that expect PostgreSQL 17
features (pg_stat_checkpointer, updated pg_stat_bgwriter).

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
(cherry picked from commit fd1714442e)
This commit is contained in:
IvanHunters 2026-03-31 00:46:47 +03:00 committed by github-actions[bot]
parent 02e200372b
commit 091f21fbd2
3 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,43 @@
#!/bin/sh
# Migration 37 --> 38
# Backfill spec.version on postgreses.apps.cozystack.io resources.
#
# Before this migration PostgreSQL had a default version field set to v18.
# This migration sets spec.version to "v17" for any postgres app resource that
# does not already have it set, to ensure compatibility with monitoring
# configurations that are hardcoded to PostgreSQL 17.
set -euo pipefail
DEFAULT_VERSION="v17"
# Skip if the CRD does not exist (postgres was never installed)
if ! kubectl api-resources --api-group=apps.cozystack.io -o name 2>/dev/null | grep -q '^postgreses\.'; then
echo "CRD postgreses.apps.cozystack.io not found, skipping migration"
kubectl create configmap -n cozy-system cozystack-version \
--from-literal=version=38 --dry-run=client -o yaml | kubectl apply -f-
exit 0
fi
POSTGRESES=$(kubectl get postgreses.apps.cozystack.io -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}{"\n"}{end}')
for resource in $POSTGRESES; do
NS="${resource%%/*}"
APP_NAME="${resource##*/}"
# Skip if spec.version is already set
CURRENT_VER=$(kubectl get postgreses.apps.cozystack.io -n "$NS" "$APP_NAME" \
-o jsonpath='{.spec.version}')
if [ -n "$CURRENT_VER" ]; then
echo "SKIP $NS/$APP_NAME: spec.version already set to '$CURRENT_VER'"
continue
fi
echo "Patching postgres/$APP_NAME in $NS: setting version=$DEFAULT_VERSION"
kubectl patch postgreses.apps.cozystack.io -n "$NS" "$APP_NAME" --type=merge \
--patch "{\"spec\":{\"version\":\"${DEFAULT_VERSION}\"}}"
done
# Stamp version
kubectl create configmap -n cozy-system cozystack-version \
--from-literal=version=38 --dry-run=client -o yaml | kubectl apply -f-

View file

@ -5,6 +5,7 @@ metadata:
name: alerta-db
spec:
instances: 2
imageName: ghcr.io/cloudnative-pg/postgresql:17.7
{{- if .Values._cluster.scheduling }}
{{- $rawConstraints := get .Values._cluster.scheduling "globalAppTopologySpreadConstraints" }}
{{- if $rawConstraints }}

View file

@ -4,6 +4,7 @@ metadata:
name: grafana-db
spec:
instances: 2
imageName: ghcr.io/cloudnative-pg/postgresql:17.7
storage:
size: {{ .Values.grafana.db.size }}
{{- if .Values._cluster.scheduling }}