Repository navigation
fix: delegate in-tree barman WAL recovery to the instance manager - #11105
Conversation
|
/test |
|
❗ By default, the pull request is configured to backport to all release branches.
|
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/28462334338 |
c73f5cd to
4a3ee3e
Compare
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/28517284216 |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/28545286679 |
5d13aa4 to
ec4c215
Compare
|
/test |
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/28652592859 |
e99a78b to
a8ff3a3
Compare
|
/test |
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/28877370006 |
In-tree barman recovery set `restore_command` to a direct `barman-cloud-wal-restore` invocation, embedding the recovery source object store options into the command line. Route it through `/controller/manager wal-restore` instead, the same command HA replicas and CNPG-I plugin restores already use, so the object store details and credentials no longer end up in the restore command. The bootstrap recovery Job runs the local webserver but not the instance reconciler that normally fills the wal-restore cache, and the recovery source store cannot always be derived from the cluster spec: for a recovery.backup reference it lives only in the referenced Backup CR. The Job therefore resolves the source store and credentials while it has them and stores them in the cache, where the wal-restore command picks them up. The lookup is gated on a cluster that has not elected a primary yet, so a running instance's WAL restore path is untouched. For a recovery.source the source store's Wal configuration is honored to match the Barman Cloud plugin: the prefetch parallelism and the additional barman-cloud-wal-restore command-line arguments are taken from the external cluster's barmanObjectStore. A recovery.backup reference records no such configuration, so it restores one segment at a time. Signed-off-by: Armando Ruocco <[email protected]>
A replica cluster configures streaming replication in concludeRestore and returns before starting PostgreSQL in the recovery Job, so the wal-restore command is never invoked there and the cache that setupBootstrapWALRestoreCache populated was never read. Skip populating it for replica clusters. Signed-off-by: Armando Ruocco <[email protected]>
The bootstrap recovery Job cached the barman-cloud-wal-restore options as a []string while the wal-restore command read the prefetch parallelism from the cluster spec separately, so the source Wal settings were resolved in two places. Cache the resolved source object store configuration instead, so wal-restore derives both the options and the parallelism from a single object, exactly as it does for a running instance and as the Barman Cloud plugin does from its ObjectStore resource. This removes bootstrapMaxParallel and unifies the bootstrap and normal resolution through one helper. It is behavior-preserving. Signed-off-by: Armando Ruocco <[email protected]>
The recovery Job skipped populating the WAL-restore cache for replica clusters because PostgreSQL never replays WAL in that Job: the restore concludes by configuring streaming replication before any recovery start, so the cached values are never read there. That skip only saved two in-memory writes, while tying the cache setup to the exact control flow of concludeRestore: it had to be re-proven correct any time the replica bootstrap sequence changed. Populating the cache unconditionally is simpler and harmless, since an unread cache entry costs nothing and dies with the Job process. Signed-off-by: Armando Ruocco <[email protected]>
The same five-field mapping from a Backup status back to a barman object store configuration appeared in three places in restore.go. Extract it into a helper so the copies cannot drift apart. Signed-off-by: Armando Ruocco <[email protected]>
The unit tests for the wal-restore settings use a fake cache client, so they never exercise the JSON serialization of the recovery source store between the Job webserver and the wal-restore command. Add a test that serves a fully populated store through serveCache and decodes it the same way the local cache client does. Signed-off-by: Armando Ruocco <[email protected]>
When resolving the bootstrap-cached recovery source object store, getWALRestoreSettings treated any error from the cache lookup as "nothing cached yet" and fell through to GetRecoverConfiguration. That fallback resolves the object store from the cluster's own spec.backup.barmanObjectStore, which is unrelated to the recovery source. On a cluster that configures both a recovery source and its own backup destination, a genuine cache error could therefore make recovery restore WALs from the wrong (and possibly empty) store, promoting early and silently losing data with no error surfaced. Only a real cache miss now falls back; any other error aborts the WAL restore so the failure is visible instead of silently changing the recovery source. Signed-off-by: Marco Nenciarini <[email protected]>
…path Now that getRestoreWalConfig returns a path-independent constant, createEnvAndConfigForSnapshotRestore no longer needs to compute and return a config string: it always returned exactly what the caller already had. Return only the environment and let RestoreSnapshot obtain the config from getRestoreWalConfig directly. Signed-off-by: Marco Nenciarini <[email protected]>
Now that both recovery sources terminate in concludeRestore with a config string and an environment, extract the plugin and Barman Cloud object-store branches of Restore into restoreViaPlugin and restoreViaBarmanObjectStore, each returning that pair. Restore becomes a small dispatch on the recovery source, removing the deeply nested if/else that required a nestif lint exception. Signed-off-by: Marco Nenciarini <[email protected]>
The bootstrap ServerName argument restated the field it falls back from, which reads as a bug on a quick look; it isn't, since the field is always populated for a cached recovery source. Note why instead. The function doc comment and the first inline comment in its body also repeated the same bootstrap-cache explanation almost verbatim. Keep the doc comment focused on what the function returns and point to the gate below for the why. Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
a8ff3a3 to
e30a0e3
Compare
|
/test |
|
@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/31476720139 |
…1105) In-tree barman recovery used to set `restore_command` to a direct `barman-cloud-wal-restore` invocation, embedding the recovery source object store options and credentials on the command line. It now goes through `/controller/manager wal-restore` instead, the same path HA replicas and CNPG-I plugin restores already use, so object store details and credentials no longer appear in the restore command. Also fixes a bug where any cache lookup error (not just a real cache miss) fell back to the cluster's own backup destination, which on a cluster configuring both a recovery source and its own backup could silently restore WALs from the wrong store. Closes #3459 Assisted-by: Claude Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit e997aa0)
…1105) In-tree barman recovery used to set `restore_command` to a direct `barman-cloud-wal-restore` invocation, embedding the recovery source object store options and credentials on the command line. It now goes through `/controller/manager wal-restore` instead, the same path HA replicas and CNPG-I plugin restores already use, so object store details and credentials no longer appear in the restore command. Also fixes a bug where any cache lookup error (not just a real cache miss) fell back to the cluster's own backup destination, which on a cluster configuring both a recovery source and its own backup could silently restore WALs from the wrong store. Closes #3459 Assisted-by: Claude Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit e997aa0)
…1105) In-tree barman recovery used to set `restore_command` to a direct `barman-cloud-wal-restore` invocation, embedding the recovery source object store options and credentials on the command line. It now goes through `/controller/manager wal-restore` instead, the same path HA replicas and CNPG-I plugin restores already use, so object store details and credentials no longer appear in the restore command. Also fixes a bug where any cache lookup error (not just a real cache miss) fell back to the cluster's own backup destination, which on a cluster configuring both a recovery source and its own backup could silently restore WALs from the wrong store. Closes #3459 Assisted-by: Claude Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit e997aa0)
##### [\`v1.30.1\`](https://github.com/cloudnative-pg/cloudnative-pg/releases/tag/v1.30.1) **Release date:** Sep 23, 2026 ##### Enhancements - Added `restoreAdditionalCommandArgs` to `.barmanObjectStore.data` for in-tree Barman Cloud recoveries, so custom flags are forwarded to `barman-cloud-restore` during recovery. ([#11278](cloudnative-pg/cloudnative-pg#11278)) <!-- 1.29 1.28 --> - Plugin authors no longer need to re-derive whether an empty WAL archive should be treated as an error: the operator now computes the `check_empty_wal_archive` decision once and passes it to CNPG-I plugins on both WAL archiving and restore hooks. ([#11216](cloudnative-pg/cloudnative-pg#11216)) <!-- 1.29 1.28 --> - Allowed setting the `ssl_ecdh_curve` PostgreSQL parameter in `.spec.postgresql.parameters`. It was previously rejected by the validating webhook even though the operator does not manage it. Contributed by [@Jamstah](https://github.com/Jamstah). ([#11308](cloudnative-pg/cloudnative-pg#11308)) <!-- 1.29 1.28 --> - Added support for setting `auth_user` in `spec.pgbouncer.parameters` to override the user PgBouncer uses for its `auth_query` connection, instead of always deriving it from the `authQuerySecret`. Useful with a custom `authQuerySecret` where the role to authenticate as differs from the one implied by the Secret. Contributed by [@jonasbadstuebner](https://github.com/jonasbadstuebner). ([#10899](cloudnative-pg/cloudnative-pg#10899)) <!-- 1.29 1.28 --> - Fixed PgBouncer metrics silently reporting zero when PgBouncer adds or reorders columns: `SHOW STATS` and `SHOW POOLS` results are now matched by column name instead of by position. Contributed by [@AdzerKI](https://github.com/AdzerKI) (`SHOW STATS`). ([#11366](cloudnative-pg/cloudnative-pg#11366), [#11464](cloudnative-pg/cloudnative-pg#11464)) <!-- 1.29 1.28 --> - `cnpg` plugin: - Added a `--dry-run` option to the `backup` command that prints the `Backup` resource that would be created, without creating it. ([#11233](cloudnative-pg/cloudnative-pg#11233)) <!-- 1.29 1.28 --> ##### Security and Supply Chain - Fixed a webhook validation bypass where an absolute extension path with an embedded `..` traversal (e.g. `/a/../../../../etc`) was accepted because only the raw path was checked; such paths still escaped the extension's mount point once resolved at runtime. Affected entries are now resolved and rejected/skipped consistently across admission, the major-upgrade job, and already-persisted Cluster specs. Contributed by [@Anand-240](https://github.com/Anand-240). ([#11210](cloudnative-pg/cloudnative-pg#11210)) <!-- 1.29 1.28 --> - Updated `google.golang.org/grpc` to v1.83.1, fixing [CVE-2026-84304](https://nvd.nist.gov/vuln/detail/CVE-2026-84304) / GHSA-vp52-pcj8-j9qc (gRPC-Go heap memory exhaustion via HTTP/2 DATA frame fragmentation). ([#11394](cloudnative-pg/cloudnative-pg#11394)) <!-- 1.29 1.28 --> ##### Changes - Updated the default PostgreSQL operand image to 18.6-system-trixie. ([#11257](cloudnative-pg/cloudnative-pg#11257)) <!-- 1.29 1.28 --> - Moved the operator's own base image from Debian 12 (bookworm) to Debian 13 (trixie), now that Debian 12 has moved to LTS-only maintenance. ([#11193](cloudnative-pg/cloudnative-pg#11193)) <!-- 1.29 1.28 --> ##### Fixes - Demoted an unreachable old primary immediately during failover, instead of waiting on checkpoint and fast-shutdown attempts that could never complete. Previously, an old primary whose PostgreSQL had become unresponsive was never shut down, so it could never rejoin the cluster as a replica of the new primary. The shutdown is now requested without blocking the reconciler, though demotion can still take up to a minute or more if PostgreSQL keeps ignoring shutdown signals. ([#11347](cloudnative-pg/cloudnative-pg#11347)) <!-- 1.29 1.28 --> - Fixed failover and Pod recreation getting stuck while any instance in the cluster was fenced. A fenced instance kept reporting itself as healthy on its status endpoint even though its Pod was permanently not Ready, which blocked the readiness guard, the primary-election logic, and the Pod-reattachment gate from reacting to an unrelated failure elsewhere in the cluster, leaving it stalled until someone manually removed the fencing. All three now recognize and skip fenced instances. ([#11274](cloudnative-pg/cloudnative-pg#11274)) <!-- 1.29 1.28 --> - Fixed a failover that could stall forever or get silently reverted. While a failover was pending, the reconciler could skip checking whether it was ready to complete, or mistake the pending state for a missing Pod and reset the target primary back to the unhealthy one. It now keeps progressing a pending failover and completes it once the WAL receivers are down, rechecking quorum safety right before promoting in case it changed while waiting. ([#11336](cloudnative-pg/cloudnative-pg#11336)) <!-- 1.29 1.28 --> - Fixed the designated-primary sort in `PostgresqlStatusList` so a tie on LSN no longer sorts it out of order. If the designated primary's Pod later disappeared from the status list, this could have led the operator to promote the wrong standby. ([#11494](cloudnative-pg/cloudnative-pg#11494)) <!-- 1.29 1.28 --> - Gated PostgreSQL startup on the instance manager actually holding the primary `Lease`, closing a window where a restarting or rescheduled primary could start accepting writes before acquiring the lease. Lease acquisition now happens during instance initialization, strictly before PostgreSQL is allowed to start, instead of only later in the reconciliation loop once the instance was already reported ready. ([#11356](cloudnative-pg/cloudnative-pg#11356)) - Bounded the primary lease take-over `Get` call to the lease's `RenewDeadline`, so a call against an unreachable API server now fails fast and retries instead of blocking indefinitely. Left unbounded, the same stalled call could also delay a primary's own lease renewal after a transient API server blip, risking an unwanted takeover by another instance once the lease appeared to expire. ([#11350](cloudnative-pg/cloudnative-pg#11350)) - Stopped abandoning a fast shutdown after 60 seconds. The request carried no explicit timeout, so `pg_ctl` fell back to its own implicit 60-second limit, and the instance manager, being PID 1 in the container, took PostgreSQL down mid-shutdown regardless of a larger configured `stopDelay`. The fast phase now waits for the full `stopDelay` instead. ([#11263](cloudnative-pg/cloudnative-pg#11263)) <!-- 1.29 1.28 --> - Waited for certificate status before refreshing secrets during bootstrap. ([#11450](cloudnative-pg/cloudnative-pg#11450)) <!-- 1.29 1.28 --> - Fixed in-tree Barman Cloud recovery ignoring `wal.maxParallel` and `wal.restoreAdditionalCommandArgs`, fetching WAL one segment at a time instead of using the configured parallelism. ([#11105](cloudnative-pg/cloudnative-pg#11105)) <!-- 1.29 1.28 --> - Honored the `unrecoverable` annotation on pending and terminating instances. ([#11241](cloudnative-pg/cloudnative-pg#11241)) <!-- 1.29 1.28 --> - Honored `Backup.spec.online` when finalizing VolumeSnapshot-based backups, so a cold backup is no longer reported as online in status. ([#11276](cloudnative-pg/cloudnative-pg#11276)) <!-- 1.29 1.28 --> - Set `--no-data-checksums` explicitly when `.spec.postgresql.dataChecksums` is `false` on PostgreSQL 18+, which now enables checksums by default in `initdb`. Contributed by [@evan314159](https://github.com/evan314159). ([#11488](cloudnative-pg/cloudnative-pg#11488)) <!-- 1.29 1.28 --> - Stopped discarding `.spec.inheritedMetadata` labels on PVC reconciliation; they were applied before, and then overwritten by, the operator's own labels. Contributed by [@GellertBabel](https://github.com/GellertBabel). ([#11499](cloudnative-pg/cloudnative-pg#11499)) <!-- 1.29 1.28 --> - Stopped `Pooler` and `DatabaseRole` from recreating their owned resources after being marked for deletion, which could block an external finalizer (e.g. ArgoCD foreground deletion) waiting for those resources to disappear. Contributed by [@mjlshen](https://github.com/mjlshen). ([#11359](cloudnative-pg/cloudnative-pg#11359)) <!-- 1.29 1.28 --> - Handled a `NULL` `stats_reset` value in the `pg_stat_wal` metric, which could occasionally break Prometheus scraping on PostgreSQL 18 clusters. Contributed by [@HoniSanders](https://github.com/HoniSanders). ([#11207](cloudnative-pg/cloudnative-pg#11207)) <!-- 1.29 1.28 --> - Recovered log streaming when a stale non-FIFO file blocked the log pipe. ([#11246](cloudnative-pg/cloudnative-pg#11246)) <!-- 1.29 1.28 --> - Stopped sampling logs of the Pods' processes, so no log lines are silently dropped. ([#11131](cloudnative-pg/cloudnative-pg#11131)) <!-- 1.29 1.28 --> - Stopped caching Helm release Secrets in the operator, which could spike memory usage and crashloop the operator on clusters with large Helm releases installed alongside it. ([#11211](cloudnative-pg/cloudnative-pg#11211)) <!-- 1.29 1.28 --> - Re-ran owned-resource finalizer cleanup after an operator restart, so a namespace deleted while the operator was down doesn't hang in `Terminating` forever. ([#11215](cloudnative-pg/cloudnative-pg#11215)) <!-- 1.29 1.28 --> - Fixed rejoining replicas taking a long time to complete `pg_rewind` when WAL prefetching (`wal.maxParallel > 1`) was enabled. ([#11204](cloudnative-pg/cloudnative-pg#11204)) <!-- 1.29 1.28 --> - Treated a PostgreSQL instance rejecting connections as started up in probes. ([#11152](cloudnative-pg/cloudnative-pg#11152)) <!-- 1.29 1.28 --> - Stopped issuing a redundant PATCH on every reconciliation when a cluster's `pvcTemplate` set `volumeAttributesClass`. Contributed by [@andrew-farries](https://github.com/andrew-farries). ([#11196](cloudnative-pg/cloudnative-pg#11196)) <!-- 1.29 1.28 --> - Stopped halting replication slot reconciliation at the first failing slot. ([#11119](cloudnative-pg/cloudnative-pg#11119)) <!-- 1.29 1.28 --> - During rollouts, compared the running configuration hash, rather than the on-disk one, avoiding unnecessary switchovers. ([#11130](cloudnative-pg/cloudnative-pg#11130)) <!-- 1.29 1.28 --> - Retried `VolumeSnapshot` errors until the deadline, instead of giving up early. ([#11132](cloudnative-pg/cloudnative-pg#11132)) <!-- 1.29 1.28 --> - Symlinked `pg_wal` to the WAL volume during plugin-based recovery, instead of replaying WAL onto the data volume, which could exhaust it on a large point-in-time recovery. ([#11127](cloudnative-pg/cloudnative-pg#11127)) <!-- 1.29 1.28 --> - Corrected grammar in `PhaseUpgradeDelayed` status messages. Contributed by [@Utkarsh-sharma47](https://github.com/Utkarsh-sharma47). ([#11065](cloudnative-pg/cloudnative-pg#11065)) <!-- 1.29 1.28 --> - CloudNativePG Interface (CNPG-I): - Reported the Postgres capabilities of a plugin correctly. ([#11447](cloudnative-pg/cloudnative-pg#11447)) <!-- 1.29 1.28 --> - Prevented the plugin status field from flapping on Cluster reconciliation. Contributed by [@sharifmshaker](https://github.com/sharifmshaker). ([#11386](cloudnative-pg/cloudnative-pg#11386)) <!-- 1.29 1.28 --> - Replaced a finalizer with in-memory cleanup on Service deletion. This avoids namespaces hanging in `Terminating` state when the operator and its plugins run in the same namespace. Contributed by [@maxlengdell](https://github.com/maxlengdell). ([#10940](cloudnative-pg/cloudnative-pg#10940)) <!-- 1.29 --> - `cnpg` plugin: - Used UTC time zone for the default backup name. ([#11329](cloudnative-pg/cloudnative-pg#11329)) <!-- 1.29 1.28 --> - Deleted PVCs before Pods in `cnpg destroy`, avoiding a race that could leave dangling PVCs needing a second invocation to clean up. Contributed by [@daanvinken](https://github.com/daanvinken). ([#10847](cloudnative-pg/cloudnative-pg#10847)) <!-- 1.29 1.28 -->
wal.maxParallelandwal.restoreAdditionalCommandArgswere silently ignored during abootstrap.recoveryfrom a Barman Cloud object store: the recovery Job composedrestore_commanddirectly, fetching one WAL at a time regardless of the configured parallelism. Recovery of large clusters could therefore take hours, even though the documentation states these settings apply to the recovery phase and running replicas already honor them.The recovery Job now sets
restore_commandto/controller/manager wal-restore, the same command HA replicas, volume snapshot recovery, and CNPG-I plugin restores already use. Recovery from arecovery.sourcepicks up the source'swal.maxParallel(parallel WAL prefetch during the replay) andwal.restoreAdditionalCommandArgs, matching the Barman Cloud plugin. Arecovery.backupreference records no WAL configuration, so it still restores one segment at a time.The recovery Job is the only component that can resolve the recovery source object store (for a
recovery.backupreference the store lives only in the referenced Backup resource), so it pre-populates the local webserver cache with the resolved store configuration and credentials. When no primary has been elected yet,wal-restorereads its options, credentials, and prefetch parallelism from that cached store; in every other situation it behaves as before.Two further consequences of routing through the shared command:
restore_commandno longer embeds any user-controlled field, removing the need for shell quoting in the recovery configuration, and WAL restore logs during the bootstrap replay are now structured and routed like on running instances.The serialization of the recovery source store between the Job webserver and the wal-restore command is covered by a dedicated unit test, and the object-store recovery end-to-end tests (recovery from an external cluster, PITR, and replica cluster recovery, plus recovery from a Backup resource) pass against this change.
Closes #3459