-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientset.go
36 lines (32 loc) · 865 Bytes
/
clientset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"context"
"fmt"
"github.com/go-logr/logr"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func GetKubeClient(ctx context.Context, cfgpath string) (*kubernetes.Clientset, *rest.Config) {
log := logr.FromContextOrDiscard(ctx)
//配置文件的存放路径
configfile := cfgpath
kubeconfig, err := clientcmd.BuildConfigFromFlags("", configfile)
if err != nil {
//log.Error(err, "BuildConfigFromFlags kube clientset faild")
fmt.Errorf("BuildConfigFromFlags kube clientset faild")
panic(err)
}
//默认为5
kubeconfig.QPS = 100
//默认为10
kubeconfig.Burst = 100
//生成clientset
clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
log.Error(err, "clientset get faild")
panic(err)
}
log.Info("GetKubeClient success")
return clientset, kubeconfig
}