Skip to content

Commit

Permalink
update sync controller for backup locations
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <[email protected]>
  • Loading branch information
skriss committed Aug 28, 2018
1 parent 2750aa7 commit 0e94fa3
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 532 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/ark/v1/labels_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ const (
// a backup/restore-specific timeout value for pod volume operations (i.e.
// restic backups/restores).
PodVolumeOperationTimeoutAnnotation = "ark.heptio.com/pod-volume-timeout"

// StorageLocationLabel is the label key used to identify the storage
// location of a backup.
StorageLocationLabel = "ark.heptio.com/storage-location"
)
97 changes: 0 additions & 97 deletions pkg/cloudprovider/backup_cache.go

This file was deleted.

170 changes: 0 additions & 170 deletions pkg/cloudprovider/backup_cache_test.go

This file was deleted.

16 changes: 0 additions & 16 deletions pkg/cloudprovider/backup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,6 @@ func DownloadBackup(objectStore ObjectStore, bucket, backupName string) (io.Read
return objectStore.GetObject(bucket, getBackupContentsKey(backupName, backupName))
}

type liveBackupLister struct {
logger logrus.FieldLogger
objectStore ObjectStore
}

func NewLiveBackupLister(logger logrus.FieldLogger, objectStore ObjectStore) BackupLister {
return &liveBackupLister{
logger: logger,
objectStore: objectStore,
}
}

func (l *liveBackupLister) ListBackups(bucket string) ([]*api.Backup, error) {
return ListBackups(l.logger, l.objectStore, bucket)
}

func ListBackups(logger logrus.FieldLogger, objectStore ObjectStore, bucket string) ([]*api.Backup, error) {
prefixes, err := objectStore.ListCommonPrefixes(bucket, "/")
if err != nil {
Expand Down
20 changes: 8 additions & 12 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,6 @@ func (s *server) runControllers(config *api.Config, defaultBackupLocation *api.B
ctx := s.ctx
var wg sync.WaitGroup

cloudBackupCacheResyncPeriod := durationMin(controller.GCSyncPeriod, s.config.backupSyncPeriod)
s.logger.Infof("Caching cloud backups every %s", cloudBackupCacheResyncPeriod)

liveBackupLister := cloudprovider.NewLiveBackupLister(s.logger, s.objectStore)
cachedBackupLister := cloudprovider.NewBackupCache(ctx, liveBackupLister, cloudBackupCacheResyncPeriod, s.logger)

go func() {
metricsMux := http.NewServeMux()
metricsMux.Handle("/metrics", promhttp.Handler())
Expand All @@ -608,12 +602,13 @@ func (s *server) runControllers(config *api.Config, defaultBackupLocation *api.B

backupSyncController := controller.NewBackupSyncController(
s.arkClient.ArkV1(),
cachedBackupLister,
config.BackupStorageProvider.Bucket,
s.sharedInformerFactory.Ark().V1().Backups(),
s.sharedInformerFactory.Ark().V1().BackupStorageLocations(),
s.config.backupSyncPeriod,
s.namespace,
s.sharedInformerFactory.Ark().V1().Backups(),
s.pluginRegistry,
s.logger,
s.logLevel,
)
wg.Add(1)
go func() {
Expand Down Expand Up @@ -775,7 +770,7 @@ func (s *server) runControllers(config *api.Config, defaultBackupLocation *api.B
// SHARED INFORMERS HAVE TO BE STARTED AFTER ALL CONTROLLERS
go s.sharedInformerFactory.Start(ctx.Done())

// Remove this sometime after v0.8.0
// TODO(1.0): remove
cache.WaitForCacheSync(ctx.Done(), s.sharedInformerFactory.Ark().V1().Backups().Informer().HasSynced)
s.removeDeprecatedGCFinalizer()

Expand All @@ -789,9 +784,10 @@ func (s *server) runControllers(config *api.Config, defaultBackupLocation *api.B
return nil
}

const gcFinalizer = "gc.ark.heptio.com"

// TODO(1.0): remove
func (s *server) removeDeprecatedGCFinalizer() {
const gcFinalizer = "gc.ark.heptio.com"

backups, err := s.sharedInformerFactory.Ark().V1().Backups().Lister().List(labels.Everything())
if err != nil {
s.logger.WithError(errors.WithStack(err)).Error("error listing backups from cache - unable to remove old finalizers")
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ func (controller *backupController) getLocationAndValidate(itm *api.Backup, defa
itm.Spec.StorageLocation = defaultBackupLocation
}

// add the storage location as a label for easy filtering later.
if itm.Labels == nil {
itm.Labels = make(map[string]string)
}
itm.Labels[api.StorageLocationLabel] = itm.Spec.StorageLocation

var backupLocation *api.BackupStorageLocation
backupLocation, err := controller.backupLocationLister.BackupStorageLocations(itm.Namespace).Get(itm.Spec.StorageLocation)
if err != nil {
Expand Down
Loading

0 comments on commit 0e94fa3

Please sign in to comment.