@@ -136,6 +136,9 @@ func (h TypedFuncs[object, request]) Generic(ctx context.Context, e event.TypedG
136136 }
137137}
138138
139+ // LowPriority is the priority set by WithLowPriorityWhenUnchanged
140+ const LowPriority = - 100
141+
139142// WithLowPriorityWhenUnchanged reduces the priority of events stemming from the initial listwatch or from a resync if
140143// and only if a controllerworkqueue.PriorityQueue is used. If not, it does nothing.
141144func WithLowPriorityWhenUnchanged [object client.Object , request comparable ](u TypedEventHandler [object , request ]) TypedEventHandler [object , request ] {
@@ -151,13 +154,31 @@ func WithLowPriorityWhenUnchanged[object client.Object, request comparable](u Ty
151154 q .Add (item )
152155 return
153156 }
157+ var priority int
154158 if isObjectUnchanged (tce ) {
155- priorityQueue .AddWithOpts (controllerworkqueue.AddOpts {Priority : - 1 }, item )
159+ priority = LowPriority
160+ }
161+ priorityQueue .AddWithOpts (controllerworkqueue.AddOpts {Priority : priority }, item )
162+ },
163+ })
164+ },
165+ UpdateFunc : func (ctx context.Context , tue event.TypedUpdateEvent [object ], trli workqueue.TypedRateLimitingInterface [request ]) {
166+ u .Update (ctx , tue , workqueueWithCustomAddFunc [request ]{
167+ TypedRateLimitingInterface : trli ,
168+ addFunc : func (item request , q workqueue.TypedRateLimitingInterface [request ]) {
169+ priorityQueue , isPriorityQueue := q .(controllerworkqueue.PriorityQueue [request ])
170+ if ! isPriorityQueue {
171+ q .Add (item )
172+ return
173+ }
174+ var priority int
175+ if tue .ObjectOld .GetResourceVersion () == tue .ObjectNew .GetResourceVersion () {
176+ priority = LowPriority
156177 }
178+ priorityQueue .AddWithOpts (controllerworkqueue.AddOpts {Priority : priority }, item )
157179 },
158180 })
159181 },
160- UpdateFunc : u .Update ,
161182 DeleteFunc : u .Delete ,
162183 GenericFunc : u .Generic ,
163184 }
0 commit comments