@@ -21,7 +21,6 @@ import (
21
21
22
22
"k8s.io/client-go/util/workqueue"
23
23
"sigs.k8s.io/controller-runtime/pkg/client"
24
- "sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue"
25
24
"sigs.k8s.io/controller-runtime/pkg/event"
26
25
"sigs.k8s.io/controller-runtime/pkg/reconcile"
27
26
)
@@ -47,7 +46,7 @@ type TypedMapFunc[object any, request comparable] func(context.Context, object)
47
46
// For UpdateEvents which contain both a new and old object, the transformation function is run on both
48
47
// objects and both sets of Requests are enqueue.
49
48
func EnqueueRequestsFromMapFunc (fn MapFunc ) EventHandler {
50
- return TypedEnqueueRequestsFromMapFunc (fn )
49
+ return WithLowPriorityWhenUnchanged ( TypedEnqueueRequestsFromMapFunc (fn ) )
51
50
}
52
51
53
52
// TypedEnqueueRequestsFromMapFunc enqueues Requests by running a transformation function that outputs a collection
@@ -82,12 +81,7 @@ func (e *enqueueRequestsFromMapFunc[object, request]) Create(
82
81
q workqueue.TypedRateLimitingInterface [request ],
83
82
) {
84
83
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 )
91
85
}
92
86
93
87
// Update implements EventHandler.
@@ -96,14 +90,9 @@ func (e *enqueueRequestsFromMapFunc[object, request]) Update(
96
90
evt event.TypedUpdateEvent [object ],
97
91
q workqueue.TypedRateLimitingInterface [request ],
98
92
) {
99
- priorityQueue , isPriorityQueue := q .(priorityqueue.PriorityQueue [request ])
100
93
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 )
107
96
}
108
97
109
98
// Delete implements EventHandler.
@@ -135,34 +124,3 @@ func (e *enqueueRequestsFromMapFunc[object, request]) mapAndEnqueue(ctx context.
135
124
}
136
125
}
137
126
}
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