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

View File

@@ -54,7 +54,7 @@ type backupSyncController struct {
defaultBackupLocation string
defaultBackupSyncPeriod time.Duration
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager
newBackupStore func(*velerov1api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
backupStoreGetter persistence.ObjectBackupStoreGetter
}
func NewBackupSyncController(
@@ -68,6 +68,7 @@ func NewBackupSyncController(
kubeClient kubernetes.Interface,
defaultBackupLocation string,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
backupStoreGetter persistence.ObjectBackupStoreGetter,
logger logrus.FieldLogger,
) Interface {
if syncPeriod <= 0 {
@@ -89,8 +90,8 @@ func NewBackupSyncController(
// use variables to refer to these functions so they can be
// replaced with fakes for testing.
newPluginManager: newPluginManager,
newBackupStore: persistence.NewObjectBackupStore,
newPluginManager: newPluginManager,
backupStoreGetter: backupStoreGetter,
}
c.resyncFunc = c.run
@@ -169,7 +170,7 @@ func (c *backupSyncController) run() {
log.Debug("Checking backup location for backups to sync into cluster")
backupStore, err := c.newBackupStore(&location, pluginManager, log)
backupStore, err := c.backupStoreGetter.Get(&location, pluginManager, log)
if err != nil {
log.WithError(err).Error("Error getting backup store for this location")
continue