2018-11-08 17:22:26 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2020-09-06 11:09:48 +08:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-11-08 17:22:26 +08:00
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
)
|
|
|
|
|
2018-12-28 00:02:08 +08:00
|
|
|
// NewClientSet returns a new kubernetes clientSet
|
2018-11-08 17:22:26 +08:00
|
|
|
func NewClientSet(kubeconfig string) (*kubernetes.Clientset, error) {
|
|
|
|
conf, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
conf.QPS = 50
|
|
|
|
conf.Burst = 100
|
|
|
|
clientSet, err := kubernetes.NewForConfig(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-12-28 00:02:08 +08:00
|
|
|
|
2018-12-28 09:10:13 +08:00
|
|
|
//_, err = clientSet.CoreV1().Namespaces().List(v1.ListOptions{})
|
|
|
|
//if err != nil {
|
|
|
|
// return nil, err
|
|
|
|
//}
|
2018-12-28 00:02:08 +08:00
|
|
|
|
2018-12-04 16:59:42 +08:00
|
|
|
logrus.Debug("Kube client api create success.")
|
2018-11-08 17:22:26 +08:00
|
|
|
|
|
|
|
return clientSet, nil
|
2018-12-28 09:10:13 +08:00
|
|
|
}
|