Skip to content

Commit

Permalink
Prioritize changed resources on update
Browse files Browse the repository at this point in the history
On an informer re-sync, all resources are re-notified as update events.
Most likely the resources didn't actually change so enqueue with low
priority if the ResourceVersion didn't change.

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Jan 25, 2025
1 parent fd71f8f commit 3a79f6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pkg/syncer/resource_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,13 @@ func (r *resourceSyncer) onUpdate(oldObj, newObj interface{}) {
return
}

r.workQueue.Enqueue(newObj)
// If the resource version didn't change, that indicates a re-sync by the informer so enqueue at low priority.
// We want to prioritize processing resources that did actually change.
if oldResource.GetResourceVersion() == newResource.GetResourceVersion() {
r.workQueue.EnqueueLowPriority(newObj)
} else {
r.workQueue.Enqueue(newObj)
}
}

func (r *resourceSyncer) onDelete(obj interface{}) {
Expand Down
12 changes: 7 additions & 5 deletions pkg/syncer/resource_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,7 @@ func testUpdateSuppression() {

Context("and the resource's ObjectMeta is updated in the datastore", func() {
BeforeEach(func() {
t := metav1.Now()
d.resource.ObjectMeta.DeletionTimestamp = &t
d.resource.ObjectMeta.Finalizers = []string{"test"}
})

It("should distribute it", func() {
Expand All @@ -941,8 +940,7 @@ func testUpdateSuppression() {

Context("and the resource's ObjectMeta is updated in the datastore", func() {
BeforeEach(func() {
t := metav1.Now()
d.resource.ObjectMeta.DeletionTimestamp = &t
d.resource.ObjectMeta.Finalizers = []string{"test"}
})

It("should not distribute it", func() {
Expand Down Expand Up @@ -1474,7 +1472,11 @@ func newTestDriver(sourceNamespace, localClusterID string, syncDirection syncer.
restMapper, gvr := test.GetRESTMapperAndGroupVersionResourceFor(d.config.ResourceType)

d.config.RestMapper = restMapper
d.config.SourceClient = fakeClient.NewSimpleDynamicClient(d.config.Scheme, initObjs...)

dynClient := fakeClient.NewSimpleDynamicClient(d.config.Scheme, initObjs...)
fakereactor.AddBasicReactors(&dynClient.Fake)

d.config.SourceClient = dynClient

d.sourceClient = d.config.SourceClient.Resource(*gvr).Namespace(d.config.SourceNamespace)

Expand Down

0 comments on commit 3a79f6a

Please sign in to comment.