From ac06321156e7eb513c7dc74f4c55d4f9fa98c271 Mon Sep 17 00:00:00 2001 From: Samuel Halim Date: Thu, 28 Nov 2024 00:30:20 +0000 Subject: [PATCH] Filtering informerFactory to return metadata w/o ManagedFields to improve memory --- pkg/cloud_provider/clientset/clientset.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/cloud_provider/clientset/clientset.go b/pkg/cloud_provider/clientset/clientset.go index 37d6834a2..eece5f6f3 100644 --- a/pkg/cloud_provider/clientset/clientset.go +++ b/pkg/cloud_provider/clientset/clientset.go @@ -25,6 +25,7 @@ import ( authenticationv1 "k8s.io/api/authentication/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/informers" @@ -77,12 +78,23 @@ func New(kubeconfigPath string, informerResyncDurationSec int) (Interface, error } func (c *Clientset) ConfigurePodLister(nodeName string) { + trimManagedFields := func(obj interface{}) (interface{}, error) { + if accessor, err := meta.Accessor(obj); err == nil { + if accessor.GetManagedFields() != nil { + accessor.SetManagedFields(nil) + } + } + + return obj, nil + } + informerFactory := informers.NewSharedInformerFactoryWithOptions( c.k8sClients, time.Duration(c.informerResyncDurationSec)*time.Second, informers.WithTweakListOptions(func(options *metav1.ListOptions) { options.FieldSelector = "spec.nodeName=" + nodeName }), + informers.WithTransform(trimManagedFields), ) podLister := informerFactory.Core().V1().Pods().Lister()