diff --git a/cmd/controller-manager/app/controllermanager.go b/cmd/controller-manager/app/controllermanager.go index aa5131d18..c03e3c627 100644 --- a/cmd/controller-manager/app/controllermanager.go +++ b/cmd/controller-manager/app/controllermanager.go @@ -198,7 +198,7 @@ func startClusterStatusController(ctx controllerscontext.Context) (enabled bool, ClusterLeaseDuration: opts.ClusterLeaseDuration, ClusterLeaseRenewIntervalFraction: opts.ClusterLeaseRenewIntervalFraction, ClusterCacheSyncTimeout: opts.ClusterCacheSyncTimeout, - RatelimiterOptions: ctx.Opts.RatelimiterOptions, + RateLimiterOptions: ctx.Opts.RateLimiterOptions, } if err := clusterStatusController.SetupWithManager(mgr); err != nil { return false, err @@ -229,7 +229,7 @@ func startBindingController(ctx controllerscontext.Context) (enabled bool, err e OverrideManager: ctx.OverrideManager, InformerManager: ctx.ControlPlaneInformerManager, ResourceInterpreter: ctx.ResourceInterpreter, - RatelimiterOptions: ctx.Opts.RatelimiterOptions, + RateLimiterOptions: ctx.Opts.RateLimiterOptions, } if err := bindingController.SetupWithManager(ctx.Mgr); err != nil { return false, err @@ -243,7 +243,7 @@ func startBindingController(ctx controllerscontext.Context) (enabled bool, err e OverrideManager: ctx.OverrideManager, InformerManager: ctx.ControlPlaneInformerManager, ResourceInterpreter: ctx.ResourceInterpreter, - RatelimiterOptions: ctx.Opts.RatelimiterOptions, + RateLimiterOptions: ctx.Opts.RateLimiterOptions, } if err := clusterResourceBindingController.SetupWithManager(ctx.Mgr); err != nil { return false, err @@ -260,7 +260,7 @@ func startExecutionController(ctx controllerscontext.Context) (enabled bool, err PredicateFunc: helper.NewExecutionPredicate(ctx.Mgr), InformerManager: informermanager.GetInstance(), ClusterClientSetFunc: util.NewClusterDynamicClientSet, - RatelimiterOption: ctx.Opts.RatelimiterOptions, + RatelimiterOption: ctx.Opts.RateLimiterOptions, } if err := executionController.SetupWithManager(ctx.Mgr); err != nil { return false, err @@ -281,7 +281,7 @@ func startWorkStatusController(ctx controllerscontext.Context) (enabled bool, er ClusterClientSetFunc: util.NewClusterDynamicClientSet, ClusterCacheSyncTimeout: opts.ClusterCacheSyncTimeout, ConcurrentWorkStatusSyncs: opts.ConcurrentWorkSyncs, - RatelimiterOptions: ctx.Opts.RatelimiterOptions, + RateLimiterOptions: ctx.Opts.RateLimiterOptions, } workStatusController.RunWorkQueue() if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil { @@ -410,7 +410,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop } objectWatcher := objectwatcher.NewObjectWatcher(mgr.GetClient(), mgr.GetRESTMapper(), util.NewClusterDynamicClientSet, resourceInterpreter) - ratelimiterOptions := ratelimiter.Options{ + rateLimiterOptions := ratelimiter.Options{ BaseDelay: opts.RateLimiterBaseDelay, MaxDelay: opts.RateLimiterMaxDelay, QPS: opts.RateLimiterQPS, @@ -428,7 +428,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop EventRecorder: mgr.GetEventRecorderFor("resource-detector"), ConcurrentResourceTemplateSyncs: opts.ConcurrentResourceTemplateSyncs, ConcurrentResourceBindingSyncs: opts.ConcurrentResourceBindingSyncs, - RatelimiterOptions: ratelimiterOptions, + RateLimiterOptions: rateLimiterOptions, } if err := mgr.Add(resourceDetector); err != nil { klog.Fatalf("Failed to setup resource detector: %v", err) @@ -464,7 +464,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop ClusterAPIBurst: opts.ClusterAPIBurst, SkippedPropagatingNamespaces: opts.SkippedPropagatingNamespaces, ConcurrentWorkSyncs: opts.ConcurrentWorkSyncs, - RatelimiterOptions: ratelimiterOptions, + RateLimiterOptions: rateLimiterOptions, }, StopChan: stopChan, DynamicClientSet: dynamicClientSet, diff --git a/pkg/controllers/binding/binding_controller.go b/pkg/controllers/binding/binding_controller.go index 8cc61d9bf..8f8c2d9e7 100644 --- a/pkg/controllers/binding/binding_controller.go +++ b/pkg/controllers/binding/binding_controller.go @@ -49,7 +49,7 @@ type ResourceBindingController struct { RESTMapper meta.RESTMapper OverrideManager overridemanager.OverrideManager ResourceInterpreter resourceinterpreter.ResourceInterpreter - RatelimiterOptions ratelimiter.Options + RateLimiterOptions ratelimiter.Options } // Reconcile performs a full reconciliation for the object referred to by the Request. @@ -221,7 +221,7 @@ func (c *ResourceBindingController) SetupWithManager(mgr controllerruntime.Manag Watches(&source.Kind{Type: &policyv1alpha1.OverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). Watches(&source.Kind{Type: &policyv1alpha1.ClusterOverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). WithOptions(controller.Options{ - RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RatelimiterOptions), + RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RateLimiterOptions), }). Complete(c) } diff --git a/pkg/controllers/binding/cluster_resource_binding_controller.go b/pkg/controllers/binding/cluster_resource_binding_controller.go index f353052a9..0f0d950cf 100644 --- a/pkg/controllers/binding/cluster_resource_binding_controller.go +++ b/pkg/controllers/binding/cluster_resource_binding_controller.go @@ -44,7 +44,7 @@ type ClusterResourceBindingController struct { RESTMapper meta.RESTMapper OverrideManager overridemanager.OverrideManager ResourceInterpreter resourceinterpreter.ResourceInterpreter - RatelimiterOptions ratelimiter.Options + RateLimiterOptions ratelimiter.Options } // Reconcile performs a full reconciliation for the object referred to by the Request. @@ -162,7 +162,7 @@ func (c *ClusterResourceBindingController) SetupWithManager(mgr controllerruntim Watches(&source.Kind{Type: &policyv1alpha1.OverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). Watches(&source.Kind{Type: &policyv1alpha1.ClusterOverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). WithOptions(controller.Options{ - RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RatelimiterOptions), + RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RateLimiterOptions), }). Complete(c) } diff --git a/pkg/controllers/context/context.go b/pkg/controllers/context/context.go index 42f9ccd03..43be31d83 100644 --- a/pkg/controllers/context/context.go +++ b/pkg/controllers/context/context.go @@ -50,7 +50,7 @@ type Options struct { ClusterName string // ConcurrentWorkSyncs is the number of Works that are allowed to sync concurrently. ConcurrentWorkSyncs int - RatelimiterOptions ratelimiter.Options + RateLimiterOptions ratelimiter.Options } // Context defines the context object for controller. diff --git a/pkg/controllers/status/cluster_status_controller.go b/pkg/controllers/status/cluster_status_controller.go index a3f8f6fb1..6fc4de1fc 100644 --- a/pkg/controllers/status/cluster_status_controller.go +++ b/pkg/controllers/status/cluster_status_controller.go @@ -84,7 +84,7 @@ type ClusterStatusController struct { ClusterLeaseControllers sync.Map ClusterCacheSyncTimeout metav1.Duration - RatelimiterOptions ratelimiter.Options + RateLimiterOptions ratelimiter.Options } // Reconcile syncs status of the given member cluster. @@ -117,7 +117,7 @@ func (c *ClusterStatusController) Reconcile(ctx context.Context, req controllerr // SetupWithManager creates a controller and register to controller manager. func (c *ClusterStatusController) SetupWithManager(mgr controllerruntime.Manager) error { return controllerruntime.NewControllerManagedBy(mgr).For(&clusterv1alpha1.Cluster{}).WithEventFilter(c.PredicateFunc).WithOptions(controller.Options{ - RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RatelimiterOptions), + RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RateLimiterOptions), }).Complete(c) } diff --git a/pkg/controllers/status/workstatus_controller.go b/pkg/controllers/status/workstatus_controller.go index 74f609d2b..0da382cde 100644 --- a/pkg/controllers/status/workstatus_controller.go +++ b/pkg/controllers/status/workstatus_controller.go @@ -49,7 +49,7 @@ type WorkStatusController struct { PredicateFunc predicate.Predicate ClusterClientSetFunc func(clusterName string, client client.Client) (*util.DynamicClusterClient, error) ClusterCacheSyncTimeout metav1.Duration - RatelimiterOptions ratelimiter.Options + RateLimiterOptions ratelimiter.Options } // Reconcile performs a full reconciliation for the object referred to by the Request. @@ -452,6 +452,6 @@ func (c *WorkStatusController) getSingleClusterManager(cluster *clusterv1alpha1. // SetupWithManager creates a controller and register to controller manager. func (c *WorkStatusController) SetupWithManager(mgr controllerruntime.Manager) error { return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha1.Work{}).WithEventFilter(c.PredicateFunc).WithOptions(controller.Options{ - RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RatelimiterOptions), + RateLimiter: ratelimiter.DefaultControllerRateLimiter(c.RateLimiterOptions), }).Complete(c) } diff --git a/pkg/detector/detector.go b/pkg/detector/detector.go index b0566fda8..803dcdfac 100644 --- a/pkg/detector/detector.go +++ b/pkg/detector/detector.go @@ -77,7 +77,10 @@ type ResourceDetector struct { // ConcurrentResourceBindingSyncs is the number of ResourceBinding that are allowed to sync concurrently. // Larger number means responsive resource template syncing but more CPU(and network) load. ConcurrentResourceBindingSyncs int - RatelimiterOptions ratelimiter.Options + + // RateLimiterOptions is the configuration for rate limiter which may significantly influence the performance of + // the controller. + RateLimiterOptions ratelimiter.Options stopCh <-chan struct{} } @@ -128,7 +131,7 @@ func (d *ResourceDetector) Start(ctx context.Context) error { Name: "resource detector", KeyFunc: ClusterWideKeyFunc, ReconcileFunc: d.Reconcile, - RatelimiterOptions: d.RatelimiterOptions, + RateLimiterOptions: d.RateLimiterOptions, } d.EventHandler = informermanager.NewFilteringHandlerOnAllEvents(d.EventFilter, d.OnAdd, d.OnUpdate, d.OnDelete) diff --git a/pkg/util/ratelimiter/rate_limiter.go b/pkg/util/ratelimiter/rate_limiter.go index 7a5c3f47b..f9df808e3 100644 --- a/pkg/util/ratelimiter/rate_limiter.go +++ b/pkg/util/ratelimiter/rate_limiter.go @@ -7,7 +7,7 @@ import ( "k8s.io/client-go/util/workqueue" ) -// Options are options for ratelimiter +// Options are options for rate limiter. type Options struct { BaseDelay time.Duration MaxDelay time.Duration diff --git a/pkg/util/worker.go b/pkg/util/worker.go index 49d11d511..cff7fd218 100644 --- a/pkg/util/worker.go +++ b/pkg/util/worker.go @@ -64,7 +64,7 @@ type Options struct { Name string KeyFunc KeyFunc ReconcileFunc ReconcileFunc - RatelimiterOptions ratelimiter.Options + RateLimiterOptions ratelimiter.Options } // NewAsyncWorker returns a asyncWorker which can process resource periodic. @@ -72,7 +72,7 @@ func NewAsyncWorker(opt Options) AsyncWorker { return &asyncWorker{ keyFunc: opt.KeyFunc, reconcileFunc: opt.ReconcileFunc, - queue: workqueue.NewNamedRateLimitingQueue(ratelimiter.DefaultControllerRateLimiter(opt.RatelimiterOptions), opt.Name), + queue: workqueue.NewNamedRateLimitingQueue(ratelimiter.DefaultControllerRateLimiter(opt.RateLimiterOptions), opt.Name), } }