Replace NewObjectBackupStore with interface (#3329)

In preparation for modifying the instantiation of `BackupStores` to be
able to load credentials, change the function `NewObjectBackupStore` to
be an interface that is passed in to all controllers.

Previously, the function to get a new backup store was configurable but
for many controllers was fixed to use `NewObjectBackupStore`. This
change introduces an interface for getting the backup store and wraps
the functionality from `NewObjectBackupStore` in a type which implements
this interface. This will allow more flexibility when introducing
credentials for a specific backup store as it will allow us to create a
new `ObjectBackupStoreGetter` type which can be configured to add
credentials config when creating the ObjectBackupStore without needing
to change the API used by the controllers.

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
This commit is contained in:
Bridget McErlean
2021-02-08 13:04:08 -05:00
committed by GitHub
parent 65c16a1d00
commit 38c08e087b
16 changed files with 117 additions and 80 deletions
@@ -21,6 +21,8 @@ import (
"testing"
"time"
"github.com/vmware-tanzu/velero/pkg/persistence"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -34,7 +36,6 @@ import (
"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/label"
"github.com/vmware-tanzu/velero/pkg/persistence"
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"
@@ -351,14 +352,10 @@ func TestBackupSyncControllerRun(t *testing.T) {
nil, // kubeClient
"",
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
NewFakeObjectBackupStoreGetter(backupStores),
velerotest.NewLogger(),
).(*backupSyncController)
c.newBackupStore = func(loc *velerov1api.BackupStorageLocation, _ persistence.ObjectStoreGetter, _ logrus.FieldLogger) (persistence.BackupStore, error) {
// this gets populated just below, prior to exercising the method under test
return backupStores[loc.Name], nil
}
pluginManager.On("CleanupClients").Return(nil)
for _, location := range test.locations {
@@ -576,6 +573,7 @@ func TestDeleteOrphanedBackups(t *testing.T) {
nil, // kubeClient
"",
nil, // new plugin manager func
persistence.NewObjectBackupStoreGetter(),
velerotest.NewLogger(),
).(*backupSyncController)
@@ -669,6 +667,7 @@ func TestStorageLabelsInDeleteOrphanedBackups(t *testing.T) {
nil, // kubeClient
"",
nil, // new plugin manager func
persistence.NewObjectBackupStoreGetter(),
velerotest.NewLogger(),
).(*backupSyncController)