Skip to content

Commit 894a1a2

Browse files
Update tests, remove unnecessary infers
1 parent a8aa423 commit 894a1a2

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

controllers/operator/mongodbreplicaset_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ func AddReplicaSetController(ctx context.Context, mgr manager.Manager, imageUrls
360360
// watch for changes to replica set MongoDB resources
361361
eventHandler := ResourceEventHandler{deleter: reconciler}
362362
// Watch for changes to primary resource MongoDbReplicaSet
363-
err = c.Watch(source.Kind[client.Object](mgr.GetCache(), &mdbv1.MongoDB{}, &eventHandler, watch.PredicatesForMongoDB[client.Object](mdbv1.ReplicaSet)))
363+
err = c.Watch(source.Kind[client.Object](mgr.GetCache(), &mdbv1.MongoDB{}, &eventHandler, watch.PredicatesForMongoDB(mdbv1.ReplicaSet)))
364364
if err != nil {
365365
return err
366366
}
367367

368-
err = c.Watch(source.Channel[client.Object](OmUpdateChannel, &handler.EnqueueRequestForObject{}, source.WithPredicates[client.Object, reconcile.Request](watch.PredicatesForMongoDB[client.Object](mdbv1.ReplicaSet))))
368+
err = c.Watch(source.Channel(OmUpdateChannel, &handler.EnqueueRequestForObject{}, source.WithPredicates[client.Object, reconcile.Request](watch.PredicatesForMongoDB(mdbv1.ReplicaSet))))
369369
if err != nil {
370370
return xerrors.Errorf("not able to setup OmUpdateChannel to listent to update events from OM: %s", err)
371371
}

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"k8s.io/apimachinery/pkg/types"
1111
"k8s.io/client-go/util/workqueue"
1212
"sigs.k8s.io/controller-runtime/pkg/client"
13-
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
1413
"sigs.k8s.io/controller-runtime/pkg/event"
1514
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1615

@@ -148,8 +147,8 @@ func TestMongoDBSearchReconcile_Success(t *testing.T) {
148147
err = c.Get(ctx, search.StatefulSetNamespacedName(), sts)
149148
assert.NoError(t, err)
150149

151-
queue := controllertest.Queue{Interface: workqueue.New()}
152-
reconciler.mdbcWatcher.Create(ctx, event.CreateEvent{Object: mdbc}, &queue)
150+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
151+
reconciler.mdbcWatcher.Create(ctx, event.CreateEvent{Object: mdbc}, queue)
153152
assert.Equal(t, 1, queue.Len())
154153
}
155154

controllers/operator/mongodbshardedcluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,12 +1651,12 @@ func AddShardedClusterController(ctx context.Context, mgr manager.Manager, image
16511651

16521652
// watch for changes to sharded cluster MongoDB resources
16531653
eventHandler := ResourceEventHandler{deleter: reconciler}
1654-
err = c.Watch(source.Kind[client.Object](mgr.GetCache(), &mdbv1.MongoDB{}, &eventHandler, watch.PredicatesForMongoDB[client.Object](mdbv1.ShardedCluster)))
1654+
err = c.Watch(source.Kind[client.Object](mgr.GetCache(), &mdbv1.MongoDB{}, &eventHandler, watch.PredicatesForMongoDB(mdbv1.ShardedCluster)))
16551655
if err != nil {
16561656
return err
16571657
}
16581658

1659-
err = c.Watch(source.Channel[client.Object](OmUpdateChannel, &handler.EnqueueRequestForObject{}, source.WithPredicates[client.Object, reconcile.Request](watch.PredicatesForMongoDB[client.Object](mdbv1.ShardedCluster))))
1659+
err = c.Watch(source.Channel(OmUpdateChannel, &handler.EnqueueRequestForObject{}, source.WithPredicates[client.Object, reconcile.Request](watch.PredicatesForMongoDB(mdbv1.ShardedCluster))))
16601660
if err != nil {
16611661
return xerrors.Errorf("not able to setup OmUpdateChannel to listent to update events from OM: %s", err)
16621662
}

controllers/operator/mongodbstandalone_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ func AddStandaloneController(ctx context.Context, mgr manager.Manager, imageUrls
6161

6262
// watch for changes to standalone MongoDB resources
6363
eventHandler := ResourceEventHandler{deleter: reconciler}
64-
err = c.Watch(source.Kind[client.Object](mgr.GetCache(), &mdbv1.MongoDB{}, &eventHandler, watch.PredicatesForMongoDB[client.Object](mdbv1.Standalone)))
64+
err = c.Watch(source.Kind[client.Object](mgr.GetCache(), &mdbv1.MongoDB{}, &eventHandler, watch.PredicatesForMongoDB(mdbv1.Standalone)))
6565
if err != nil {
6666
return err
6767
}
6868

6969
err = c.Watch(
70-
source.Channel[client.Object](OmUpdateChannel,
70+
source.Channel(OmUpdateChannel,
7171
&handler.EnqueueRequestForObject{},
72-
source.WithPredicates[client.Object, reconcile.Request](watch.PredicatesForMongoDB[client.Object](mdbv1.Standalone)),
72+
source.WithPredicates[client.Object, reconcile.Request](watch.PredicatesForMongoDB(mdbv1.Standalone)),
7373
))
7474
if err != nil {
7575
return xerrors.Errorf("not able to setup OmUpdateChannel to listent to update events from OM: %s", err)

controllers/operator/watch/predicates.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package watch
33
import (
44
"reflect"
55

6-
"sigs.k8s.io/controller-runtime/pkg/client"
76
"sigs.k8s.io/controller-runtime/pkg/event"
87
"sigs.k8s.io/controller-runtime/pkg/predicate"
98

@@ -75,7 +74,7 @@ func PredicatesForOpsManager() predicate.Funcs {
7574
}
7675
}
7776

78-
func PredicatesForMongoDB[T client.Object](resourceType mdbv1.ResourceType) predicate.Funcs {
77+
func PredicatesForMongoDB(resourceType mdbv1.ResourceType) predicate.Funcs {
7978
return predicate.Funcs{
8079
CreateFunc: func(createEvent event.CreateEvent) bool {
8180
resource := createEvent.Object.(*mdbv1.MongoDB)

mongodb-community-operator/controllers/watch/watch_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/stretchr/testify/assert"
88
"k8s.io/apimachinery/pkg/types"
99
"k8s.io/client-go/util/workqueue"
10-
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
1110
"sigs.k8s.io/controller-runtime/pkg/event"
11+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1212

1313
corev1 "k8s.io/api/core/v1"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -42,75 +42,75 @@ func TestWatcher(t *testing.T) {
4242

4343
t.Run("Non-watched object", func(t *testing.T) {
4444
watcher := New()
45-
queue := controllertest.Queue{Interface: workqueue.New()}
45+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
4646

4747
watcher.Create(ctx, event.CreateEvent{
4848
Object: obj,
49-
}, &queue)
49+
}, queue)
5050

5151
// Ensure no reconciliation is queued if object is not watched.
5252
assert.Equal(t, 0, queue.Len())
5353
})
5454

5555
t.Run("Multiple objects to reconcile", func(t *testing.T) {
5656
watcher := New()
57-
queue := controllertest.Queue{Interface: workqueue.New()}
57+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
5858
watcher.Watch(ctx, objNsName, mdb1.NamespacedName())
5959
watcher.Watch(ctx, objNsName, mdb2.NamespacedName())
6060

6161
watcher.Create(ctx, event.CreateEvent{
6262
Object: obj,
63-
}, &queue)
63+
}, queue)
6464

6565
// Ensure multiple reconciliations are enqueued.
6666
assert.Equal(t, 2, queue.Len())
6767
})
6868

6969
t.Run("Create event", func(t *testing.T) {
7070
watcher := New()
71-
queue := controllertest.Queue{Interface: workqueue.New()}
71+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
7272
watcher.Watch(ctx, objNsName, mdb1.NamespacedName())
7373

7474
watcher.Create(ctx, event.CreateEvent{
7575
Object: obj,
76-
}, &queue)
76+
}, queue)
7777

7878
assert.Equal(t, 1, queue.Len())
7979
})
8080

8181
t.Run("Update event", func(t *testing.T) {
8282
watcher := New()
83-
queue := controllertest.Queue{Interface: workqueue.New()}
83+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
8484
watcher.Watch(ctx, objNsName, mdb1.NamespacedName())
8585

8686
watcher.Update(ctx, event.UpdateEvent{
8787
ObjectOld: obj,
8888
ObjectNew: obj,
89-
}, &queue)
89+
}, queue)
9090

9191
assert.Equal(t, 1, queue.Len())
9292
})
9393

9494
t.Run("Delete event", func(t *testing.T) {
9595
watcher := New()
96-
queue := controllertest.Queue{Interface: workqueue.New()}
96+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
9797
watcher.Watch(ctx, objNsName, mdb1.NamespacedName())
9898

9999
watcher.Delete(ctx, event.DeleteEvent{
100100
Object: obj,
101-
}, &queue)
101+
}, queue)
102102

103103
assert.Equal(t, 1, queue.Len())
104104
})
105105

106106
t.Run("Generic event", func(t *testing.T) {
107107
watcher := New()
108-
queue := controllertest.Queue{Interface: workqueue.New()}
108+
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[reconcile.Request]())
109109
watcher.Watch(ctx, objNsName, mdb1.NamespacedName())
110110

111111
watcher.Generic(ctx, event.GenericEvent{
112112
Object: obj,
113-
}, &queue)
113+
}, queue)
114114

115115
assert.Equal(t, 1, queue.Len())
116116
})

0 commit comments

Comments
 (0)