Skip to content

Commit 92025dd

Browse files
committed
Fix handler
1 parent 2646684 commit 92025dd

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

pkg/handler/eventhandler.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
141144
func 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

Comments
 (0)