mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-04 20:24:02 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user