simplify and automate Postgres version upgrades
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- helm, postgresql
- Ambito
- databases
Direzione di ricerca
Start with templates/pg_cluster.yaml and the chart README, then inspect the release values and the charts that create the keycloak and metadig clusters. The issue recommends first confirming the image details, making the image explicit in values, and validating the rendered chart; read the remaining §4 steps to identify all affected files. Done means releases render with an explicit PostgreSQL image and the README accurately describes upgrade behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Our CNPG-managed PostgreSQL clusters do not receive minor-version upgrades, despite what our README says. Every cluster created by this chart is frozen at the default image of the operator version that was running when the cluster was created. On both dev-k8s and prod-k8s, every chart-managed cluster is on PG 17.5. The current PG 17 minor release is 17.12, so we are seven minor releases behind on security and bug fixes.
This issue does three things:
- Documents how the chart behaves today.
- Proposes two ways to fix it:
- (Pathway A) pin and bump
image.nameexplicitly per release. - (Pathway B) manage versions centrally with a
ClusterImageCatalog.
- (Pathway A) pin and bump
- Lays out the implementation steps in the chart and in the operator installation.
Upgrading the CNPG operator itself (1.27 → 1.30) is tracked separately in DataONEorg/k8s-cluster #90 because it first needs a Kubernetes upgrade. This issue does not depend on that work. Everything here runs on the operator we already have (CNPG 1.27). The Prep Step below must be finished before the operator upgrade, otherwise, after the operator upgrade, any newly created, rebuilt or restored cluster without an explicit image would silently come up on PG 18.
1. Current behavior
How the image gets chosen
-
templates/pg_cluster.yamlonly rendersspec.imageNamewhenimageOverrideSpecis set. Almost every release leaves it empty. The README recommends leaving it empty (overriding is "NOT recommended") so that the operator can "manage Postgres minor-version upgrades automatically." That doesn't actually happen: -
When a
Clusteris created with noimageNameand noimageCatalogRef, CNPG's defaulting webhook writes the operator's current default image into the spec and saves it on the resource. Fromapi/v1/cluster_defaults.go(identical inrelease-1.27andmain):// Defaulting the image name if not specified if r.Spec.ImageName == "" && r.Spec.ImageCatalogRef == nil { r.Spec.ImageName = configuration.Current.PostgresImageName } -
On later
helm upgrades,imageNameis absent from both the previous and the new rendered manifest. Helm's three-way merge therefore leaves the operator-written field untouched, and the cluster stays on its original image indefinitely. -
Upgrading the operator restarts every cluster to update the instance manager inside each pod. That restart does not change the PostgreSQL image of existing clusters.
Net effect: nothing in our current setup ever performs a PG minor upgrade. The README's "Note: If you leave this value empty, cnpg will default to the initial operator install/setup" is accurate. The recommendation above it is not.
Current inventory (2026-11-19)
| Cluster | On 17.5 | Other |
|---|---|---|
dev-k8s |
arctic, brooke, keycloak, notify, ogdc, vegbank-dev, vegbank (7) | metadig/metadig-pg on 15.6 |
prod-k8s |
arctic, demo, esa, goa, keycloak, knb, mn-ucsb-1, mn-unm-1, ogdc, opc, sdr, vegbank (12) | metadig/metadig-pg on 15.6 |
Every cluster above except metadig-pg reports spec.imageName: ghcr.io/cloudnative-pg/postgresql:17.5. That is the legacy unsuffixed tag of the system image. I believe it is Debian bookworm based; we verify this in the Prep Step.
The metadig and keycloak charts create their CNPG Cluster resources themselves, not through dataone-cnpg. Migrating them onto this chart is out of scope and can happen later. However, they have the same unpinned-image hazard, so as part of this issue they need an explicit spec.imageName in their own charts. The 15.6 → current 15.x upgrade for metadig is a follow-up.
Latent hazards in the current design
These get worse once the operator is upgraded (DataONEorg/k8s-cluster #90), because the CNPG 1.30 default image is PG 18 on Debian trixie:
- New or rebuilt clusters silently get a new major version. Any cluster created with
imageOverrideSpecempty after the operator upgrade gets PG 18. This includes the restore pathsinit.method: recoveryandsnapshot_recovery. Restoring a PG 17 snapshot onto a PG 18 image will fail. - Clearing a previously set
imageOverrideSpectriggers a major upgrade. Helm removesimageName, the webhook fills it in again with the current default, and the operator then attempts an in-place 17 → 18pg_upgradeacross a Debian release change. - Drift. Clusters created at different times run different versions, and nothing in Git records which.
Image variant and OS considerations
systemimages (which bundle Barman Cloud) are deprecated upstream and will be removed along with in-core Barman Cloud support. This chart only usesvolumeSnapshotbackups, so thestandardimage variant is the right target.- Our databases are created with
localeProvider: icu. Changing Debian release (bookworm → trixie) changes the glibc and ICU library versions. That can change collation order and require aREINDEXof text indexes. CNPG's in-placepg_upgradealso requires the same OS distribution on both sides.- Decision: stay on bookworm for the 17.x line (
17.12-standard-bookworm). - Handle the move to trixie together with a future PG 18 migration, using the chart's dump/restore import path, which rebuilds indexes anyway.
- Decision: stay on bookworm for the 17.x line (
2. Proposed pathways
Pathway A: explicit image.name per release
Every release pins its image explicitly in values (imageOverrideSpec, to be renamed image.name). The chart templates change to require an image value: the chart refuses to render without one. That way we no longer rely on the operator's default and the risks that come with it. A minor upgrade is a values change plus helm upgrade, release by release.
Pros
- Simple. No new cluster-wide resources, and it works with our current operator.
- Each release's exact version is visible in its values file in Git and is reviewable in a PR.
- Each upgrade is limited to one release. Rollout order is entirely under our control.
- Rollback is a one-line revert.
Cons
- Nineteen clusters × every minor release means a lot of manual edits and deploys, which won't happen reliably. This is how we ended up seven minors behind.
- Versions will drift between releases over time.
- Pinning by digest gets noisy to maintain by hand.
Pathway B: ClusterImageCatalog
A small number of cluster-scoped ClusterImageCatalog resources, owned by the operator installation, map major → image. Each catalog therefore decides which minor version is installed for a given PostgreSQL major version. Each release references a catalog and a major version (image.catalog). A minor upgrade is one edit to a catalog entry, and CNPG rolls it out to every cluster that references that entry. If an application needs a different image (e.g. metadig), it can create its own namespaced ImageCatalog with the versions it wants and reference it with kind: ImageCatalog.
Pros
- One change upgrades the fleet, so keeping current becomes routine. PostgreSQL minor upgrades are binary-compatible drop-in replacements and have historically been painless for us, so we expect this to be smooth. We should still read each minor release's notes for post-upgrade actions (see A.1).
- The major version is still explicit per release. Restores and new clusters land on the intended major version, never on the operator default.
- Catalogs can be split into tiers (dev/stable) for dev-first rollouts.
- Upstream publishes official catalogs pinned by digest, and CNPG's own docs say
imageCatalogRefwill eventually replaceimageNameas the default method. - The same mechanism is how we'll later move a release to PG 18 (
major: 18).
Cons
- A catalog edit affects every referencing cluster across namespaces. Problems spread, so we need tiering and rollout delays.
- Adds a cluster-scoped resource with its own ownership and change process, which belongs in the operator/infra repo, not this chart.
- The exact image each release runs is no longer visible in its values file. It's in the catalog plus cluster status.
- Migrating existing releases needs care (see B.2): CNPG rejects a Cluster that has both
imageNameandimageCatalogRefset.
Recommendation
Do the Prep Step now, then upgrade to 17.12 using Pathway A. This gets every cluster onto the current minor release as quickly as possible with the least new machinery.
Pathway B likely needs more testing than A, so we follow up by trialing it systematically on dev-k8s. If the trial goes well, we move releases onto the catalogs. If anything goes awry, the clusters stay on Pathway A pinning.
The Prep Step removes the hazards above whichever pathway we choose, and B depends on it anyway.
3. Implementation steps
Prep Step: shared prerequisites (do now, on the current CNPG 1.27 operator)
- Confirm image details.
- Confirm the Debian release behind the running
postgresql:17.5image. - Confirm the exact target tag and digest, e.g.
ghcr.io/cloudnative-pg/postgresql:17.12-standard-bookworm@sha256:….
- Confirm the Debian release behind the running
- Ship the chart changes in §4.1: explicit image value, validation, and the README fix. Release a new chart version. Catalog support can ship in the same release or later with the Pathway B trial.
- Pin every release to what it runs today.
- Set the image value to
ghcr.io/cloudnative-pg/postgresql:17.5in each release's values. That may be a standalone release or a subchart key in the metacat/etc. charts. - For keycloak and metadig, set
spec.imageNamein their own charts. - Run
helm difffirst to confirm the only change is the addition ofspec.imageName, thenhelm upgradeeach one. - Expected result: no pod restarts, because the spec value does not change, but Helm now owns
spec.imageName.
- Set the image value to
- Back up each cluster immediately before any image change, with a one-off
Backupusingmethod: volumeSnapshot. Confirm the backup's phase iscompleted.
Pathway A steps
- Read the PostgreSQL release notes for 17.6 through 17.12.
- Note any "post-upgrade" actions, such as reindexing specific index types affected by a fixed bug, and add them to the runbook.
- On one dev cluster (e.g.
vegbank-dev/vegbankdb2-cnpg), set the image to17.12-standard-bookworm@sha256:…andhelm upgrade.- CNPG replaces replicas one by one, then switches over to or restarts the primary.
- Don't change PostgreSQL parameters in the same release. With
primaryUpdateMethod: switchover, CNPG rejects simultaneous image and parameter changes.
- Verify:
kubectl cnpg status <rel>-cnpgSELECT version();- application smoke tests
- check the logs for collation-version warnings; none are expected, since the OS doesn't change
- Roll out the rest.
- Upgrade the remaining dev releases.
- Wait for an agreed soak period (e.g. one week).
- Upgrade prod one release at a time. Start with lower-traffic member nodes, and do
knb,arcticandkeycloaklast.
- Repeat for each future minor release. Optionally automate the PRs with Renovate against the image value.
Pathway B steps
- Create catalogs in the operator installation (see §4.2):
dataone-pg-bookworm-devanddataone-pg-bookworm-stable.- Each initially maps
major: 17to the exact image clusters run at that point (17.12 if Pathway A has completed).
- Each initially maps
- Switch releases from
image.nametoimage.catalog.- Set
image.catalog: {kind: ClusterImageCatalog, name: dataone-pg-bookworm-<tier>, major: 17}and clearimage.name. - Assign dev releases to
devand prod releases tostable. - The Prep Step made
spec.imageNameHelm-owned, so the three-way merge removes it in the same patch that addsspec.imageCatalogRef. - The resolved image is unchanged, so this should not trigger a rollout. Verify on one dev cluster first.
- Set
- Upgrade the dev catalog entry to the next minor release's digest. All dev clusters roll out, spaced by
CLUSTERS_ROLLOUT_DELAY. Verify as in A.3. - After the soak period, upgrade the stable catalog to the same digest and watch the prod rollouts.
- Ongoing:
- Each new PG minor release is a PR against the catalog manifests: dev first, then stable.
- A future major upgrade for a release is a values change to
major: 18. That needs an 18 entry on the same OS, or a dump/restore into a new release if we are also moving to trixie.
4. Required changes
4.1 dataone-cnpg Helm chart
-
Values: replace
imageOverrideSpecwith animageblock, and keep the old key working for one release cycle:image: ## Option A: explicit image (tag + digest recommended) name: "" # e.g. ghcr.io/cloudnative-pg/postgresql:17.12-standard-bookworm@sha256:... ## Option B: image catalog reference (mutually exclusive with image.name) catalog: {} # e.g. {kind: ClusterImageCatalog, name: dataone-pg-bookworm-stable, major: 17} -
Template (
pg_cluster.yaml):-
Resolve
image.name, falling back toimageOverrideSpec. If set, renderspec.imageName. -
If
image.catalogis set, render:imageCatalogRef: apiGroup: postgresql.cnpg.io kind: {{ .kind | default "ClusterImageCatalog" }} name: {{ .name }} major: {{ .major }} -
failif both are set. -
failif neither is set. This is what removes the "silently gets the operator default" hazard.
-
-
Optional: expose
primaryUpdateStrategy/primaryUpdateMethod, so releases can choose switchover or restart, and supervised or unsupervised, for the primary. -
Versioning: requiring an image value breaks anyone who relies on the default, so this needs a major chart version bump (2.0.0).
-
Docs and examples:
- Rewrite the README "Postgres Image Version" section: there are no automatic upgrades; explain how to pin, how catalogs work, and the bookworm/trixie collation caveat.
- Add an "Upgrading PostgreSQL" section covering minor upgrades, and major upgrades via in-place
pg_upgradevs. dump/restore import. - Update every file in
examples/to set an image explicitly. - Call out the restore hazard in the recovery sections: the restore image's major version must match the backup.
-
Testing:
helm templatecases covering name only, catalog only, both (must fail), neither (must fail), and legacyimageOverrideSpec.
4.2 CNPG operator installation (k8s-cluster repo / operator deployment)
This section only covers what the PostgreSQL image work needs. Operator version and configuration changes for the upgrade are in DataONEorg/k8s-cluster #90.
- Image catalogs (Pathway B):
- Add
ClusterImageCatalogmanifestsdataone-pg-bookworm-devanddataone-pg-bookworm-stablenext to the operator install. Give them entries formajor: 17(and18when needed), pinned by digest. - Alternatively, vendor the official
catalog-standard-bookworm.yamlfromcloudnative-pg/artifactsat a pinned commit and derive the two tiers from it. - Catalogs must not live in the per-release chart. They are cluster-scoped and would conflict across Helm releases.
- Add
- Rollout pacing (Pathway B): set
CLUSTERS_ROLLOUT_DELAY(and optionallyINSTANCES_ROLLOUT_DELAY) in the operator config (cnpg-controller-manager-config). A catalog edit then rolls clusters out one after another, not all at once. - Ownership: name an owner and a cadence for reviewing new PG minor releases. PostgreSQL ships quarterly releases plus out-of-cycle security releases. Consider Renovate or Dependabot on the catalog manifests.
Open questions for review
- Is the dev/stable split enough, or do we want a per-namespace
ImageCatalogfor releases that need to hold back?- My initial thought is that the cluster-wide catalogs are enough.
- Which releases use this chart as a subchart (metacat, …)? Each needs its values updated in the Prep Step.
- Some charts set up CNPG themselves (metadig, keycloak). They should be migrated to
dataone-cnpglater, but they still get an explicitspec.imageNamenow.
- Some charts set up CNPG themselves (metadig, keycloak). They should be migrated to
- What soak period between dev and prod? What order for prod, and in which maintenance windows?
References
- Lingua principale
- Shell
- Stelle
- 0
- Fork
- 0
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di DataONEorg/dataone-cnpg
-
bug: CNPG instance manager trying to update credentials for non-existent `app` userForse di nuovo libera @artntek l’ha presa 246 giorni fa e non c’è nessuna pull request aperta. Apertabug
DataONEorg/dataone-cnpg#10 · 2 commenti · 1 assegnatario ·
Tutte le issue di DataONEorg/dataone-cnpg
Issue simili
-
bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 90/100
zeabur-oss/builder#304 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation security
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
maiychrus25/OpenTea-DX-OS#221 ·
-
ci severity: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
TMHSDigital/Spackle#205 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 1/5 1-3 ore Idoneità per principianti 92/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
obra/superpowers#2766 ·
I maintainer di solito rispondono entro 1 giorno