Skip to content

Commit

Permalink
Merge pull request #78 from OrangeBao/main
Browse files Browse the repository at this point in the history
fix: use master config to init resourcemanager for adapter
  • Loading branch information
kosmos-robot authored Sep 28, 2023
2 parents 8a00bca + a55b7fc commit 558cbba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ e2e-logs

_delete/

kube-config
kube-config

__debug_bin*
38 changes: 21 additions & 17 deletions pkg/knode-manager/knode.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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
Expand All @@ -82,6 +83,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
Expand All @@ -92,11 +111,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,
Expand Down Expand Up @@ -132,19 +146,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,
Expand All @@ -166,7 +170,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,
Expand Down

0 comments on commit 558cbba

Please sign in to comment.