package infra

import (
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
	"k8s.io/client-go/util/homedir"
	"os"
	"path/filepath"
)

var ClientSet *kubernetes.Clientset

func InitKubernetesClient() {
	kubeConfigFile := filepath.Join(homedir.HomeDir(), ".kube", "config")
	config, err := clientcmd.BuildConfigFromFlags("", kubeConfigFile)
	if err != nil {
		GlobalLogger.Error("读取k8s配置文件失败", err.Error())
		os.Exit(0)
	}

	ClientSet, err = kubernetes.NewForConfig(config)
	if err != nil {
		GlobalLogger.Error("读取k8s配置文件失败", err.Error())
		os.Exit(0)
	}
}
