Conversation
commit: 961c6eb |
There was a problem hiding this comment.
Pull request overview
This PR updates the PGBackup controller reconciliation flow so that if the referenced PerconaPGCluster is missing or terminating while a backup is in progress, the backup transitions to Failed, its lease is released, and backup finalizers (including snapshot-related ones) can be removed to avoid leaving the backup stuck in Running.
Changes:
- Mark
PerconaPGBackupasFailed(with a status error) when the cluster is not found or is being deleted duringStarting/Running. - Adjust lease handling and finalizer processing to allow releasing the lease and removing snapshot-related finalizers when the cluster is unavailable/terminating.
- Add a unit test covering failure + finalizer/lease cleanup when the cluster is unavailable (including snapshot mode).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
percona/controller/pgbackup/controller.go |
Detect cluster deletion/unavailability during backup and drive failure + lease/finalizer cleanup paths. |
percona/controller/pgbackup/controller_test.go |
Adds test coverage for failing backups when the cluster is deleted/terminating (including snapshot lease/finalizer cleanup). |
| backup := &v2.PerconaPGBackup{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-backup", | ||
| Namespace: cluster.Namespace, | ||
| Finalizers: []string{pNaming.FinalizerDeleteBackup}, | ||
| }, | ||
| Spec: v2.PerconaPGBackupSpec{ | ||
| PGCluster: cluster.Name, | ||
| RepoName: new("repo1"), | ||
| }, | ||
| Status: v2.PerconaPGBackupStatus{State: v2.BackupRunning}, | ||
| } |
| Status: v2.PerconaPGBackupStatus{State: v2.BackupRunning}, | ||
| } | ||
| if tt.snapshot { | ||
| backup.Spec.Method = new(v2.BackupMethodVolumeSnapshot) |
| if err := pgBackup.UpdateStatus(ctx, r.Client, func(bcp *v2.PerconaPGBackup) { | ||
| bcp.Status.State = v2.BackupFailed | ||
| bcp.Status.Error = statusError | ||
| }); err != nil { | ||
| return reconcile.Result{}, errors.Wrap(err, "update backup status") | ||
| } | ||
|
|
||
| pgBackup.Status.State = v2.BackupFailed | ||
| pgBackup.Status.Error = statusError |
There was a problem hiding this comment.
Seems that we are using this pattern more or less a lot in the codebase, maybe we can introduce something like failBackup(ctx context.Context, pgBackup *v2.PerconaPGBackup, reason string) and reuse it.
DESCRIPTION
Problem:
When a cluster is deleted while a backup is still in progress, the backup remains stuck in the
Runningstate. Instead, it should transition toFailed.Solution:
During backup reconcile, if the cluster is not found or has deletion timestamp, set an active backup as
Failed, release its backup lease, and remove all finalizers.CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability