forked from kubeedge/kubeedge
/
kubeclient.go
33 lines (28 loc) · 841 Bytes
/
kubeclient.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
package utils
import (
"github.com/kubeedge/beehive/pkg/common/log"
"github.com/kubeedge/kubeedge/cloud/pkg/devicecontroller/config"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// KubeClient from config
func KubeClient() (*kubernetes.Clientset, error) {
kubeConfig, err := KubeConfig()
if err != nil {
log.LOGGER.Warnf("Get kube config failed with error: %s", err)
return nil, err
}
return kubernetes.NewForConfig(kubeConfig)
}
// KubeConfig from flags
func KubeConfig() (conf *rest.Config, err error) {
kubeConfig, err := clientcmd.BuildConfigFromFlags(config.KubeMaster, config.KubeConfig)
if err != nil {
return nil, err
}
kubeConfig.QPS = config.KubeQPS
kubeConfig.Burst = config.KubeBurst
kubeConfig.ContentType = config.KubeContentType
return kubeConfig, err
}