From c2aff77a6ca93be275f06a0e541fa3198207a3c8 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 3 Apr 2024 08:38:12 -0400 Subject: [PATCH] Trim ManagedFields in the resource syncer to ...reduce the informer cache memory usage. Fixes https://github.com/submariner-io/admiral/issues/859 Signed-off-by: Tom Pantelis --- pkg/syncer/resource_syncer.go | 5 ++++- test/e2e/watcher/watcher.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/syncer/resource_syncer.go b/pkg/syncer/resource_syncer.go index 696cfff8..2d0eb282 100644 --- a/pkg/syncer/resource_syncer.go +++ b/pkg/syncer/resource_syncer.go @@ -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 @@ -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 diff --git a/test/e2e/watcher/watcher.go b/test/e2e/watcher/watcher.go index a42bb6c4..8e9429ab 100644 --- a/test/e2e/watcher/watcher.go +++ b/test/e2e/watcher/watcher.go @@ -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)