Return the error when getting backup store in backup deletion controller (#4465)

Per discussion in
https://github.com/vmware-tanzu/velero/issues/4260#issuecomment-947721686
https://github.com/vmware-tanzu/velero/issues/4260#issuecomment-951347384

return the error to avoid a panic when downloading the backup tarball

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
pull/4480/head
Daniel Jiang 2021-12-21 05:38:13 +08:00 committed by GitHub
parent d627362abd
commit d7aa82d8ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 5 deletions

View File

@ -0,0 +1 @@
Return the error when getting backup store in backup deletion controller

View File

@ -291,7 +291,7 @@ func (c *backupDeletionController) processRequest(req *velerov1api.DeleteBackupR
backupStore, err := c.backupStoreGetter.Get(location, pluginManager, log)
if err != nil {
errs = append(errs, err.Error())
return errors.Wrap(err, "error getting the backup store")
}
actions, err := pluginManager.GetDeleteItemActions()

View File

@ -21,6 +21,7 @@ import (
"context"
"fmt"
"io/ioutil"
"strings"
"testing"
"time"
@ -36,19 +37,20 @@ import (
core "k8s.io/client-go/testing"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/vmware-tanzu/velero/pkg/builder"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
"github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks"
"github.com/vmware-tanzu/velero/pkg/volume"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
"github.com/vmware-tanzu/velero/pkg/builder"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions"
"github.com/vmware-tanzu/velero/pkg/metrics"
persistencemocks "github.com/vmware-tanzu/velero/pkg/persistence/mocks"
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
pluginmocks "github.com/vmware-tanzu/velero/pkg/plugin/mocks"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
"github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
"github.com/vmware-tanzu/velero/pkg/volume"
)
func TestBackupDeletionControllerProcessQueueItem(t *testing.T) {
@ -183,6 +185,29 @@ func setupBackupDeletionControllerTest(t *testing.T, objects ...runtime.Object)
}
func TestBackupDeletionControllerProcessRequest(t *testing.T) {
t.Run("failed to get backup store", func(t *testing.T) {
backup := builder.ForBackup(velerov1api.DefaultNamespace, "foo").StorageLocation("default").Result()
location := &velerov1api.BackupStorageLocation{
ObjectMeta: metav1.ObjectMeta{
Namespace: backup.Namespace,
Name: backup.Spec.StorageLocation,
},
Spec: velerov1api.BackupStorageLocationSpec{
Provider: "objStoreProvider",
StorageType: velerov1api.StorageType{
ObjectStorage: &velerov1api.ObjectStorageLocation{
Bucket: "bucket",
},
},
},
}
td := setupBackupDeletionControllerTest(t, location, backup)
td.controller.backupStoreGetter = &fakeErrorBackupStoreGetter{}
err := td.controller.processRequest(td.req)
assert.NotNil(t, err)
assert.True(t, strings.HasPrefix(err.Error(), "error getting the backup store"))
})
t.Run("missing spec.backupName", func(t *testing.T) {
td := setupBackupDeletionControllerTest(t)
td.req.Spec.BackupName = ""

View File

@ -18,6 +18,7 @@ package controller
import (
"context"
"fmt"
"path/filepath"
"testing"
"time"
@ -130,6 +131,13 @@ func (t *testEnvironment) stop() error {
return env.Stop()
}
type fakeErrorBackupStoreGetter struct {
}
func (f *fakeErrorBackupStoreGetter) Get(*velerov1api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error) {
return nil, fmt.Errorf("some error")
}
type fakeSingleObjectBackupStoreGetter struct {
store persistence.BackupStore
}