@@ -21,7 +21,6 @@ import (
2121
2222 "k8s.io/client-go/util/workqueue"
2323 "sigs.k8s.io/controller-runtime/pkg/client"
24- "sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue"
2524 "sigs.k8s.io/controller-runtime/pkg/event"
2625 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2726)
@@ -47,7 +46,7 @@ type TypedMapFunc[object any, request comparable] func(context.Context, object)
4746// For UpdateEvents which contain both a new and old object, the transformation function is run on both
4847// objects and both sets of Requests are enqueue.
4948func EnqueueRequestsFromMapFunc (fn MapFunc ) EventHandler {
50- return TypedEnqueueRequestsFromMapFunc (fn )
49+ return WithLowPriorityWhenUnchanged ( TypedEnqueueRequestsFromMapFunc (fn ) )
5150}
5251
5352// TypedEnqueueRequestsFromMapFunc enqueues Requests by running a transformation function that outputs a collection
@@ -82,12 +81,7 @@ func (e *enqueueRequestsFromMapFunc[object, request]) Create(
8281 q workqueue.TypedRateLimitingInterface [request ],
8382) {
8483 reqs := map [request ]empty {}
85- priorityQueue , isPriorityQueue := q .(priorityqueue.PriorityQueue [request ])
86- if ! isPriorityQueue {
87- e .mapAndEnqueue (ctx , q , evt .Object , reqs )
88- return
89- }
90- e .mapAndEnqueuePriorityCreate (ctx , priorityQueue , evt .Object , reqs )
84+ e .mapAndEnqueue (ctx , q , evt .Object , reqs )
9185}
9286
9387// Update implements EventHandler.
@@ -96,14 +90,9 @@ func (e *enqueueRequestsFromMapFunc[object, request]) Update(
9690 evt event.TypedUpdateEvent [object ],
9791 q workqueue.TypedRateLimitingInterface [request ],
9892) {
99- priorityQueue , isPriorityQueue := q .(priorityqueue.PriorityQueue [request ])
10093 reqs := map [request ]empty {}
101- if ! isPriorityQueue {
102- e .mapAndEnqueue (ctx , q , evt .ObjectOld , reqs )
103- e .mapAndEnqueue (ctx , q , evt .ObjectNew , reqs )
104- return
105- }
106- e .mapAndEnqueuePriorityUpdate (ctx , priorityQueue , evt .ObjectOld , evt .ObjectNew , reqs )
94+ e .mapAndEnqueue (ctx , q , evt .ObjectOld , reqs )
95+ e .mapAndEnqueue (ctx , q , evt .ObjectNew , reqs )
10796}
10897
10998// Delete implements EventHandler.
@@ -135,34 +124,3 @@ func (e *enqueueRequestsFromMapFunc[object, request]) mapAndEnqueue(ctx context.
135124 }
136125 }
137126}
138-
139- func (e * enqueueRequestsFromMapFunc [object , request ]) mapAndEnqueuePriorityCreate (ctx context.Context , q priorityqueue.PriorityQueue [request ], o object , reqs map [request ]empty ) {
140- for _ , req := range e .toRequests (ctx , o ) {
141- var priority int
142- obj := any (o ).(client.Object )
143- evtObj := event.TypedCreateEvent [client.Object ]{
144- Object : obj ,
145- }
146- if isObjectUnchanged (evtObj ) {
147- priority = LowPriority
148- }
149-
150- q .AddWithOpts (priorityqueue.AddOpts {Priority : priority }, req )
151- reqs [req ] = empty {}
152- }
153- }
154-
155- func (e * enqueueRequestsFromMapFunc [object , request ]) mapAndEnqueuePriorityUpdate (ctx context.Context , q priorityqueue.PriorityQueue [request ], oldobj object , newobj object , reqs map [request ]empty ) {
156- list := e .toRequests (ctx , oldobj )
157- list = append (list , e .toRequests (ctx , newobj )... )
158- for _ , req := range list {
159- var priority int
160- objnew := any (oldobj ).(client.Object )
161- objold := any (newobj ).(client.Object )
162- if objnew .GetResourceVersion () == objold .GetResourceVersion () {
163- priority = LowPriority
164- }
165- q .AddWithOpts (priorityqueue.AddOpts {Priority : priority }, req )
166- reqs [req ] = empty {}
167- }
168- }
0 commit comments