HAOJX

创建config和clientset

字数统计: 61阅读时长: 1 min
2021/07/05 Share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package lib

import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"log"
)

func InitConfig() *rest.Config{
config,err:=clientcmd.BuildConfigFromFlags("","config")
if err != nil {
log.Fatal(err)
}
return config
}

func InitClient() *kubernetes.Clientset {
client,err:=kubernetes.NewForConfig(InitConfig())
if err != nil {
log.Fatal(err)
}
return client
}
CATALOG