Skip to content

Commit

Permalink
Filtering informerFactory to return metadata w/o ManagedFields to
Browse files Browse the repository at this point in the history
improve memory
  • Loading branch information
halimsam committed Nov 28, 2024
1 parent 215ff96 commit e7939da
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/cloud_provider/clientset/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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"
Expand Down Expand Up @@ -77,12 +79,22 @@ 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

Check failure on line 88 in pkg/cloud_provider/clientset/clientset.go

View workflow job for this annotation

GitHub Actions / verify

return with no blank line before (nlreturn)
}

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()

Expand Down

0 comments on commit e7939da

Please sign in to comment.