From aa5f389936994e42a467827984c93b9ed040245b Mon Sep 17 00:00:00 2001 From: allenxu404 Date: Thu, 18 Aug 2022 19:21:43 +0800 Subject: [PATCH] add gc controller into enabledRuntimeControllers for disable-controller feature Signed-off-by: allenxu404 --- pkg/cmd/server/server.go | 12 ++++++++---- pkg/controller/gc_controller.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index b042f19a70..d846bdc12e 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -720,6 +720,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string enabledRuntimeControllers := make(map[string]struct{}) enabledRuntimeControllers[controller.ServerStatusRequest] = struct{}{} enabledRuntimeControllers[controller.DownloadRequest] = struct{}{} + enabledRuntimeControllers[controller.GarbageCollection] = struct{}{} if s.config.restoreOnly { s.logger.Info("Restore only mode - not starting the backup, schedule, delete-backup, or GC controllers") @@ -790,10 +791,6 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string s.logger.Fatal(err, "unable to create controller", "controller", controller.ResticRepo) } - if err := controller.NewGCReconciler(s.logger, s.mgr.GetClient()).SetupWithManager(s.mgr); err != nil { - s.logger.Fatal(err, "unable to create controller", "controller", controller.GarbageCollection) - } - if err := controller.NewBackupDeletionReconciler( s.logger, s.mgr.GetClient(), @@ -835,6 +832,13 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string } } + if _, ok := enabledRuntimeControllers[controller.GarbageCollection]; ok { + r := controller.NewGCReconciler(s.logger, s.mgr.GetClient()) + if err := r.SetupWithManager(s.mgr); err != nil { + s.logger.Fatal(err, "unable to create controller", "controller", controller.GarbageCollection) + } + } + // TODO(2.0): presuming all controllers and resources are converted to runtime-controller // by v2.0, the block from this line and including the `s.mgr.Start() will be // deprecated, since the manager auto-starts all the caches. Until then, we need to start the diff --git a/pkg/controller/gc_controller.go b/pkg/controller/gc_controller.go index e270616b54..383045a323 100644 --- a/pkg/controller/gc_controller.go +++ b/pkg/controller/gc_controller.go @@ -26,6 +26,8 @@ import ( "k8s.io/apimachinery/pkg/util/clock" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/event" + "sigs.k8s.io/controller-runtime/pkg/predicate" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" pkgbackup "github.com/vmware-tanzu/velero/pkg/backup" @@ -64,6 +66,17 @@ func (c *gcReconciler) SetupWithManager(mgr ctrl.Manager) error { s := kube.NewPeriodicalEnqueueSource(c.logger, mgr.GetClient(), &velerov1api.BackupList{}, defaultGCFrequency) return ctrl.NewControllerManagedBy(mgr). For(&velerov1api.Backup{}). + WithEventFilter(predicate.Funcs{ + UpdateFunc: func(ue event.UpdateEvent) bool { + return false + }, + DeleteFunc: func(de event.DeleteEvent) bool { + return false + }, + GenericFunc: func(ge event.GenericEvent) bool { + return false + }, + }). Watches(s, nil). Complete(c) }