Skip to content

Commit

Permalink
Merge pull request #1089 from yue9944882/client-go-generic-interface-pt0
Browse files Browse the repository at this point in the history
Use typed client-go constructors for rate-limit related objects
  • Loading branch information
k8s-ci-robot authored Jan 14, 2025
2 parents 28b2e0b + e82a4f0 commit bf18a51
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pkg/controllers/tagging/tagging_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,32 @@ func NewTaggingController(
return nil, err
}

var rateLimiter workqueue.RateLimiter
var rateLimiter workqueue.TypedRateLimiter[any]
var rateLimitEnabled bool
if rateLimit > 0.0 && burstLimit > 0 {
klog.Infof("Rate limit enabled on controller with rate %f and burst %d.", rateLimit, burstLimit)
// This is the workqueue.DefaultControllerRateLimiter() but in case where throttling is enabled on the controller,
// the rate and burst values are set to the provided values.
rateLimiter = workqueue.NewMaxOfRateLimiter(
workqueue.NewItemExponentialFailureRateLimiter(5*time.Millisecond, 1000*time.Second),
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(rateLimit), burstLimit)},
rateLimiter = workqueue.NewTypedMaxOfRateLimiter(
workqueue.NewTypedItemExponentialFailureRateLimiter[any](5*time.Millisecond, 1000*time.Second),
&workqueue.TypedBucketRateLimiter[any]{Limiter: rate.NewLimiter(rate.Limit(rateLimit), burstLimit)},
)
rateLimitEnabled = true
} else {
klog.Infof("Rate limit disabled on controller.")
rateLimiter = workqueue.DefaultControllerRateLimiter()
rateLimiter = workqueue.DefaultTypedControllerRateLimiter[any]()
rateLimitEnabled = false
}

tc := &Controller{
nodeInformer: nodeInformer,
kubeClient: kubeClient,
cloud: awsCloud,
tags: tags,
resources: resources,
workqueue: workqueue.NewNamedRateLimitingQueue(rateLimiter, TaggingControllerClientName),
nodeInformer: nodeInformer,
kubeClient: kubeClient,
cloud: awsCloud,
tags: tags,
resources: resources,
workqueue: workqueue.NewTypedRateLimitingQueueWithConfig[any](rateLimiter, workqueue.TypedRateLimitingQueueConfig[any]{
Name: TaggingControllerClientName,
}),
nodesSynced: nodeInformer.Informer().HasSynced,
nodeMonitorPeriod: nodeMonitorPeriod,
rateLimitEnabled: rateLimitEnabled,
Expand Down

0 comments on commit bf18a51

Please sign in to comment.