Skip to content

Commit d5dc17f

Browse files
committed
prevent backup deletion when errors occur
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
1 parent 694b9a0 commit d5dc17f

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

pkg/controller/backup_deletion_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
268268

269269
if err != nil {
270270
log.WithError(err).Errorf("Unable to download tarball for backup %s, skipping associated DeleteItemAction plugins", backup.Name)
271+
// for backups which failed before tarball object could be uploaded we do offline cleanup
272+
log.Info("Cleaning up CSI volumesnapshots")
273+
r.deleteCSIVolumeSnapshotsIfAny(ctx, backup, log)
274+
271275
// If the tarball simply does not exist (HTTP 404 / not found), the download
272276
// failure is permanent and not retryable, so we let deletion proceed.
273277
// For transient errors (throttling, auth failures, network issues), record
@@ -357,7 +361,7 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
357361
}
358362
}
359363

360-
if backupStore != nil {
364+
if backupStore != nil && len(errs) == 0 {
361365
log.Info("Removing backup from backup storage")
362366
if err := backupStore.DeleteBackup(backup.Name); err != nil {
363367
errs = append(errs, err.Error())

pkg/controller/backup_deletion_controller_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,15 +670,14 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
670670

671671
td.backupStore.On("GetBackupVolumeSnapshots", input.Spec.BackupName).Return(snapshots, nil)
672672
td.backupStore.On("GetBackupContents", input.Spec.BackupName).Return(nil, fmt.Errorf("error downloading tarball"))
673-
td.backupStore.On("DeleteBackup", input.Spec.BackupName).Return(nil)
674673

675674
_, err := td.controller.Reconcile(t.Context(), td.req)
676675
require.NoError(t, err)
677676

678677
td.backupStore.AssertCalled(t, "GetBackupContents", input.Spec.BackupName)
679-
// DeleteBackup (removing backup data from object storage) is still called because
680-
// that step is not gated by the errs slice; only the Kubernetes Backup CR deletion is.
681-
td.backupStore.AssertCalled(t, "DeleteBackup", input.Spec.BackupName)
678+
// DeleteBackup (removing backup data from object storage) must NOT be called
679+
// when there are errors, so that the deletion can be retried later.
680+
td.backupStore.AssertNotCalled(t, "DeleteBackup", input.Spec.BackupName)
682681

683682
// the dbr should still exist and be marked Processed with errors
684683
res := &velerov1api.DeleteBackupRequest{}

0 commit comments

Comments
 (0)