[Bug]: lastSuccessfulBackup/firstRecoverabilityPoint intermittently not updated after a completed volumeSnapshot backup (stale cache read in updateClusterWithSnapshotsBackupTimes)
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I believe this is a new bug.
I am running a supported version of CloudNativePG
- I have information about the versions I am running.
Version
1.29 (latest patch) — 1.29.1; the affected code is unchanged on current main
What version of Kubernetes are you using?
1.35
What is your Kubernetes environment?
Cloud: Google GKE (v1.35.6-gke.1641000)
How did you install the operator?
Helm
What happened?
Cluster.status.lastSuccessfulBackup / firstRecoverabilityPoint (and therefore the cnpg_collector_last_available_backup_timestamp metric) intermittently fail to advance after a completed volumeSnapshot backup, with no error logged. The status stays at the previous backup's end time until the next backup completes (a whole schedule interval later). With a 4h ScheduledBackup and backup-staleness alerting on the metric, each occurrence produces a false "backups stale" page while the backup catalog is actually healthy. We see this roughly a few times per week across five clusters.
Observed timeline (one occurrence, 2026-08-22, all UTC):
04:30:00scheduled Backupatlas-postgres-scheduled-20260822043000starts (methodvolumeSnapshot, online, target = standby)04:31:46Backup CR reachesphase: completed(stoppedAt: 04:31:46); the VolumeSnapshot isreadyToUse: trueand carriescnpg.io/backupEndTime: 2026-08-22T04:31:46Z(verified present afterwards)04:31:46the cluster conditionLastBackupSucceeded("Backup was successful") is patched — so the post-completion code path inreconcileSnapshotBackupdid run to its endstatus.lastSuccessfulBackupremains2026-08-22T00:31:04Z(the previous backup) for the next 4 hours; no operator log line matches"could not update cluster's backups metadata"or"Can't update the cluster with the completed snapshot backup data"08:31:45the next scheduled backup completes and the status jumps directly to08:31:45— the04:31:46value never appears
Analysis:
In internal/controller/backup_controller.go, reconcileSnapshotBackup completes the backup (completeSnapshotBackupStep → annotateSnapshotsWithBackupData, which patches cnpg.io/backupEndTime onto the VolumeSnapshots) and then, in the same reconcile pass, calls updateClusterWithSnapshotsBackupTimes. That function recomputes the backup times via volumesnapshot.GetSnapshotsBackupTimes, which lists VolumeSnapshots through the manager's cached client — milliseconds after the annotation write. When the informer cache does not yet reflect the just-written annotation, the newest end time computed is the previous backup's, reflect.DeepEqual(origCluster.Status, cluster.Status) sees no change, and the patch is silently skipped. Nothing retries it: the Backup is now phase: completed, so subsequent reconciles return early, and the status stays stale until the next backup's completion recomputes it.
All the observed evidence matches this read-your-own-write race: completed Backup CR, annotation present, LastBackupSucceeded patched in the same second, no error logged, exactly-one-interval staleness, self-healing on the next backup.
Suggested fix ideas:
completeSnapshotBackupStepalready holds the authoritativebackup.Status.StoppedAt;updateClusterWithSnapshotsBackupTimescould take the just-completed backup's end time as a floor fornewestSnapshot(keeping the listing only foroldestSnapshot/firstRecoverabilityPoint), or- read the snapshots with the API reader instead of the cached client in this path.
Happy to submit a PR if a maintainer confirms the preferred direction.
Cluster resource
# relevant excerpt
spec:
instances: 3
backup:
retentionPolicy: 30d
volumeSnapshot:
className: csi-pd-snapshotclass
online: true
# plus a ScheduledBackup, method: volumeSnapshot, every 4h ("0 30 */4 * * *")Relevant log output
# operator logs for the affected backup, 04:30:00–04:32:00 — normal flow, then nothing after completion:
04:30:00 info Creating backup
04:30:00 info Waiting for VolumeSnapshot to be provisioned
04:30:06..04:31:36 info Waiting for VolumeSnapshot to be ready to use (repeats)
04:32:00 info Next backup schedule next=2026-08-22T08:30:00Z
# no "could not update cluster's backups metadata", no "Can't update the cluster with the completed
# snapshot backup data", no error-level lines for this cluster in the windowSource: cloudnative-pg/cloudnative-pg