[Bug]: A failed plugin backup sets the deprecated `status.lastFailedBackup`, so `cnpg_collector_last_failed_backup_timestamp` stays newer than the last available backup
What happened?
With backups taken through the Barman Cloud plugin, a failed backup still writes
.status.lastFailedBackup in the Cluster, but a successful one does not write
.status.lastSuccessfulBackup. The API reference says both fields are
"not set for backup plugins".
After a single failed plugin backup, the deprecated metrics end up in a state that looks like the last backup failed, even though every backup after it succeeded:
# cluster-a (plugin backups every day, two failures on 2026-10-06/07, 15 successes since)
cnpg_collector_last_available_backup_timestamp 0
cnpg_collector_last_failed_backup_timestamp 1791345609 # 2026-10-07T04:00:09Z
barman_cloud_cloudnative_pg_io_last_available_backup_timestamp 1792641604 # 2026-10-22
$ kubectl get cluster cluster-a -o jsonpath='{.status.lastSuccessfulBackup} / {.status.lastFailedBackup}'
/ 2026-10-07T04:00:09Z
The LastBackupSucceeded condition is True, and the plugin metrics are correct.
Only the deprecated fields and metrics disagree.
Where
pkg/management/postgres/webserver/plugin_backup.go,markBackupAsFailedcallsstatus.FlagBackupAsFailed(..., b.Cluster, failure).pkg/resources/status/backup.gosetscluster.Status.LastFailedBackupfor every method.
Proposal
Skip the lastFailedBackup update in FlagBackupAsFailed when the backup
method is plugin, and keep updating the LastBackupSucceeded condition. This
matches the API reference and the warning in monitoring.md. I have a small
patch with a unit test and can open a PR if this approach is fine.
(Alternative: keep the current behavior and change the API reference and
monitoring.md. That leaves a failure timestamp without the matching success
timestamp, so I'd prefer the code change.)
Version
1.30.0 (operator), plugin-barman-cloud 0.14.0. The same code is on main (2a54673).
I used an AI assistant (Claude) to read the code and draft this report; I checked the numbers on my own cluster.
I'd like to work on this.
The approach I have in mind: in FlagBackupAsFailed (pkg/resources/status/backup.go), skip the .status.lastFailedBackup update when backup.Spec.Method is plugin. The success side already never sets lastSuccessfulBackup for plugins, and the API reference says both fields are not set for backup plugins. Because the check is in FlagBackupAsFailed, it covers both the instance manager and the operator's backup controller. The backup phase and the LastBackupSucceeded condition are still updated as before, and other methods are unchanged. A stale value already set on existing clusters would stay; the change only stops new writes.
I would add a Ginkgo spec in pkg/resources/status/backup_test.go that flags a plugin backup as failed and checks that lastFailedBackup stays empty while the condition is False.
If this sounds right, could you assign the issue to me? Following AI_POLICY.md, I'd disclose that I'm using an AI assistant (Claude) and add the Assisted-by: trailer to the commit.