From a55b7fc5c6f456362163c6d3589a5cd7e3d84feb Mon Sep 17 00:00:00 2001 From: baoyinghai Date: Thu, 28 Sep 2023 16:55:42 +0800 Subject: [PATCH] fix: use master config to init resourcemanager for adapter Signed-off-by: baoyinghai --- .gitignore | 4 +++- pkg/knode-manager/knode.go | 38 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 48d611595..eef595cab 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ e2e-logs _delete/ -kube-config \ No newline at end of file +kube-config + +__debug_bin* \ No newline at end of file diff --git a/pkg/knode-manager/knode.go b/pkg/knode-manager/knode.go index 2f0038aeb..bf9536fdb 100644 --- a/pkg/knode-manager/knode.go +++ b/pkg/knode-manager/knode.go @@ -75,6 +75,7 @@ func NewKnode(ctx context.Context, knode *kosmosv1alpha1.Knode, cmdConfig *confi return nil, fmt.Errorf("kubeconfig of knode %s is empty", knode.Name) } + // init master client master, err := utils.NewClientFromConfigPath(cmdConfig.KubeConfigPath, func(config *rest.Config) { config.QPS = cmdConfig.KubeAPIQPS config.Burst = cmdConfig.KubeAPIBurst @@ -83,6 +84,24 @@ func NewKnode(ctx context.Context, knode *kosmosv1alpha1.Knode, cmdConfig *confi return nil, fmt.Errorf("could not build clientset for master cluster: %v", err) } + masterInformers := NewInformers(master, cmdConfig.InformerResyncPeriod) + + podInformerForNodeFactory := kubeinformers.NewSharedInformerFactoryWithOptions( + master, + cmdConfig.InformerResyncPeriod, + kubeinformers.WithNamespace(cmdConfig.KubeNamespace), + kubeinformers.WithTweakListOptions(func(options *metav1.ListOptions) { + options.FieldSelector = fields.OneTermEqualSelector("spec.nodeName", knode.Spec.NodeName).String() + })) + + podInformerForNode := podInformerForNodeFactory.Core().V1().Pods() + + rm, err := manager.NewResourceManager(podInformerForNode.Lister(), masterInformers.secretInformer.Lister(), masterInformers.cmInformer.Lister(), masterInformers.serviceInformer.Lister()) + if err != nil { + return nil, errors.Wrap(err, "could not create resource manager") + } + + // init adapter client client, err := utils.NewClientFromBytes(knode.Spec.Kubeconfig, func(config *rest.Config) { config.QPS = knode.Spec.KubeAPIQPS config.Burst = knode.Spec.KubeAPIBurst @@ -93,11 +112,6 @@ func NewKnode(ctx context.Context, knode *kosmosv1alpha1.Knode, cmdConfig *confi clientInformers := NewInformers(client, cmdConfig.InformerResyncPeriod) - rm, err := manager.NewResourceManager(clientInformers.podInformer.Lister(), clientInformers.secretInformer.Lister(), clientInformers.cmInformer.Lister(), clientInformers.serviceInformer.Lister()) - if err != nil { - return nil, errors.Wrap(err, "could not create resource manager") - } - ac := &k8sadapter.AdapterConfig{ Client: client, Master: master, @@ -143,19 +157,9 @@ func NewKnode(ctx context.Context, knode *kosmosv1alpha1.Knode, cmdConfig *confi eb.StartLogging(klog.Infof) eb.StartRecordingToSink(&corev1client.EventSinkImpl{Interface: master.CoreV1().Events(cmdConfig.KubeNamespace)}) - masterInformers := NewInformers(master, cmdConfig.InformerResyncPeriod) - - podInformerForNode := kubeinformers.NewSharedInformerFactoryWithOptions( - master, - cmdConfig.InformerResyncPeriod, - kubeinformers.WithNamespace(cmdConfig.KubeNamespace), - kubeinformers.WithTweakListOptions(func(options *metav1.ListOptions) { - options.FieldSelector = fields.OneTermEqualSelector("spec.nodeName", knode.Spec.NodeName).String() - })) - pc, err := controllers.NewPodController(controllers.PodConfig{ PodClient: master.CoreV1(), - PodInformer: podInformerForNode.Core().V1().Pods(), + PodInformer: podInformerForNode, EventRecorder: eb.NewRecorder(scheme.Scheme, corev1.EventSource{Component: path.Join(dummyNode.Name, ComponentName)}), PodHandler: podAdapter, ConfigMapInformer: masterInformers.cmInformer, @@ -182,7 +186,7 @@ func NewKnode(ctx context.Context, knode *kosmosv1alpha1.Knode, cmdConfig *confi master: master, clientInformerFactory: clientInformers.informer, masterInformerFactory: masterInformers.informer, - podInformerFactory: podInformerForNode, + podInformerFactory: podInformerForNodeFactory, ac: ac, podController: pc, nodeController: nc,