Repository: kubernetes/kubernetes
File: staging/src/k8s.io/cloud-provider/controllers/route/route_controller.go (Go)

Code before:

func New(
	routes cloudprovider.Routes,
	kubeClient clientset.Interface,
	nodeInformer coreinformers.NodeInformer,
	clusterName string,
	clusterCIDRs []*net.IPNet,
) (*RouteController, error) {
	if len(clusterCIDRs) == 0 {
		klog.Fatal("RouteController: Must specify clusterCIDR.")
	}

	rc := &RouteController{
		routes:           routes,
		kubeClient:       kubeClient,
		clusterName:      clusterName,
		clusterCIDRs:     clusterCIDRs,
		nodeInformer:     nodeInformer,
		nodeLister:       nodeInformer.Lister(),
		nodeListerSynced: nodeInformer.Informer().HasSynced,
	}

	if utilfeature.DefaultFeatureGate.Enabled(features.CloudControllerManagerWatchBasedRoutesReconciliation) {
		// We use [TypedWithMaxWaitRateLimiter] to cap the [TypedBucketRateLimiter] at 10 seconds.
		// Without this cap, the bucket rate limiter would keep accumulating delay for each node event.
		// With the cap, even under a constant stream of node events, reconciles happen at most every
		// 10 seconds — either triggered immediately or queued for another run if one is already in progress.
		bucketRateLimiter := &workqueue.TypedBucketRateLimiter[string]{Limiter: rate.NewLimiter(rate.Every(minRouteResyncInterval), 1)}
		rc.workqueue = workqueue.NewTypedRateLimitingQueueWithConfig(
			workqueue.NewTypedWithMaxWaitRateLimiter[string](bucketRateLimiter, minRouteResyncInterval),
			workqueue.TypedRateLimitingQueueConfig[string]{Name: "Routes"},
		)

		_, err := rc.nodeInformer.Informer().AddEventHandler(
			// It is only necessary to reconcile the routes for any events that have the potential to impact them:
			// - Node is added
			// - Node is removed
			// - Node .Status.Addresses is changed
			// - Node .Spec.PodCIDRs is changed
			cache.ResourceEventHandlerFuncs{
				AddFunc:    rc.enqueueReconcile,
				UpdateFunc: rc.handleNodeUpdate,
				DeleteFunc: rc.enqueueReconcile,
			},
		)
		if err != nil {
			return nil, err
		}
	}

	return rc, nil

Review comment (refactor):
hmm, I'm a bit fuzzy on the details, but it kind of seems that you want to implement the logic we have for kube-proxy, with a bounded frequency runner , instead of the workqueue https://github.com/kubernetes/kubernetes/pull/131615

So you collapse all events during one defined period, and ensure that new events are executed later after that period, so you don't need even a workqueue, just the runner 
https://github.com/kubernetes/kubernetes/blob/afb2b97425317948e9e59b2a7871fca5bbb2ab08/pkg/proxy/runner/bounded_frequency_runner.go#L44-L64 

but we may have to move it to a shared place, like components-base or components-helpers https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/component-helpers

Code after:
func New(
	routes cloudprovider.Routes,
	kubeClient clientset.Interface,
	nodeInformer coreinformers.NodeInformer,
	clusterName string,
	clusterCIDRs []*net.IPNet,
) (*RouteController, error) {
	if len(clusterCIDRs) == 0 {
		klog.Fatal("RouteController: Must specify clusterCIDR.")
	}

	rc := &RouteController{
		routes:           routes,
		kubeClient:       kubeClient,
		clusterName:      clusterName,
		clusterCIDRs:     clusterCIDRs,
		nodeInformer:     nodeInformer,
		nodeLister:       nodeInformer.Lister(),
		nodeListerSynced: nodeInformer.Informer().HasSynced,
	}

	if utilfeature.DefaultFeatureGate.Enabled(features.CloudControllerManagerWatchBasedRoutesReconciliation) {
		// We use [TypedWithMaxWaitRateLimiter] to cap the [TypedBucketRateLimiter] at 10 seconds.
		// Without this cap, the bucket rate limiter would keep accumulating delay for each node event.
		// With the cap, even under a constant stream of node events, reconciles happen at most every
		// 10 seconds — either triggered immediately or queued for another run if one is already in progress.
		bucketRateLimiter := &workqueue.TypedBucketRateLimiter[string]{Limiter: rate.NewLimiter(rate.Every(minRouteResyncInterval), 1)}
		rc.workqueue = workqueue.NewTypedRateLimitingQueueWithConfig(
			workqueue.NewTypedWithMaxWaitRateLimiter[string](bucketRateLimiter, minRouteResyncInterval),
			workqueue.TypedRateLimitingQueueConfig[string]{Name: "Routes"},
		)

		_, err := rc.nodeInformer.Informer().AddEventHandler(
			// It is only necessary to reconcile the routes for any events that have the potential to impact them:
			// - Node is added
			// - Node is removed
			// - Node .Status.Addresses is changed
			// - Node .Spec.PodCIDRs is changed
			cache.ResourceEventHandlerFuncs{
				AddFunc:    rc.enqueueClusterReconcile,
				UpdateFunc: rc.handleNodeUpdate,
				DeleteFunc: rc.enqueueClusterReconcile,
			},
		)
		if err != nil {
			return nil, err
		}
	}

	return rc, nil
}