Migrate ServerStatusRequest controller and resource to kubebuilder (#2838)

* Convert ServerStatusRequest controller to controller-runtime

Signed-off-by: Carlisia <carlisia@vmware.com>

* Add select stm

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fixed status patch bug

Signed-off-by: Carlisia <carlisia@vmware.com>

* Add mgr start

Signed-off-by: Carlisia <carlisia@vmware.com>

* Trying to sync

Signed-off-by: Carlisia <carlisia@vmware.com>

* Clean async now

Signed-off-by: Carlisia <carlisia@vmware.com>

* Clean up + move context out

Signed-off-by: Carlisia <carlisia@vmware.com>

* Bug: not closing the channel

Signed-off-by: Carlisia <carlisia@vmware.com>

* Clean up some tests

Signed-off-by: Carlisia <carlisia@vmware.com>

* Much better way to fetch an update using a backoff loop

Signed-off-by: Carlisia <carlisia@vmware.com>

* Even better way to retry: use apimachinery lib

Signed-off-by: Carlisia <carlisia@vmware.com>

* Refactor controller + add test

Signed-off-by: Carlisia <carlisia@vmware.com>

* partially fix unit tests

Signed-off-by: Ashish Amarnath <ashisham@vmware.com>

* Fix and add tests

Signed-off-by: Carlisia <carlisia@vmware.com>

* Add changelog

Signed-off-by: Carlisia <carlisia@vmware.com>

* Add ability to disable the controller + cleanups

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix bug w/ disabling controllers + fix test + clean up

Signed-off-by: Carlisia <carlisia@vmware.com>

* Move role.yaml to the correct folder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Add sample serverstatusrequest.yaml

Signed-off-by: Carlisia <carlisia@vmware.com>

* Add requeue + better formatting

Signed-off-by: Carlisia <carlisia@vmware.com>

* Increase # of max concurrent reconciles

Signed-off-by: Carlisia <carlisia@vmware.com>

Co-authored-by: Ashish Amarnath <ashisham@vmware.com>
This commit is contained in:
Carlisia Campos
2020-09-01 14:15:23 -07:00
committed by GitHub
parent aed504a0fd
commit c952932f1b
19 changed files with 760 additions and 383 deletions

View File

@@ -34,6 +34,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/clock"
kubeerrs "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
@@ -777,31 +778,19 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
}
}
serverStatusRequestControllerRunInfo := func() controllerRunInfo {
serverStatusRequestController := controller.NewServerStatusRequestController(
s.logger,
s.veleroClient.VeleroV1(),
s.sharedInformerFactory.Velero().V1().ServerStatusRequests(),
s.pluginRegistry,
)
return controllerRunInfo{
controller: serverStatusRequestController,
numWorkers: defaultControllerWorkers,
}
}
enabledControllers := map[string]func() controllerRunInfo{
BackupSyncControllerKey: backupSyncControllerRunInfo,
BackupControllerKey: backupControllerRunInfo,
ScheduleControllerKey: scheduleControllerRunInfo,
GcControllerKey: gcControllerRunInfo,
BackupDeletionControllerKey: deletionControllerRunInfo,
RestoreControllerKey: restoreControllerRunInfo,
ResticRepoControllerKey: resticRepoControllerRunInfo,
DownloadRequestControllerKey: downloadrequestControllerRunInfo,
ServerStatusRequestControllerKey: serverStatusRequestControllerRunInfo,
BackupSyncControllerKey: backupSyncControllerRunInfo,
BackupControllerKey: backupControllerRunInfo,
ScheduleControllerKey: scheduleControllerRunInfo,
GcControllerKey: gcControllerRunInfo,
BackupDeletionControllerKey: deletionControllerRunInfo,
RestoreControllerKey: restoreControllerRunInfo,
ResticRepoControllerKey: resticRepoControllerRunInfo,
DownloadRequestControllerKey: downloadrequestControllerRunInfo,
}
// Note: all runtime type controllers that can be disabled are grouped separately, below:
enabledRuntimeControllers := make(map[string]struct{})
enabledRuntimeControllers[ServerStatusRequestControllerKey] = struct{}{}
if s.config.restoreOnly {
s.logger.Info("Restore only mode - not starting the backup, schedule, delete-backup, or GC controllers")
@@ -819,7 +808,13 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
s.logger.Infof("Disabling controller: %s", controllerName)
delete(enabledControllers, controllerName)
} else {
s.logger.Fatalf("Invalid value for --disable-controllers flag provided: %s. Valid values are: %s", controllerName, strings.Join(disableControllerList, ","))
// maybe it is a runtime type controllers, so attempt to remove that
if _, ok := enabledRuntimeControllers[controllerName]; ok {
s.logger.Infof("Disabling controller: %s", controllerName)
delete(enabledRuntimeControllers, controllerName)
} else {
s.logger.Fatalf("Invalid value for --disable-controllers flag provided: %s. Valid values are: %s", controllerName, strings.Join(disableControllerList, ","))
}
}
}
@@ -852,20 +847,36 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
s.logger.WithField("informer", informer).Info("Informer cache synced")
}
storageLocationInfo := velero.StorageLocation{
Client: s.mgr.GetClient(),
Ctx: s.ctx,
DefaultStorageLocation: s.config.defaultBackupLocation,
DefaultStoreValidationFrequency: s.config.storeValidationFrequency,
NewPluginManager: newPluginManager,
NewBackupStore: persistence.NewObjectBackupStore,
bslr := controller.BackupStorageLocationReconciler{
Scheme: s.mgr.GetScheme(),
StorageLocation: velero.StorageLocation{
Client: s.mgr.GetClient(),
Ctx: s.ctx,
DefaultStorageLocation: s.config.defaultBackupLocation,
DefaultStoreValidationFrequency: s.config.storeValidationFrequency,
NewPluginManager: newPluginManager,
NewBackupStore: persistence.NewObjectBackupStore,
},
Log: s.logger,
}
if err := (&controller.BackupStorageLocationReconciler{
Scheme: s.mgr.GetScheme(),
StorageLocation: storageLocationInfo,
Log: s.logger,
}).SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", "BackupStorageLocation")
if err := bslr.SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", "backup-storage-location")
}
if _, ok := enabledRuntimeControllers[ServerStatusRequestControllerKey]; ok {
r := controller.ServerStatusRequestReconciler{
Scheme: s.mgr.GetScheme(),
Client: s.mgr.GetClient(),
Ctx: s.ctx,
ServerStatus: velero.ServerStatus{
PluginRegistry: s.pluginRegistry,
Clock: clock.RealClock{},
},
Log: s.logger,
}
if err := r.SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", ServerStatusRequestControllerKey)
}
}
// TODO(2.0): presuming all controllers and resources are converted to runtime-controller