From 133dc185ca5eeadd04b40edb0575f84b80b10434 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Fri, 24 Aug 2018 11:07:01 -0700 Subject: [PATCH] backup sync: process the default location first Signed-off-by: Steve Kriss --- pkg/cmd/server/server.go | 1 + pkg/controller/backup_sync_controller.go | 5 +++++ pkg/controller/backup_sync_controller_test.go | 2 ++ pkg/controller/restore_controller.go | 2 ++ 4 files changed, 10 insertions(+) diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index b2a53d865..60d6c96b8 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -571,6 +571,7 @@ func (s *server) runControllers(config *api.Config, defaultBackupLocation *api.B s.sharedInformerFactory.Ark().V1().BackupStorageLocations(), s.config.backupSyncPeriod, s.namespace, + s.config.defaultBackupLocation, s.pluginRegistry, s.logger, s.logLevel, diff --git a/pkg/controller/backup_sync_controller.go b/pkg/controller/backup_sync_controller.go index 0706108fc..a19d7aea0 100644 --- a/pkg/controller/backup_sync_controller.go +++ b/pkg/controller/backup_sync_controller.go @@ -45,6 +45,7 @@ type backupSyncController struct { backupLister listers.BackupLister backupStorageLocationLister listers.BackupStorageLocationLister namespace string + defaultBackupLocation string newPluginManager func(logrus.FieldLogger) plugin.Manager listCloudBackups func(logrus.FieldLogger, cloudprovider.ObjectStore, string) ([]*arkv1api.Backup, error) } @@ -55,6 +56,7 @@ func NewBackupSyncController( backupStorageLocationInformer informers.BackupStorageLocationInformer, syncPeriod time.Duration, namespace string, + defaultBackupLocation string, pluginRegistry plugin.Registry, logger logrus.FieldLogger, logLevel logrus.Level, @@ -68,6 +70,7 @@ func NewBackupSyncController( genericController: newGenericController("backup-sync", logger), client: client, namespace: namespace, + defaultBackupLocation: defaultBackupLocation, backupLister: backupInformer.Lister(), backupStorageLocationLister: backupStorageLocationInformer.Lister(), @@ -97,6 +100,8 @@ func (c *backupSyncController) run() { c.logger.WithError(errors.WithStack(err)).Error("Error getting backup storage locations from lister") return } + // sync the default location first, if it exists + locations = orderedBackupLocations(locations, c.defaultBackupLocation) pluginManager := c.newPluginManager(c.logger) diff --git a/pkg/controller/backup_sync_controller_test.go b/pkg/controller/backup_sync_controller_test.go index a91a45c0b..4badb0368 100644 --- a/pkg/controller/backup_sync_controller_test.go +++ b/pkg/controller/backup_sync_controller_test.go @@ -176,6 +176,7 @@ func TestBackupSyncControllerRun(t *testing.T) { sharedInformers.Ark().V1().BackupStorageLocations(), time.Duration(0), test.namespace, + "", nil, // pluginRegistry arktest.NewLogger(), logrus.DebugLevel, @@ -341,6 +342,7 @@ func TestDeleteOrphanedBackups(t *testing.T) { sharedInformers.Ark().V1().BackupStorageLocations(), time.Duration(0), test.namespace, + "", nil, // pluginRegistry arktest.NewLogger(), logrus.InfoLevel, diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 4fe2842b0..215c51405 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -521,6 +521,8 @@ func (c *restoreController) fetchFromBackupStorage(backupName string, pluginMana return backupInfo{}, errors.New("not able to fetch from backup storage") } +// orderedBackupLocations returns a new slice with the default backup location first (if it exists), +// followed by the rest of the locations in no particular order. func orderedBackupLocations(locations []*api.BackupStorageLocation, defaultLocationName string) []*api.BackupStorageLocation { var result []*api.BackupStorageLocation