Skip to content

Commit

Permalink
Merge pull request #399 from halimsam/automated-cherry-pick-of-#398-u…
Browse files Browse the repository at this point in the history
…pstream-release-1.8

Automated cherry pick of #398: Filtering informerFactory to return metadata w/o ManagedFields
  • Loading branch information
saikat-royc authored Dec 6, 2024
2 parents 80c8110 + ac06321 commit 84d6645
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,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"
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 84d6645

Please sign in to comment.