Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
IvanHunters
af3cccd8e6 fix(platform): update migration targetVersion to 38
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2026-04-08 23:26:13 +03:00
IvanHunters
730bb7a8c5 feat(postgres): pin PostgreSQL 17.7-standard-trixie for system databases
This change pins the PostgreSQL image to version 17.7-standard-trixie
for all system databases (keycloak-db, harbor-db, grafana-db, alerta-db,
seaweedfs-db) to ensure consistency and use the Debian Trixie base image.

Changes:
- Updated database templates for system components to use
  ghcr.io/cloudnative-pg/postgresql:17.7-standard-trixie
- Replaced migration 37 with a script that updates existing CNPG clusters
  to use the new image version
- Migration safely identifies system databases by checking for the absence
  of the apps.cozystack.io/application.name label to avoid touching
  user-created Postgres applications

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2026-04-08 23:22:15 +03:00
IvanHunters
64d33b22e2 revert(postgres): remove hardcoded PostgreSQL 17.7 image from system databases
Partially reverts #2304 by removing explicit imageName specification
from system database manifests (Harbor, Keycloak, Grafana, Alerta, SeaweedFS).

This allows CNPG operator to manage PostgreSQL versions according to
operator defaults and ClusterImageCatalog configuration.

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2026-04-07 21:26:08 +03:00
7 changed files with 59 additions and 31 deletions

View file

@ -1,43 +1,71 @@
#!/bin/sh #!/bin/sh
# Migration 37 --> 38 # Migration 37 --> 38
# Backfill spec.version on postgreses.apps.cozystack.io resources. # Update PostgreSQL image to 17.7-standard-trixie for system databases.
# #
# Before this migration PostgreSQL had a default version field set to v18. # This migration updates the imageName for all CNPG clusters with names matching
# This migration sets spec.version to "v17" for any postgres app resource that # system database patterns (keycloak-db, harbor-db, grafana-db, alerta-db, seaweedfs-db)
# does not already have it set, to ensure compatibility with monitoring # to use the pinned PostgreSQL 17.7-standard-trixie image from ghcr.io/cloudnative-pg.
# configurations that are hardcoded to PostgreSQL 17. #
# NOTE: This migration ONLY updates system CNPG Cluster resources (clusters.postgresql.cnpg.io),
# NOT user-created Postgres applications (postgreses.apps.cozystack.io).
set -euo pipefail set -euo pipefail
DEFAULT_VERSION="v17" TARGET_IMAGE="ghcr.io/cloudnative-pg/postgresql:17.7-standard-trixie"
# Skip if the CRD does not exist (postgres was never installed) # Database names to update (can be in any namespace)
if ! kubectl api-resources --api-group=apps.cozystack.io -o name 2>/dev/null | grep -q '^postgreses\.'; then DB_NAMES="keycloak-db harbor-db grafana-db alerta-db seaweedfs-db"
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}') echo "=== Updating PostgreSQL images for system databases: $DB_NAMES ==="
for resource in $POSTGRESES; do echo "Target image: $TARGET_IMAGE"
NS="${resource%%/*}"
APP_NAME="${resource##*/}"
# Skip if spec.version is already set # Find all CNPG clusters across all namespaces
CURRENT_VER=$(kubectl get postgreses.apps.cozystack.io -n "$NS" "$APP_NAME" \ ALL_CLUSTERS=$(kubectl get clusters.postgresql.cnpg.io -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}{"\n"}{end}' 2>/dev/null || true)
-o jsonpath='{.spec.version}')
if [ -n "$CURRENT_VER" ]; then for entry in $ALL_CLUSTERS; do
echo "SKIP $NS/$APP_NAME: spec.version already set to '$CURRENT_VER'" [ -z "$entry" ] && continue
NAMESPACE="${entry%%/*}"
CLUSTER_NAME="${entry##*/}"
# Skip if this is a user-created Postgres (has apps.cozystack.io/application.name label)
APP_LABEL=$(kubectl get clusters.postgresql.cnpg.io -n "$NAMESPACE" "$CLUSTER_NAME" \
-o jsonpath='{.metadata.labels.apps\.cozystack\.io/application\.name}' 2>/dev/null || echo "")
if [ -n "$APP_LABEL" ]; then
continue continue
fi fi
echo "Patching postgres/$APP_NAME in $NS: setting version=$DEFAULT_VERSION" # Check if cluster name matches one of our target databases
MATCH=false
for db_name in $DB_NAMES; do
if [ "$CLUSTER_NAME" = "$db_name" ]; then
MATCH=true
break
fi
done
kubectl patch postgreses.apps.cozystack.io -n "$NS" "$APP_NAME" --type=merge \ if [ "$MATCH" = false ]; then
--patch "{\"spec\":{\"version\":\"${DEFAULT_VERSION}\"}}" continue
fi
# Get current imageName
CURRENT_IMAGE=$(kubectl get clusters.postgresql.cnpg.io -n "$NAMESPACE" "$CLUSTER_NAME" \
-o jsonpath='{.spec.imageName}' 2>/dev/null || echo "")
if [ "$CURRENT_IMAGE" = "$TARGET_IMAGE" ]; then
echo "SKIP $NAMESPACE/$CLUSTER_NAME: already using $TARGET_IMAGE"
continue
fi
echo "PATCH $NAMESPACE/$CLUSTER_NAME: $CURRENT_IMAGE -> $TARGET_IMAGE"
kubectl patch clusters.postgresql.cnpg.io -n "$NAMESPACE" "$CLUSTER_NAME" \
--type=merge \
--patch "{\"spec\":{\"imageName\":\"${TARGET_IMAGE}\"}}"
done done
echo "=== PostgreSQL image update completed ==="
# Stamp version # Stamp version
kubectl create configmap -n cozy-system cozystack-version \ kubectl create configmap -n cozy-system cozystack-version \
--from-literal=version=38 --dry-run=client -o yaml | kubectl apply -f- --from-literal=version=38 --dry-run=client -o yaml | kubectl apply -f-

View file

@ -6,7 +6,7 @@ sourceRef:
migrations: migrations:
enabled: false enabled: false
image: ghcr.io/cozystack/cozystack/platform-migrations:v1.2.1@sha256:e8fcf006a4451fc0e961455e9b27a61b7103ee49b1a81fe5e4662ffed093fad6 image: ghcr.io/cozystack/cozystack/platform-migrations:v1.2.1@sha256:e8fcf006a4451fc0e961455e9b27a61b7103ee49b1a81fe5e4662ffed093fad6
targetVersion: 37 targetVersion: 38
# Bundle deployment configuration # Bundle deployment configuration
bundles: bundles:
system: system:

View file

@ -5,7 +5,7 @@ metadata:
name: {{ .Values.harbor.fullnameOverride }}-db name: {{ .Values.harbor.fullnameOverride }}-db
spec: spec:
instances: {{ .Values.db.replicas }} instances: {{ .Values.db.replicas }}
imageName: ghcr.io/cloudnative-pg/postgresql:17.7 imageName: ghcr.io/cloudnative-pg/postgresql:17.7-standard-trixie
storage: storage:
size: {{ .Values.db.size }} size: {{ .Values.db.size }}
{{- with .Values.db.storageClass }} {{- with .Values.db.storageClass }}

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@ metadata:
name: seaweedfs-db name: seaweedfs-db
spec: spec:
instances: {{ .Values.db.replicas }} instances: {{ .Values.db.replicas }}
imageName: ghcr.io/cloudnative-pg/postgresql:17.7 imageName: ghcr.io/cloudnative-pg/postgresql:17.7-standard-trixie
storage: storage:
size: {{ .Values.db.size }} size: {{ .Values.db.size }}
{{- with .Values.db.storageClass }} {{- with .Values.db.storageClass }}