From 9592aad85fdfc7d960a0e3bb3aa359fd671ca89a Mon Sep 17 00:00:00 2001 From: chaunceyjiang Date: Wed, 26 Apr 2023 17:45:19 +0800 Subject: [PATCH] fix: graceful-eviction still works after an unexpected restart of karmada-controller-manager Signed-off-by: chaunceyjiang --- .../crb_graceful_eviction_controller.go | 10 +++++++++- .../rb_graceful_eviction_controller.go | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/gracefuleviction/crb_graceful_eviction_controller.go b/pkg/controllers/gracefuleviction/crb_graceful_eviction_controller.go index 8e65a9a20..ab5107e96 100644 --- a/pkg/controllers/gracefuleviction/crb_graceful_eviction_controller.go +++ b/pkg/controllers/gracefuleviction/crb_graceful_eviction_controller.go @@ -84,7 +84,15 @@ func (c *CRBGracefulEvictionController) syncBinding(binding *workv1alpha2.Cluste // SetupWithManager creates a controller and register to controller manager. func (c *CRBGracefulEvictionController) SetupWithManager(mgr controllerruntime.Manager) error { clusterResourceBindingPredicateFn := predicate.Funcs{ - CreateFunc: func(createEvent event.CreateEvent) bool { return false }, + CreateFunc: func(createEvent event.CreateEvent) bool { + newObj := createEvent.Object.(*workv1alpha2.ClusterResourceBinding) + if len(newObj.Spec.GracefulEvictionTasks) == 0 { + return false + } + // When the current component is restarted and there are still tasks in the + // GracefulEvictionTasks queue, we need to continue the procession. + return newObj.Status.SchedulerObservedGeneration == newObj.Generation + }, UpdateFunc: func(updateEvent event.UpdateEvent) bool { newObj := updateEvent.ObjectNew.(*workv1alpha2.ClusterResourceBinding) diff --git a/pkg/controllers/gracefuleviction/rb_graceful_eviction_controller.go b/pkg/controllers/gracefuleviction/rb_graceful_eviction_controller.go index 7e0cce93c..2dbe04b57 100644 --- a/pkg/controllers/gracefuleviction/rb_graceful_eviction_controller.go +++ b/pkg/controllers/gracefuleviction/rb_graceful_eviction_controller.go @@ -84,7 +84,15 @@ func (c *RBGracefulEvictionController) syncBinding(binding *workv1alpha2.Resourc // SetupWithManager creates a controller and register to controller manager. func (c *RBGracefulEvictionController) SetupWithManager(mgr controllerruntime.Manager) error { resourceBindingPredicateFn := predicate.Funcs{ - CreateFunc: func(createEvent event.CreateEvent) bool { return false }, + CreateFunc: func(createEvent event.CreateEvent) bool { + newObj := createEvent.Object.(*workv1alpha2.ResourceBinding) + if len(newObj.Spec.GracefulEvictionTasks) == 0 { + return false + } + // When the current component is restarted and there are still tasks in the + // GracefulEvictionTasks queue, we need to continue the procession. + return newObj.Status.SchedulerObservedGeneration == newObj.Generation + }, UpdateFunc: func(updateEvent event.UpdateEvent) bool { newObj := updateEvent.ObjectNew.(*workv1alpha2.ResourceBinding)