Skip to content

Commit

Permalink
Fix issue: backup schedule pause/unpause doesn't work
Browse files Browse the repository at this point in the history
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(尹文开) <[email protected]>
  • Loading branch information
ywk253100 committed Dec 13, 2024
1 parent 0224d99 commit 6e34c09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8512-ywk253100
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue: backup schedule pause/unpause doesn't work
25 changes: 14 additions & 11 deletions pkg/controller/schedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Check warning on line 80 in pkg/controller/schedule_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/schedule_controller.go#L74-L80

Added lines #L74 - L80 were not covered by tests
})
s := kube.NewPeriodicalEnqueueSource(c.logger.WithField("controller", constant.ControllerSchedule), mgr.GetClient(), &velerov1.ScheduleList{}, scheduleSyncPeriod,
kube.PeriodicalEnqueueSourceOption{
Predicates: []predicate.Predicate{pred},
})

Check warning on line 85 in pkg/controller/schedule_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/schedule_controller.go#L82-L85

Added lines #L82 - L85 were not covered by tests
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)).

Check warning on line 87 in pkg/controller/schedule_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/schedule_controller.go#L87

Added line #L87 was not covered by tests
WatchesRawSource(s).
Complete(c)
}
Expand Down

0 comments on commit 6e34c09

Please sign in to comment.