Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: failed to sync work when binding's target clusters are empty #5818

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pkg/controllers/binding/binding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -167,7 +169,7 @@
func (c *ResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&workv1alpha2.ResourceBinding{}).
For(&workv1alpha2.ResourceBinding{}, builder.WithPredicates(bindingPredicateFn)).
WithEventFilter(predicate.GenerationChangedPredicate{}).
Watches(&policyv1alpha1.OverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Expand Down Expand Up @@ -228,3 +230,28 @@
return requests
}
}

var bindingPredicateFn = predicate.Funcs{
CreateFunc: func(tce event.TypedCreateEvent[client.Object]) bool {
binding, ok := tce.Object.(*workv1alpha2.ResourceBinding)
if !ok {
return false
}
return binding.Status.SchedulerObservedGeneration == binding.Generation
},
UpdateFunc: func(tue event.TypedUpdateEvent[client.Object]) bool {
newBinding, ok := tue.ObjectNew.(*workv1alpha2.ResourceBinding)
if !ok {
return false
}
_, ok = tue.ObjectOld.(*workv1alpha2.ResourceBinding)
if !ok {
return false
}

return newBinding.Status.SchedulerObservedGeneration == newBinding.Generation
},
DeleteFunc: func(tde event.TypedDeleteEvent[client.Object]) bool {

Check failure on line 254 in pkg/controllers/binding/binding_controller.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'tde' seems to be unused, consider removing or renaming it as _ (revive)
return true
},
}
29 changes: 28 additions & 1 deletion pkg/controllers/binding/cluster_resource_binding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -163,7 +165,7 @@
func (c *ClusterResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).
Named(ClusterResourceBindingControllerName).
For(&workv1alpha2.ClusterResourceBinding{}).
For(&workv1alpha2.ClusterResourceBinding{}, builder.WithPredicates(clusterResourceBindingPredicateFn)).
Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
WithEventFilter(predicate.GenerationChangedPredicate{}).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter[controllerruntime.Request](c.RateLimiterOptions)}).
Expand Down Expand Up @@ -214,3 +216,28 @@
return requests
}
}

var clusterResourceBindingPredicateFn = predicate.Funcs{
CreateFunc: func(tce event.TypedCreateEvent[client.Object]) bool {
crBinding, ok := tce.Object.(*workv1alpha2.ClusterResourceBinding)
if !ok {
return false
}
return crBinding.Status.SchedulerObservedGeneration == crBinding.Generation
},
UpdateFunc: func(tue event.TypedUpdateEvent[client.Object]) bool {
newBinding, ok := tue.ObjectNew.(*workv1alpha2.ClusterResourceBinding)
if !ok {
return false
}
_, ok = tue.ObjectOld.(*workv1alpha2.ClusterResourceBinding)
if !ok {
return false
}

return newBinding.Status.SchedulerObservedGeneration == newBinding.Generation
},
DeleteFunc: func(tde event.TypedDeleteEvent[client.Object]) bool {

Check failure on line 240 in pkg/controllers/binding/cluster_resource_binding_controller.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'tde' seems to be unused, consider removing or renaming it as _ (revive)
return true
},
}
Loading