Barman-Cloud Sidecar Retention Policy#
The barman-cloud sidecar runs a continuous polling loop — CatalogMaintenanceRunnable — that periodically enforces backup retention policies, reconciles Kubernetes Backup objects against the barman catalog, and updates the cluster's first recoverability point.
How the Loop Works#
CatalogMaintenanceRunnable.Start runs a for loop that:
- Calls
cycle()to enforce retention and get the next wait interval. - Waits for that interval (via
time.After) or forctx.Done()— whichever fires first. - Returns
nilwhen the context is cancelled (SIGTERM path).
The loop only enforces retention on the current primary pod; replicas skip maintenance silently .
Each cycle() does three things :
- Calls
barmanCommand.DeleteBackupsByPolicywith theRetentionPolicyfromObjectStore.spec.retentionPolicy(skipped if the field is empty). - Calls
barmanCommand.GetBackupListand deletes anyBackupKubernetes objects not present in the barman catalog. - Updates
ObjectStore.status.serverRecoveryWindowviaupdateRecoveryWindow.
The CatalogMaintenanceRunnable is registered as a controller-runtime Runnable and started alongside the CNPG-i gRPC server in instance.Start.
Interval Configuration#
The polling interval is set via ObjectStore.spec.instanceSidecarConfiguration.retentionPolicyIntervalSeconds .
| Setting | Value |
|---|---|
| API field | spec.instanceSidecarConfiguration.retentionPolicyIntervalSeconds |
| kubebuilder default | 1800 seconds (30 minutes) |
| Fallback (error/unreadable config) | 300 seconds (5 minutes) |
The two defaults serve different purposes:
- 1800 s is the steady-state interval — used when the
ObjectStoreis fetched successfully andcycle()returns cleanly. - 300 s is the error-recovery interval — used when
cycle()returns0(i.e., the cluster or object store couldn't be read, or enforcement failed) .
SIGTERM / Shutdown Delay#
The loop's select block exits immediately on ctx.Done() , so the inter-cycle sleep is fully interruptible. However, if a retention cycle is actively running when SIGTERM arrives, the sidecar will not respond until the in-flight cycle() call completes. Depending on the size of the backup catalog and the latency of the object store API, this can introduce a meaningful delay before the pod terminates.
To reduce worst-case shutdown time, lower retentionPolicyIntervalSeconds — this has no effect on active cycles but makes the pod more responsive when idle between cycles. There is no separate timeout on the cycle() call itself; the context passed to barmanCommand.DeleteBackupsByPolicy and barmanCommand.GetBackupList is the same manager context that is cancelled on SIGTERM, so Kubernetes' terminationGracePeriodSeconds remains the hard upper bound.
Key Source Files#
| File | Purpose |
|---|---|
internal/cnpgi/instance/retention.go | Loop, cycle, maintenance logic |
internal/cnpgi/instance/manager.go | Registers CatalogMaintenanceRunnable with the controller-runtime manager |
api/v1/objectstore_types.go | InstanceSidecarConfiguration struct, field defaults |