Skip to content

Commit

Permalink
Trim ManagedFields in the resource syncer to
Browse files Browse the repository at this point in the history
...reduce the informer cache memory usage.

Fixes #859

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis authored and skitt committed Apr 3, 2024
1 parent 8bea092 commit c2aff77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/syncer/resource_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func NewResourceSyncer(config *ResourceSyncerConfig) (Interface, error) {

resourceClient := config.SourceClient.Resource(*gvr).Namespace(config.SourceNamespace)

syncer.store, syncer.informer = cache.NewInformer(&cache.ListWatch{
syncer.store, syncer.informer = cache.NewTransformingInformer(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.LabelSelector = config.SourceLabelSelector
options.FieldSelector = config.SourceFieldSelector
Expand All @@ -256,6 +256,9 @@ func NewResourceSyncer(config *ResourceSyncerConfig) (Interface, error) {
AddFunc: syncer.onCreate,
UpdateFunc: syncer.onUpdate,
DeleteFunc: syncer.onDelete,
}, func(obj interface{}) (interface{}, error) {
resourceUtil.MustToMeta(obj).SetManagedFields(nil)
return obj, nil
})

return syncer, nil
Expand Down
1 change: 1 addition & 0 deletions test/e2e/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var _ = Describe("[watcher] Resource watcher tests", func() {
It("should notify the handler of each event", func() {
clusterName := framework.TestContext.ClusterIDs[framework.ClusterA]
toaster := util.CreateToaster(t.client, util.NewToaster("test-toaster", t.framework.Namespace), clusterName)
toaster.SetManagedFields(nil)
Eventually(t.created).Should(Receive(Equal(toaster)))

util.DeleteToaster(t.client, toaster, clusterName)
Expand Down

0 comments on commit c2aff77

Please sign in to comment.