Skip to content

fix(sidecar): serve backups while the cluster bootstraps - #286

Open
armru wants to merge 3 commits into
mainfrom
dev/268
Open

armru wants to merge 3 commits into
mainfrom
dev/268

Conversation

@armru

@armru armru commented Sep 16, 2026

Copy link
Copy Markdown
Member

Problem

When a cluster bootstraps from a Klio backup, the operator injected a
dedicated restore sidecar (klio cnpgi restore) whose CNPG-I identity only
advertised the restore and WAL services. Once recovery completed, the
lifecycle hook swapped it for klio-plugin, which also advertises backup.
A backup requested in between, which is what happens with a replica cluster
and an immediate backup, was rejected by CNPG with
plugin does not support Backup service.

Fix

One sidecar, klio-plugin, serves every phase. It advertises restore,
backup and WAL from the start, and each service already picks its
repository configuration per request from the cluster definition. The
operator now selects which configuration the sidecar is started with
(archive, recovery source, or replica source) instead of choosing a
different container. The bootstrap pod spec equals the steady-state spec,
so recovery no longer causes a rollout, and a backup arriving during
bootstrap is served.

Consequences:

  • klio cnpgi restore is removed; nothing injects it any more.
  • A klio-restore entry in PluginConfiguration.spec.containers is still
    accepted but ignored, and documented as deprecated. klio-plugin is the
    only container to customise.

A second commit makes the sidecar config watcher hash the whole config
mount rather than the file behind --config, so a rotated recovery or
replica source Secret also restarts the sidecar.

Testing

  • Unit tests for the new configuration selection and the directory
    watcher; the selection tests fail on main.
  • BackupFromReplicaCluster e2e now requests the backup immediately after
    creating the replica cluster and asserts the bootstrapping pod is never
    recreated. It fails deterministically on main and passes with this
    change.

Closes #268

A cluster bootstrapping from a Klio backup received a dedicated
`klio-restore` sidecar that only advertised the restore and WAL
capabilities, later swapped for `klio-plugin` by a rollout once the
primary was elected. CloudNativePG dispatches a backup as soon as the
instance is ready, which lands in that window: the plugin client
rejects it with "plugin does not support Backup service". A replica
cluster created together with an immediate ScheduledBackup hit this
every time.

Inject the same `klio-plugin` sidecar in every phase and give the
`cnpgi instance` server the restore capability too. The restore hook
and the WAL service already pick their repository per request from
the cluster definition, so nothing needs swapping once recovery
completes, and the pod spec no longer changes after bootstrap. The
`cnpgi restore` command goes away; a `klio-restore` entry in
`PluginConfiguration.spec.containers` is still accepted but ignored.

The replica-cluster e2e now requests the backup right after creating
the cluster, before its bootstrap completes.

Closes #268

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
The config watcher only hashed the file behind --config, which is the
archive configuration once a cluster has one. The restore and WAL
services read the recovery source and replica source configurations
from sibling files in the same projected Secret mount, so a rotation of
one of those Secrets went unnoticed until the next unrelated restart.

Watch the whole mount directory instead. Every regular file is hashed
together with its name, symlinks are followed so the kubelet layout of
a projected volume is handled, and its internal directories are
skipped.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Nothing injects a `klio-restore` container any more: the `klio-plugin`
sidecar serves the restore hooks as well. Keeping the name in the CRD only
let a `PluginConfiguration` carry an entry the operator silently ignored.

Accept `klio-plugin` alone in `spec.containers`, and document in the
upgrade notes that a leftover `klio-restore` entry must be removed before
upgrading.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
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.

No backup capability on immediate backup from replica cluster

1 participant