Skip to content

K8SPG-992: fail backup when cluster is deleted#1691

Open
pooknull wants to merge 1 commit into
mainfrom
K8SPG-992
Open

K8SPG-992: fail backup when cluster is deleted#1691
pooknull wants to merge 1 commit into
mainfrom
K8SPG-992

Conversation

@pooknull

@pooknull pooknull commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

DESCRIPTION

Problem:
When a cluster is deleted while a backup is still in progress, the backup remains stuck in the Running state. Instead, it should transition to Failed.

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

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PG version?
  • Does the change support oldest and newest supported Kubernetes version?

@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
backup-enable-disable passed 00:13:00
builtin-extensions passed 00:06:36
cert-manager-tls passed 00:13:45
custom-envs passed 00:19:32
custom-tls passed 00:06:41
database-init-sql passed 00:02:30
demand-backup passed 00:25:02
demand-backup-offline-snapshot passed 00:15:15
dynamic-configuration passed 00:03:43
finalizers passed 00:04:00
init-deploy passed 00:03:02
huge-pages passed 00:03:08
major-upgrade-14-to-15 passed 00:11:15
major-upgrade-15-to-16 passed 00:10:34
major-upgrade-16-to-17 passed 00:10:59
major-upgrade-17-to-18 passed 00:09:46
ldap passed 00:03:53
ldap-tls passed 00:05:49
monitoring passed 00:08:52
monitoring-pmm3 passed 00:09:17
one-pod passed 00:06:22
operator-self-healing passed 00:10:28
pitr passed 00:12:54
scaling passed 00:05:49
scheduled-backup passed 00:28:56
self-healing passed 00:10:20
sidecars passed 00:02:45
standby-pgbackrest passed 00:18:42
standby-streaming passed 00:12:52
start-from-backup passed 00:13:52
tablespaces passed 00:07:12
telemetry-transfer passed 00:04:33
upgrade-consistency passed 00:07:08
upgrade-minor passed 00:07:00
users passed 00:04:29
migration-from-crunchy-standby passed 00:18:25
migration-from-crunchy-pv passed 00:08:13
migration-from-crunchy-backup-restore passed 00:16:19
Summary Value
Tests Run 38/38
Job Duration 02:11:52
Total Test Time 06:23:18

commit: 961c6eb
image: perconalab/percona-postgresql-operator:PR-1691-961c6eb54

@egegunes egegunes added this to the v3.1.0 milestone Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PerconaPGBackup as Failed (with a status error) when the cluster is not found or is being deleted during Starting/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).

Comment on lines +72 to +83
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)
Comment on lines +137 to +145
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

7 participants