Skip to content

chore(deps): PostgreSQL 18 for CloudNativePG clusters, copied first - #217

Open
Yoshiofthewire wants to merge 5 commits into
chore/postgres-18from
chore/postgres-18-cnpg
Open

Yoshiofthewire wants to merge 5 commits into
chore/postgres-18from
chore/postgres-18-cnpg

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: An existing highly available KyIdentity database (a CloudNativePG Cluster on PostgreSQL 17) moves to 18 on the next apply. Every instance's claim is copied and verified first, and the copies are never deleted or replaced. If anything fails once the Cluster is stopped, it starts again on 17. Fresh Clusters start on 18.

What changed

  • A new step kyidentity.database-upgrade runs before deploy:
    1. It creates a pre-upgrade-pg17-<claim>-<UTC yyyymmdd-hhmmss> copy claim per Cluster data claim. Every attempt makes its own set. A separate WAL or tablespace claim, which the installer never makes, refuses before anything stops.
    2. Storage check: one copy pod per instance starts once on that instance's node while the Cluster still runs. If the storage refuses or cannot provide the copies, nothing is stopped, and the message names the earlier copies taking space.
    3. It hibernates the Cluster, then copies and verifies each claim as uid 26, one pod per instance.
    4. It re-reads the Cluster (same uid, still hibernated on 17). One patch then sets postgresql:18.7-minimal-trixie@sha256:c8caac98…88cc and wakes it, so CloudNativePG runs pg_upgrade --link.
    5. It waits until the Cluster is healthy, then runs vacuumdb --analyze-only --missing-stats-only.
  • Conflict fix (CI run 45719982937): Cluster patches no longer carry a resourceVersion. The operator writes the Cluster's status all the time, so the old image switch was refused with "the object has been modified". The switch and the wake carry the Cluster's metadata.uid instead, so the API server refuses them on a Cluster recreated since.
  • Failure path: anything that fails after the hibernation is requested gets one patch: hibernation off and the 17 image. This includes a copy, the "verified" mark, a refused switch, and a hibernation whose answer was lost. If that wake fails too, the error says what to set by hand.
  • A switch whose answer is lost is never rolled back blindly (Guide, 949e81a). Apply re-reads the Cluster. If the 18 image is set, the upgrade is under way, and the normal wait takes over (its rollback checks the data major first). If the Cluster cannot be read, apply writes nothing and says how to check.
  • No WAL claims (Guide, 0bf19ae). With walStorage, pgdata/pg_wal is a link to a mount the copy pod lacks, so verification could never pass. The installer's Cluster spec sets no walStorage, so such a claim is now refused up front instead of stopping sign-in for a copy that must fail.
  • Copy roles as the Cluster stopped (Guide, 949e81a). After the instances are gone, the claims are listed again, a changed set refuses, and each copy's instance-role comes from that list. A failover during the storage check can no longer label a stale standby "primary" for the rollback. An upgrade still on 17 data after 15 min gets the 17 image back, which is CloudNativePG's documented rollback.
  • Copies: none is deleted or replaced by the installer. Apply's note and every error list all of this Cluster's copies (verified or not) with the kubectl delete pvc command.
  • Deploy's applyCluster refuses any major change by itself. Docs: "PostgreSQL 17 to 18" and "Going back to PostgreSQL 17" in docs/guided-setup.md. The plan gains list on persistentvolumeclaims. New e2e shard kube-cluster-upgrade.

Review this

Checked (at c728a71, which contains chore/postgres-18 02e5c57)

  • make ci exit 0 on k81 at c728a71: notes, tidy, gofmt, vet including e2e tags, and go test -race ./.... It also passed at 0bf19ae, 949e81a and 147c997.
  • GitHub CI at 949e81a, 0bf19ae and c728a71: every job green, including e2e (kube-cluster-upgrade) on real CloudNativePG (upgrade 5m32s, documented rollback 58s), the PostgreSQL 17-to-18 job and documentation (mdbook). The security reviewer cleared each head; the Guide reports no major issues at c728a71.
  • docs/check-links.py passes: 283 links. mdbook build is left to this PR's documentation workflow (the local run was still waiting for a slot).
  • 14 fake-client tests (plus subtests). The fixture's operator writes the Cluster after every read, so any write carrying a read resourceVersion conflicts, as on a real server. All 13 new mutations fail (Detail). Two of them reproduce CI's exact error.
  • On c1c9811, the CI run already exercised the old wake path on real CNPG: after the refused switch the Cluster was back on 17.12, hibernation: off, 3/3 ready.

Not checked

  • The e2e cannot run on Major (kind's kube-proxy hits the host's inotify limit). It ran only in GitHub CI, green at every head since 949e81a. The e2e does not take the lost-answer, failover or WAL-refusal paths: those are proven by the unit tests only.
  • The failure path is not in the e2e. Breaking a copy after hibernation on kind is not cheap or reliable, so it is covered only by the unit tests and by the incidental CI evidence above.

Decided for you

  • The storage check is not a guarantee. It proves the storage provisions each copy at its full size before sign-in stops. Thin or node-local storage (local-path, kind's standard) can still fill up during the copy. That copy then fails, and the Cluster wakes on 17 (sign-in down for that attempt only). A real free-space check is not reliably knowable across storage classes.
  • The storage-check pod mounts each instance's claims read-only beside the running instance, on its node, as the single-pod pre-upgrade copy already does.
  • A Cluster with a separate WAL claim (walStorage, set by hand, never by the installer) cannot be upgraded by the installer. A symlink-aware copier would need its own real-filesystem proof.
  • A copy left by a failed attempt stays (unverified) beside the new one. It is never reused, so disk use grows per failed attempt. The refusal message names those copies so you can delete them.
  • Major upgrades need CloudNativePG 1.26 or later. An ANALYZE failure is reported, not fatal.

You need to: merge after #216, once CI, the security reviewer and the Guide are clean. I merged #216's branch at 02e5c57 (kit v4) into this PR after garganey's hand-off, because GitHub runs no CI on a conflicting PR. The conflicts were in AGENTS.md and CHANGELOG.md only, and it was a merge, not a rebase. If #216 moves again, merge it again.

Detail

Mutations of this change (each alone, go test -run ClusterUpgrade ./internal/kube/):

Mutation Fails
hibernate patch carries resourceVersion TestClusterUpgrade, CopyFailure, FailsAfterHibernation, OperatorRefuses, Rollback (CI's "object has been modified")
switch patch carries the stale resourceVersion (the c1c9811 code) TestClusterUpgrade, CopyFailure, Rollback, ForeignCopy
wake defer registered after the hibernation FailsAfterHibernation/hibernation_answer_lost
wake does not set the 17 image FailsAfterHibernation/switch_answer_lost (Cluster left on 18)
copy names without the attempt stamp CopyFailure (AlreadyExists on retry), StorageCheckRefused
no storage check TestClusterUpgrade (sequence), StorageCheckRefused
storage check not pinned to the instance's node TestClusterUpgrade, StorageCheckRefused
no uid check / no state check before switch ClusterChangedDuringCopy/recreated, /image
a landed switch treated as failed (17 set back) SwitchAnswerLost/landed
a switch of unknown state woken on 17 anyway SwitchAnswerLost/unknown
copy roles from the list taken before the stop FailoverBeforeStop
a WAL claim accepted again WALClaimRefused

gannet's 8 earlier mutations still apply to the unchanged guards. The "foreign copy overwritten" one is moot now: names are unique per attempt, and a foreign copy is asserted untouched and absent from the note.

Images: 18 operand ghcr.io/cloudnative-pg/postgresql:18.7-minimal-trixie@sha256:c8caac9817d2b5e5e66297a3ccf86d9fcbd68f097aa6cc00161d83f9635e88cc (the index digest, trixie as for 17.12).

CloudNativePG facts relied on (release-1.30 source):

  • The major upgrade compares spec.imageName's tag major with status.pgDataImageInfo.majorVersion, and runs once the Cluster is awake.
  • On success it deletes the replicas' claims.
  • Reverting the image deletes the job.
  • A new Cluster adopts claims labelled cnpg.io/cluster that have no owner (reconcileRestoredCluster).
  • Claim roles come from cnpg.io/pvcRole.

🤖 Generated with Claude Code

A Cluster an earlier release made runs PostgreSQL 17. The new step
kyidentity.database-upgrade (before deploy) moves it as the owner
decided on 2026-11-25:

- create a pre-upgrade-pg17-<claim> copy claim for every claim the
  Cluster owns (a refused claim stops nothing);
- hibernate the Cluster, copy and verify each claim as uid 26, one pod
  per instance, with the existing claim copier;
- one patch sets the 18.7-minimal-trixie image and wakes the Cluster, so
  CloudNativePG runs its in-place pg_upgrade --link;
- wait until it is healthy, then vacuumdb --analyze-only
  --missing-stats-only.

A failed copy, or an operator that refuses the image, wakes the Cluster
on 17 unchanged. An upgrade still on 17 data after the timeout gets the
17 image back, which is CloudNativePG's documented rollback. Deploy
refuses any major change by itself. Copies are never deleted, and a
same-named copy of another Cluster is refused. Fresh Clusters start on
18. docs/guided-setup.md documents going back to 17 from the primary's
copy; the new e2e shard kube-cluster-upgrade runs it on kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyquickstart-217, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

Yoshiofthewire and others added 3 commits November 25, 2026 19:14
The image switch carried the resourceVersion read before the copy, and the
operator writes the Cluster's status in the meantime, so a real API server
refused it (CI e2e kube-cluster-upgrade, run 45719982937). Cluster patches
now carry no resourceVersion; the switch re-reads the Cluster first, and
both the switch and the wake name its uid.

Anything that fails once the hibernation is requested (its answer lost
included) wakes the Cluster in one patch on its old image. Each attempt
makes its own timestamped copies; none is replaced or deleted. Each
instance's copy pod starts once on its node before hibernating, so storage
that cannot provide the copies is refused while sign-in still works, naming
the earlier copies that take space.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-18-cnpg

Conflicts in AGENTS.md and CHANGELOG.md only: kept #216's rollback text and
#217's CloudNativePG entries, and dropped "CloudNativePG clusters stay on 17".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…topped

PR Reviewer Guide at 949e81a:
- An image switch that landed with its answer lost had already woken the
  Cluster, and the deferred wake set 17 back while CloudNativePG might be
  upgrading. Re-read it: with the new image set, leave it to the wait (whose
  rollback checks the data major first); if it cannot be read, report how
  to check and write nothing.
- Copies took instance-role from the claims listed before the storage
  check, so a failover before the stop labelled a stale standby primary.
  Re-list the claims once the instances are gone, refuse a changed set,
  and record the roles as stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Both Guide findings at 949e81a are fixed in 0bf19ae; each has a test that fails without the fix.

  • Unsafe rollback: after a switch error, copyAndSwitch re-reads the Cluster. If the 18 image is set (same uid), it does not wake on 17. The normal wait takes over, and its rollback only sets 17 back while status.pgDataImageInfo still records 17 data. If the Cluster cannot be read, nothing more is written, and the error says how to check imageName. Tests: TestClusterUpgradeSwitchAnswerLost/landed and /unknown. Mutating either guard fails its subtest.
  • Stale primary: once the instances are gone, the claims are listed again. A changed claim set refuses (and wakes on 17). Each copy's kyquickstart/instance-role is written from that list when the copy is marked verified. Test: TestClusterUpgradeFailoverBeforeStop moves the primary during the storage check. Taking the roles from the first list fails it.

The earlier "Stale resourceVersion" finding (c1c9811) was fixed in 147c997: Cluster patches carry no resourceVersion. The switch re-reads the Cluster, and the switch and the wake carry metadata.uid. CI's e2e (kube-cluster-upgrade) passed at 949e81a.

PR Reviewer Guide at 0bf19ae: with walStorage, pgdata/pg_wal is a link to
CloudNativePG's WAL mount, which the copy pod does not mount, so the copy's
diff -r cannot verify it and every upgrade would stop sign-in, then wake on
17. The installer's Cluster spec never sets walStorage, so a WAL claim is
refused like a tablespace's: before the claims are made or the Cluster is
stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

WAL Copies (0bf19ae): fixed in c728a71 by refusing such Clusters, not by copying them.

  • The installer's Cluster spec never sets walStorage (internal/kube/dbcluster.go, only storage), so a Cluster it made has no PG_WAL claim.
  • A PG_WAL claim is now refused in clusterClaims, as a tablespace's already was: before any copy claim is made and before hibernation. Sign-in is never stopped for a copy that cannot verify.
  • Test: TestClusterUpgradeWALClaimRefused asserts no events, no copies and the 17 image. Accepting PG_WAL again fails it.
  • The docs no longer describe WAL copies.

I did not make copyCommand symlink-aware: it is shared with every app's pre-upgrade copy, and the change would need its own real-filesystem proof for a layout the installer never creates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant