From 5e53974311b5ee02ab98ee1e4052dda1933ec577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Fri, 13 Dec 2024 15:58:40 +0800 Subject: [PATCH] Fix issue: backup schedule pause/unpause doesn't work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue is caused by the changes of controller-runtime: WithEventFilter() doesn't apply to WatchesRawSource(), this commit set Predicate for WatchesRawSource() seperatedly Fixes #8437 Signed-off-by: Wenkai Yin(尹文开) --- pkg/controller/schedule_controller.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/controller/schedule_controller.go b/pkg/controller/schedule_controller.go index 40ddf7b79e..4b89e98a3e 100644 --- a/pkg/controller/schedule_controller.go +++ b/pkg/controller/schedule_controller.go @@ -31,6 +31,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" bld "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/predicate" velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" @@ -70,18 +71,20 @@ func NewScheduleReconciler( } func (c *scheduleReconciler) SetupWithManager(mgr ctrl.Manager) error { - s := kube.NewPeriodicalEnqueueSource(c.logger.WithField("controller", constant.ControllerSchedule), mgr.GetClient(), &velerov1.ScheduleList{}, scheduleSyncPeriod, kube.PeriodicalEnqueueSourceOption{}) + pred := kube.NewAllEventPredicate(func(obj client.Object) bool { + schedule := obj.(*velerov1.Schedule) + if pause := schedule.Spec.Paused; pause { + c.logger.Infof("schedule %s is paused, skip", schedule.Name) + return false + } + return true + }) + s := kube.NewPeriodicalEnqueueSource(c.logger.WithField("controller", constant.ControllerSchedule), mgr.GetClient(), &velerov1.ScheduleList{}, scheduleSyncPeriod, + kube.PeriodicalEnqueueSourceOption{ + Predicates: []predicate.Predicate{pred}, + }) return ctrl.NewControllerManagedBy(mgr). - // global predicate, works for both For and Watch - WithEventFilter(kube.NewAllEventPredicate(func(obj client.Object) bool { - schedule := obj.(*velerov1.Schedule) - if pause := schedule.Spec.Paused; pause { - c.logger.Infof("schedule %s is paused, skip", schedule.Name) - return false - } - return true - })). - For(&velerov1.Schedule{}, bld.WithPredicates(kube.SpecChangePredicate{})). + For(&velerov1.Schedule{}, bld.WithPredicates(kube.SpecChangePredicate{}, pred)). WatchesRawSource(s). Complete(c) }