diff --git a/pkg/k8sutil/client.go b/pkg/k8sutil/client.go deleted file mode 100644 index 65ca108b4..000000000 --- a/pkg/k8sutil/client.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright 2024 The HAMi Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package k8sutil - -import ( - "os" - "path/filepath" - - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" -) - -// NewClient connects to an API server. -func NewClient() (kubernetes.Interface, error) { - kubeConfig := os.Getenv("KUBECONFIG") - if kubeConfig == "" { - kubeConfig = filepath.Join(os.Getenv("HOME"), ".kube", "config") - } - config, err := rest.InClusterConfig() - if err != nil { - config, err = clientcmd.BuildConfigFromFlags("", kubeConfig) - if err != nil { - return nil, err - } - } - client, err := kubernetes.NewForConfig(config) - return client, err -} diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 14c2f6806..e2f5f68a6 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -29,6 +29,7 @@ import ( "github.com/Project-HAMi/HAMi/pkg/scheduler/config" "github.com/Project-HAMi/HAMi/pkg/scheduler/policy" "github.com/Project-HAMi/HAMi/pkg/util" + "github.com/Project-HAMi/HAMi/pkg/util/client" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -71,12 +72,6 @@ func NewScheduler() *Scheduler { return s } -func check(err error) { - if err != nil { - klog.Fatal(err) - } -} - func (s *Scheduler) onUpdateNode(_, newObj interface{}) { s.nodeNotify <- struct{}{} } @@ -125,9 +120,7 @@ func (s *Scheduler) onDelPod(obj interface{}) { } func (s *Scheduler) Start() { - kubeClient, err := k8sutil.NewClient() - check(err) - s.kubeClient = kubeClient + s.kubeClient = client.GetClient() informerFactory := informers.NewSharedInformerFactoryWithOptions(s.kubeClient, time.Hour*1) s.podLister = informerFactory.Core().V1().Pods().Lister() s.nodeLister = informerFactory.Core().V1().Nodes().Lister()