This is an automated email from the ASF dual-hosted git repository.
manirajv06 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new d176add3 [YUNIKORN-3447] Drop managed fields in the informers (#1090)
d176add3 is described below
commit d176add344d75826ed6472df7176d499d9e7f0a6
Author: Wilfred Spiegelenburg <[email protected]>
AuthorDate: Thu Sep 10 13:09:51 2026 +0530
[YUNIKORN-3447] Drop managed fields in the informers (#1090)
The objects loaded by the informers contain a field called ManagedFields
This can be a large part of the object to store. The field is not used
in the scheduler and removed in the default scheduler also to limit
memory overhead.
Applying the same change to the informers in the K8shim.
Closes: #1090
Signed-off-by: Manikandan R <[email protected]>
---
pkg/admission/informers.go | 15 ++++++++++++++-
pkg/client/apifactory.go | 14 +++++++++++++-
test/e2e/framework/helpers/k8s/k8s_utils.go | 18 +++++++++++++++---
3 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/pkg/admission/informers.go b/pkg/admission/informers.go
index 52da7364..94efe3e9 100644
--- a/pkg/admission/informers.go
+++ b/pkg/admission/informers.go
@@ -22,9 +22,11 @@ import (
"time"
"go.uber.org/zap"
+ "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/informers"
informersv1 "k8s.io/client-go/informers/core/v1"
schedulinginformersv1 "k8s.io/client-go/informers/scheduling/v1"
+ "k8s.io/client-go/tools/cache"
"github.com/apache/yunikorn-k8shim/pkg/client"
"github.com/apache/yunikorn-k8shim/pkg/log"
@@ -40,7 +42,7 @@ type Informers struct {
func NewInformers(kubeClient client.KubeClient, namespace string) *Informers {
stopChan := make(chan struct{})
- informerFactory :=
informers.NewSharedInformerFactoryWithOptions(kubeClient.GetClientSet(), 0,
informers.WithNamespace(namespace))
+ informerFactory :=
informers.NewSharedInformerFactoryWithOptions(kubeClient.GetClientSet(), 0,
informers.WithNamespace(namespace),
informers.WithTransform(stripManagedFields()))
informerFactory.Start(stopChan)
result := &Informers{
@@ -53,6 +55,17 @@ func NewInformers(kubeClient client.KubeClient, namespace
string) *Informers {
return result
}
+// stripManagedFields removes the managed fields from objects received by the
informers as we do not need them.
+// If any future code relies on the managed fields to be available this might
need adjustments.
+func stripManagedFields() cache.TransformFunc {
+ return func(in any) (any, error) {
+ if obj, err := meta.Accessor(in); err == nil &&
obj.GetManagedFields() != nil {
+ obj.SetManagedFields(nil)
+ }
+ return in, nil
+ }
+}
+
func (i *Informers) Start() {
go i.ConfigMap.Informer().Run(i.stopChan)
go i.PriorityClass.Informer().Run(i.stopChan)
diff --git a/pkg/client/apifactory.go b/pkg/client/apifactory.go
index 93c87e54..7b6a4d33 100644
--- a/pkg/client/apifactory.go
+++ b/pkg/client/apifactory.go
@@ -22,6 +22,7 @@ import (
"errors"
"go.uber.org/zap"
+ "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
@@ -91,7 +92,7 @@ type APIFactory struct {
func NewAPIFactory(scheduler api.SchedulerAPI, informerFactory
informers.SharedInformerFactory, configs *conf.SchedulerConf, testMode bool)
(*APIFactory, error) {
kubeClient := NewKubeClient(configs.KubeConfig)
- namespaceInformerFactory :=
informers.NewSharedInformerFactoryWithOptions(kubeClient.GetClientSet(), 0,
informers.WithNamespace(configs.Namespace))
+ namespaceInformerFactory :=
informers.NewSharedInformerFactoryWithOptions(kubeClient.GetClientSet(), 0,
informers.WithNamespace(configs.Namespace),
informers.WithTransform(stripManagedFields()))
// init informers
// volume informers are also used to get the Listers for the predicates
podInformer := informerFactory.Core().V1().Pods()
@@ -163,6 +164,17 @@ func NewAPIFactory(scheduler api.SchedulerAPI,
informerFactory informers.SharedI
}, nil
}
+// stripManagedFields removes the managed fields from objects received by the
informers as we do not need them.
+// If any future code relies on the managed fields to be available this might
need adjustments.
+func stripManagedFields() cache.TransformFunc {
+ return func(in any) (any, error) {
+ if obj, err := meta.Accessor(in); err == nil &&
obj.GetManagedFields() != nil {
+ obj.SetManagedFields(nil)
+ }
+ return in, nil
+ }
+}
+
func (s *APIFactory) GetAPIs() *Clients {
return s.clients
}
diff --git a/test/e2e/framework/helpers/k8s/k8s_utils.go
b/test/e2e/framework/helpers/k8s/k8s_utils.go
index 46ee9f0d..60eaac5c 100644
--- a/test/e2e/framework/helpers/k8s/k8s_utils.go
+++ b/test/e2e/framework/helpers/k8s/k8s_utils.go
@@ -39,6 +39,7 @@ import (
schedulingv1 "k8s.io/api/scheduling/v1"
storagev1 "k8s.io/api/storage/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
+ "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
@@ -760,7 +761,7 @@ func (k *KubeCtl) UpdateConfigMap(cMap *v1.ConfigMap,
namespace string) (*v1.Con
}
func (k *KubeCtl) StartConfigMapInformer(namespace string, stopChan <-chan
struct{}, eventHandler cache.ResourceEventHandler) error {
- informerFactory :=
informers.NewSharedInformerFactoryWithOptions(k.clientSet, 0,
informers.WithNamespace(namespace))
+ informerFactory :=
informers.NewSharedInformerFactoryWithOptions(k.clientSet, 0,
informers.WithNamespace(namespace),
informers.WithTransform(stripManagedFields()))
informerFactory.Start(stopChan)
configMapInformer := informerFactory.Core().V1().ConfigMaps()
_, err := configMapInformer.Informer().AddEventHandler(eventHandler)
@@ -778,6 +779,17 @@ func (k *KubeCtl) StartConfigMapInformer(namespace string,
stopChan <-chan struc
return nil
}
+// stripManagedFields removes the managed fields from objects received by the
informers as we do not need them.
+// If any future code relies on the managed fields to be available this might
need adjustments.
+func stripManagedFields() cache.TransformFunc {
+ return func(in any) (any, error) {
+ if obj, err := meta.Accessor(in); err == nil &&
obj.GetManagedFields() != nil {
+ obj.SetManagedFields(nil)
+ }
+ return in, nil
+ }
+}
+
func (k *KubeCtl) DeleteConfigMap(cName string, namespace string) error {
return
k.clientSet.CoreV1().ConfigMaps(namespace).Delete(context.TODO(), cName,
metav1.DeleteOptions{})
}
@@ -810,8 +822,8 @@ func (k *KubeCtl) CreateDeployment(deployment
*appsv1.Deployment, namespace stri
return
k.clientSet.AppsV1().Deployments(namespace).Create(context.TODO(), deployment,
metav1.CreateOptions{})
}
-func (k *KubeCtl) CreateStatefulSet(stetafulSet *appsv1.StatefulSet, namespace
string) (*appsv1.StatefulSet, error) {
- return
k.clientSet.AppsV1().StatefulSets(namespace).Create(context.TODO(),
stetafulSet, metav1.CreateOptions{})
+func (k *KubeCtl) CreateStatefulSet(statefulSet *appsv1.StatefulSet, namespace
string) (*appsv1.StatefulSet, error) {
+ return
k.clientSet.AppsV1().StatefulSets(namespace).Create(context.TODO(),
statefulSet, metav1.CreateOptions{})
}
func (k *KubeCtl) CreateReplicaSet(replicaSet *appsv1.ReplicaSet, namespace
string) (*appsv1.ReplicaSet, error) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]