Skip to content

Commit ec9a3d6

Browse files
committed
Use TypedRateLimitingInterface to replace deprecated RateLimiter
Signed-off-by: Jian Qiu <jqiu@redhat.com>
1 parent 68bb7fc commit ec9a3d6

8 files changed

Lines changed: 37 additions & 24 deletions

File tree

pkg/basecontroller/factory/base_controller.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@ func (c *baseController) processNextWorkItem(queueCtx context.Context) {
147147
defer c.syncContext.Queue().Done(key)
148148

149149
syncCtx := c.syncContext.(syncContext)
150-
var ok bool
151-
queueKey, ok := key.(string)
152-
if !ok {
153-
utilruntime.HandleError(fmt.Errorf("%q controller failed to process key %q (not a string)", c.name, key))
154-
return
155-
}
150+
queueKey := key
156151

157152
if err := c.sync(queueCtx, syncCtx, queueKey); err != nil {
158153
if klog.V(4).Enabled() || key != "key" {

pkg/basecontroller/factory/controller_context.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ import (
1212
// syncContext implements SyncContext and provide user access to queue and object that caused
1313
// the sync to be triggered.
1414
type syncContext struct {
15-
queue workqueue.RateLimitingInterface // nolint:staticcheck // SA1019
15+
queue workqueue.TypedRateLimitingInterface[string]
1616
}
1717

1818
var _ SyncContext = syncContext{}
1919

2020
// NewSyncContext gives new sync context.
2121
func NewSyncContext(name string) SyncContext {
2222
return syncContext{
23-
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), name), // nolint:staticcheck // SA1019
23+
queue: workqueue.NewTypedRateLimitingQueueWithConfig(
24+
workqueue.DefaultTypedControllerRateLimiter[string](),
25+
workqueue.TypedRateLimitingQueueConfig[string]{Name: name},
26+
),
2427
}
2528
}
2629

27-
func (c syncContext) Queue() workqueue.RateLimitingInterface { // nolint:staticcheck // SA1019
30+
func (c syncContext) Queue() workqueue.TypedRateLimitingInterface[string] {
2831
return c.queue
2932
}
3033

pkg/basecontroller/factory/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Controller interface {
3333
type SyncContext interface {
3434
// Queue gives access to controller queue. This can be used for manual requeue, although if a Sync() function return
3535
// an error, the object is automatically re-queued. Use with caution.
36-
Queue() workqueue.RateLimitingInterface // nolint:staticcheck // SA1019
36+
Queue() workqueue.TypedRateLimitingInterface[string]
3737
}
3838

3939
// SyncFunc is a function that contain main controller logic.

pkg/cloudevents/clients/work/garbagecollector/garbagecollector.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type GarbageCollector struct {
6666
// each monitor list/watches a resource (including manifestwork)
6767
monitors monitors
6868
// garbage collector attempts to delete the items in attemptToDelete queue when the time is ripe.
69-
attemptToDelete workqueue.RateLimitingInterface // nolint:staticcheck // SA1019
69+
attemptToDelete workqueue.TypedRateLimitingInterface[*dependent]
7070
}
7171

7272
// NewGarbageCollector creates a new garbage collector instance.
@@ -89,7 +89,10 @@ func NewGarbageCollector(
8989
workInformer: workInformer,
9090
metadataClient: metadataClient,
9191
ownerGVRFilters: ownerGVRFilters,
92-
attemptToDelete: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "garbage_collector_attempt_to_delete"), // nolint:staticcheck // SA1019
92+
attemptToDelete: workqueue.NewTypedRateLimitingQueueWithConfig(
93+
workqueue.DefaultTypedControllerRateLimiter[*dependent](),
94+
workqueue.TypedRateLimitingQueueConfig[*dependent]{Name: "garbage_collector_attempt_to_delete"},
95+
),
9396
}
9497
}
9598

pkg/cloudevents/clients/work/garbagecollector/garbagecollector_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ func TestProcessManifestWorkEvent(t *testing.T) {
8383
utilruntime.HandleError(fmt.Errorf("failed to add indexers: %v", err))
8484
}
8585
gc := &GarbageCollector{
86-
workClient: fakeWorkClient.WorkV1(),
87-
workIndexer: fakeWorkInformer.Informer().GetIndexer(),
88-
workInformer: fakeWorkInformer,
89-
metadataClient: metadataClient,
90-
attemptToDelete: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "garbage_collector_attempt_to_delete"), // nolint:staticcheck // SA1019
86+
workClient: fakeWorkClient.WorkV1(),
87+
workIndexer: fakeWorkInformer.Informer().GetIndexer(),
88+
workInformer: fakeWorkInformer,
89+
metadataClient: metadataClient,
90+
attemptToDelete: workqueue.NewTypedRateLimitingQueueWithConfig(
91+
workqueue.DefaultTypedControllerRateLimiter[*dependent](),
92+
workqueue.TypedRateLimitingQueueConfig[*dependent]{Name: "garbage_collector_attempt_to_delete"},
93+
),
9194
}
9295
go fakeWorkInformer.Informer().Run(ctx.Done())
9396
if !cache.WaitForCacheSync(ctx.Done(), fakeWorkInformer.Informer().HasSynced) {
@@ -223,7 +226,10 @@ func setupGC(t *testing.T, config *rest.Config) *GarbageCollector {
223226
workInformer: workInformer.Work().V1().ManifestWorks(),
224227
metadataClient: metadataClient,
225228
ownerGVRFilters: ownerGVRFilters,
226-
attemptToDelete: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "garbage_collector_attempt_to_delete"), // nolint:staticcheck // SA1019
229+
attemptToDelete: workqueue.NewTypedRateLimitingQueueWithConfig(
230+
workqueue.DefaultTypedControllerRateLimiter[*dependent](),
231+
workqueue.TypedRateLimitingQueueConfig[*dependent]{Name: "garbage_collector_attempt_to_delete"},
232+
),
227233
}
228234
}
229235

pkg/cloudevents/clients/work/store/base.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type baseSourceStore struct {
2424
store.BaseClientWatchStore[*workv1.ManifestWork]
2525

2626
// a queue to save the received work events
27-
receivedWorks workqueue.RateLimitingInterface // nolint:staticcheck // SA1019
27+
receivedWorks workqueue.TypedRateLimitingInterface[*workv1.ManifestWork]
2828
}
2929

3030
func (bs *baseSourceStore) HandleReceivedResource(action types.ResourceAction, work *workv1.ManifestWork) error {
@@ -39,11 +39,11 @@ func (bs *baseSourceStore) HandleReceivedResource(action types.ResourceAction, w
3939

4040
// workProcessor process the received works from given work queue with a specific store
4141
type workProcessor struct {
42-
works workqueue.RateLimitingInterface // nolint:staticcheck // SA1019
42+
works workqueue.TypedRateLimitingInterface[*workv1.ManifestWork]
4343
store store.ClientWatcherStore[*workv1.ManifestWork]
4444
}
4545

46-
func newWorkProcessor(works workqueue.RateLimitingInterface, store store.ClientWatcherStore[*workv1.ManifestWork]) *workProcessor { // nolint:staticcheck // SA1019
46+
func newWorkProcessor(works workqueue.TypedRateLimitingInterface[*workv1.ManifestWork], store store.ClientWatcherStore[*workv1.ManifestWork]) *workProcessor {
4747
return &workProcessor{
4848
works: works,
4949
store: store,
@@ -79,7 +79,7 @@ func (b *workProcessor) processNextWork() bool {
7979
}
8080
defer b.works.Done(key)
8181

82-
if err := b.handleWork(key.(*workv1.ManifestWork)); err != nil {
82+
if err := b.handleWork(key); err != nil {
8383
// we failed to handle the work, we should requeue the item to work on later
8484
// this method will add a backoff to avoid hotlooping on particular items
8585
b.works.AddRateLimited(key)

pkg/cloudevents/clients/work/store/informer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ func NewSourceInformerWatcherStore(ctx context.Context) *SourceInformerWatcherSt
3434
s := &SourceInformerWatcherStore{
3535
baseSourceStore: baseSourceStore{
3636
BaseClientWatchStore: store.BaseClientWatchStore[*workv1.ManifestWork]{},
37-
receivedWorks: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "informer-watcher-store"), // nolint:staticcheck // SA1019
37+
receivedWorks: workqueue.NewTypedRateLimitingQueueWithConfig(
38+
workqueue.DefaultTypedControllerRateLimiter[*workv1.ManifestWork](),
39+
workqueue.TypedRateLimitingQueueConfig[*workv1.ManifestWork]{Name: "informer-watcher-store"},
40+
),
3841
},
3942
watcher: store.NewWatcher(),
4043
}

pkg/cloudevents/clients/work/store/local.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ func NewSourceLocalWatcherStore(ctx context.Context, listFunc ListLocalWorksFunc
6666

6767
// A queue to save the received work events, it helps us retry events
6868
// where errors occurred while processing
69-
receivedWorks: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "local-watcher-store"), // nolint:staticcheck // SA1019
69+
receivedWorks: workqueue.NewTypedRateLimitingQueueWithConfig(
70+
workqueue.DefaultTypedControllerRateLimiter[*workv1.ManifestWork](),
71+
workqueue.TypedRateLimitingQueueConfig[*workv1.ManifestWork]{Name: "local-watcher-store"},
72+
),
7073
},
7174

7275
watcher: store.NewWatcher(),

0 commit comments

Comments
 (0)