@@ -20,7 +20,9 @@ import (
2020 "context"
2121 "fmt"
2222 "sync"
23+ "time"
2324
25+ "golang.org/x/time/rate"
2426 "k8s.io/apimachinery/pkg/runtime"
2527 "k8s.io/client-go/util/workqueue"
2628 "k8s.io/klog/v2"
@@ -38,6 +40,24 @@ type WorkItem struct {
3840 Callback func (ctx context.Context , obj any ) error
3941}
4042
43+ // Return composite rate limiter that combines both per-item exponential backoff
44+ // and an overall token bucket rate-limiting strategy. It calculates the
45+ // exponential backoff for the individual item (based on its personal retry
46+ // history), checks the global rate against the token bucket, and picks the
47+ // longest delay from either strategy, ensuring that both per-item and overall
48+ // queue health are respected.
49+ func DefaultPrepUnprepRateLimiter () workqueue.TypedRateLimiter [any ] {
50+ return workqueue .NewTypedMaxOfRateLimiter (
51+ // This is a per-item exponential backoff limiter. Each time an item
52+ // fails and is retried, the delay grows exponentially starting from the
53+ // lower value up to the upper bound.
54+ workqueue .NewTypedItemExponentialFailureRateLimiter [any ](250 * time .Millisecond , 3000 * time .Second ),
55+ // Global (not per-item) rate limiter. Allows up to 5 retries per
56+ // second, with bursts of up to 10.
57+ & workqueue.TypedBucketRateLimiter [any ]{Limiter : rate .NewLimiter (rate .Limit (5 ), 10 )},
58+ )
59+ }
60+
4161func DefaultControllerRateLimiter () workqueue.TypedRateLimiter [any ] {
4262 return workqueue .DefaultTypedControllerRateLimiter [any ]()
4363}
0 commit comments