Skip to content

Commit

Permalink
Fail Delete Backup if BSL is not available (#8029)
Browse files Browse the repository at this point in the history
* Fail Delete Backup if BSL is not available

Signed-off-by: Anshul Ahuja <[email protected]>

* linter

Signed-off-by: Anshul Ahuja <[email protected]>

---------

Signed-off-by: Anshul Ahuja <[email protected]>
  • Loading branch information
anshulahuja98 authored Jul 31, 2024
1 parent 7b26673 commit 1a167f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque

backupStore, err := r.backupStoreGetter.Get(location, pluginManager, log)
if err != nil {
return ctrl.Result{}, errors.Wrap(err, "error getting the backup store")
_, patchErr := r.patchDeleteBackupRequest(ctx, dbr, func(r *velerov1api.DeleteBackupRequest) {
r.Status.Phase = velerov1api.DeleteBackupRequestPhaseProcessed
r.Status.Errors = append(r.Status.Errors, fmt.Sprintf("cannot delete backup because backup storage location %s is currently unavailable, error: %s", location.Name, err.Error()))
})
return ctrl.Result{}, patchErr
}

actions, err := pluginManager.GetDeleteItemActions()
Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/backup_deletion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
td := setupBackupDeletionControllerTest(t, defaultTestDbr(), location, backup)
td.controller.backupStoreGetter = &fakeErrorBackupStoreGetter{}
_, err := td.controller.Reconcile(ctx, td.req)
assert.Error(t, err)
assert.True(t, strings.HasPrefix(err.Error(), "error getting the backup store"))
require.NoError(t, err)
res := &velerov1api.DeleteBackupRequest{}
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
require.NoError(t, err)
assert.Equal(t, "Processed", string(res.Status.Phase))
assert.Len(t, res.Status.Errors, 1)
assert.True(t, strings.HasPrefix(res.Status.Errors[0], fmt.Sprintf("cannot delete backup because backup storage location %s is currently unavailable", location.Name)))
})

t.Run("missing spec.backupName", func(t *testing.T) {
Expand Down

0 comments on commit 1a167f9

Please sign in to comment.