Merge pull request #5444 from Lyndon-Li/remove-restic

Pod Volume Backup/Restore Refactor: Remove Restic in code
This commit is contained in:
Xun Jiang/Bruce Jiang
2022-10-17 15:32:17 +08:00
committed by GitHub
32 changed files with 333 additions and 321 deletions
+20 -9
View File
@@ -300,7 +300,7 @@ func newServer(f client.Factory, config serverConfig, logger *logrus.Logger) (*s
// cancelFunc is not deferred here because if it was, then ctx would immediately
// be cancelled once this function exited, making it useless to any informers using later.
// That, in turn, causes the velero server to halt when the first informer tries to use it (probably restic's).
// That, in turn, causes the velero server to halt when the first informer tries to use it.
// Therefore, we must explicitly call it on the error paths in this function.
ctx, cancelFunc := context.WithCancel(context.Background())
@@ -395,7 +395,9 @@ func (s *server) run() error {
return err
}
if err := s.initRestic(); err != nil {
s.checkNodeAgent()
if err := s.initRepoManager(); err != nil {
return err
}
@@ -499,7 +501,7 @@ func (s *server) veleroResourcesExist() error {
// - Service accounts go before pods or controllers so pods can use them.
// - Limit ranges go before pods or controllers so pods can use them.
// - Pods go before controllers so they can be explicitly restored and potentially
// have restic restores run before controllers adopt the pods.
// have pod volume restores run before controllers adopt the pods.
// - Replica sets go before deployments/other controllers so they can be explicitly
// restored and be adopted by controllers.
// - CAPI ClusterClasses go before Clusters.
@@ -530,7 +532,16 @@ var defaultRestorePriorities = []string{
"clusterresourcesets.addons.cluster.x-k8s.io",
}
func (s *server) initRestic() error {
func (s *server) checkNodeAgent() {
// warn if node agent does not exist
if err := nodeagent.IsRunning(s.ctx, s.kubeClient, s.namespace); err == nodeagent.DaemonsetNotFound {
s.logger.Warn("Velero node agent not found; pod volume backups/restores will not work until it's created")
} else if err != nil {
s.logger.WithError(errors.WithStack(err)).Warn("Error checking for existence of velero node agent")
}
}
func (s *server) initRepoManager() error {
// warn if node agent does not exist
if err := nodeagent.IsRunning(s.ctx, s.kubeClient, s.namespace); err == nodeagent.DaemonsetNotFound {
s.logger.Warn("Velero node agent not found; pod volume backups/restores will not work until it's created")
@@ -664,7 +675,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
// By far, PodVolumeBackup, PodVolumeRestore, BackupStorageLocation controllers
// are not included in --disable-controllers list.
// This is because of PVB and PVR are used by Restic DaemonSet,
// This is because of PVB and PVR are used by node agent DaemonSet,
// and BSL controller is mandatory for Velero to work.
enabledControllers := map[string]func() controllerRunInfo{
controller.Backup: backupControllerRunInfo,
@@ -675,7 +686,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
controller.ServerStatusRequest: {},
controller.DownloadRequest: {},
controller.Schedule: {},
controller.ResticRepo: {},
controller.BackupRepo: {},
controller.BackupDeletion: {},
controller.GarbageCollection: {},
controller.BackupSync: {},
@@ -748,9 +759,9 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
}
}
if _, ok := enabledRuntimeControllers[controller.ResticRepo]; ok {
if err := controller.NewResticRepoReconciler(s.namespace, s.logger, s.mgr.GetClient(), s.config.repoMaintenanceFrequency, s.repoManager).SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", controller.ResticRepo)
if _, ok := enabledRuntimeControllers[controller.BackupRepo]; ok {
if err := controller.NewBackupRepoReconciler(s.namespace, s.logger, s.mgr.GetClient(), s.config.repoMaintenanceFrequency, s.repoManager).SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", controller.BackupRepo)
}
}
+2 -2
View File
@@ -94,7 +94,7 @@ func TestRemoveControllers(t *testing.T) {
controller.BackupSync,
controller.DownloadRequest,
controller.GarbageCollection,
controller.ResticRepo,
controller.BackupRepo,
controller.Restore,
controller.Schedule,
controller.ServerStatusRequest,
@@ -130,7 +130,7 @@ func TestRemoveControllers(t *testing.T) {
controller.ServerStatusRequest: {},
controller.Schedule: {},
controller.BackupDeletion: {},
controller.ResticRepo: {},
controller.BackupRepo: {},
controller.DownloadRequest: {},
}