adopt transform func to save memory

Signed-off-by: dddddai <dddwq@foxmail.com>
This commit is contained in:
dddddai 2022-09-16 10:41:04 +08:00
parent a1098a6b45
commit 01f37c160c
6 changed files with 31 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import (
"k8s.io/component-base/term"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/healthz"
@ -34,6 +35,7 @@ import (
"github.com/karmada-io/karmada/pkg/sharedcli/klogflag"
"github.com/karmada-io/karmada/pkg/sharedcli/profileflag"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
"github.com/karmada-io/karmada/pkg/util/fedinformer/typedmanager"
"github.com/karmada-io/karmada/pkg/util/gclient"
@ -188,6 +190,9 @@ func run(ctx context.Context, karmadaConfig karmadactl.KarmadaConfig, opts *opti
clusterv1alpha1.SchemeGroupVersion.WithKind("Cluster").GroupKind().String(): opts.ConcurrentClusterSyncs,
},
},
NewCache: cache.BuilderWithOptions(cache.Options{
DefaultTransform: fedinformer.StripUnusedFields,
}),
})
if err != nil {
return fmt.Errorf("failed to build controller manager: %w", err)

View File

@ -18,6 +18,7 @@ import (
"k8s.io/component-base/term"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/healthz"
@ -48,6 +49,7 @@ import (
"github.com/karmada-io/karmada/pkg/sharedcli/klogflag"
"github.com/karmada-io/karmada/pkg/sharedcli/profileflag"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
"github.com/karmada-io/karmada/pkg/util/fedinformer/typedmanager"
"github.com/karmada-io/karmada/pkg/util/gclient"
@ -134,6 +136,9 @@ func Run(ctx context.Context, opts *options.Options) error {
schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"}.GroupKind().String(): opts.ConcurrentNamespaceSyncs,
},
},
NewCache: cache.BuilderWithOptions(cache.Options{
DefaultTransform: fedinformer.StripUnusedFields,
}),
})
if err != nil {
klog.Errorf("failed to build controller manager: %v", err)

View File

@ -26,6 +26,7 @@ import (
clusterlister "github.com/karmada-io/karmada/pkg/generated/listers/cluster/v1alpha1"
worklister "github.com/karmada-io/karmada/pkg/generated/listers/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/gclient"
)
@ -70,6 +71,10 @@ func NewDescheduler(karmadaClient karmadaclientset.Interface, kubeClient kuberne
unschedulableThreshold: opts.UnschedulableThreshold.Duration,
deschedulingInterval: opts.DeschedulingInterval.Duration,
}
// ignore the error here because the informers haven't been started
_ = desched.bindingInformer.SetTransform(fedinformer.StripUnusedFields)
_ = desched.clusterInformer.SetTransform(fedinformer.StripUnusedFields)
schedulerEstimatorWorkerOptions := util.Options{
Name: "scheduler-estimator",
KeyFunc: nil,

View File

@ -32,6 +32,7 @@ import (
"github.com/karmada-io/karmada/pkg/estimator/server/replica"
estimatorservice "github.com/karmada-io/karmada/pkg/estimator/service"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
"github.com/karmada-io/karmada/pkg/util/fedinformer/keys"
"github.com/karmada-io/karmada/pkg/util/helper"
@ -92,6 +93,10 @@ func NewEstimatorServer(
},
parallelizer: lifted.NewParallelizer(opts.Parallelism),
}
// ignore the error here because the informers haven't been started
_ = es.nodeInformer.Informer().SetTransform(fedinformer.StripUnusedFields)
_ = es.podInformer.Informer().SetTransform(fedinformer.StripUnusedFields)
_ = informerFactory.Apps().V1().ReplicaSets().Informer().SetTransform(fedinformer.StripUnusedFields)
// Establish a connection between the pods and their assigned nodes.
_ = es.podInformer.Informer().AddIndexers(cache.Indexers{

View File

@ -14,6 +14,7 @@ import (
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
"github.com/karmada-io/karmada/pkg/scheduler/metrics"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/gclient"
)
@ -56,6 +57,12 @@ func (s *Scheduler) addAllEventHandlers() {
DeleteFunc: s.deleteCluster,
},
)
// ignore the error here because the informers haven't been started
_ = bindingInformer.SetTransform(fedinformer.StripUnusedFields)
_ = policyInformer.SetTransform(fedinformer.StripUnusedFields)
_ = clusterBindingInformer.SetTransform(fedinformer.StripUnusedFields)
_ = clusterPolicyInformer.SetTransform(fedinformer.StripUnusedFields)
_ = memClusterInformer.SetTransform(fedinformer.StripUnusedFields)
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartStructuredLogging(0)

View File

@ -26,6 +26,7 @@ import (
clusterlister "github.com/karmada-io/karmada/pkg/generated/listers/cluster/v1alpha1"
"github.com/karmada-io/karmada/pkg/search/backendstore"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
"github.com/karmada-io/karmada/pkg/util/gclient"
"github.com/karmada-io/karmada/pkg/util/restmapper"
@ -103,6 +104,9 @@ func (c *Controller) addAllEventHandlers() {
UpdateFunc: c.updateResourceRegistry,
DeleteFunc: c.deleteResourceRegistry,
})
// ignore the error here because the informers haven't been started
_ = clusterInformer.SetTransform(fedinformer.StripUnusedFields)
_ = resourceRegistryInformer.SetTransform(fedinformer.StripUnusedFields)
}
// Start the controller