diff --git a/cmd/gateway/server/server.go b/cmd/gateway/server/server.go index 1aed68882..c65167c56 100644 --- a/cmd/gateway/server/server.go +++ b/cmd/gateway/server/server.go @@ -50,11 +50,13 @@ func Run(s *option.GWServer) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - var clientset kubernetes.Interface - if s.Config.K8SConfPath == "" { - clientset = k8sutil.MustNewKubeClient() - } else { - k8sutil.NewClientset(s.K8SConfPath) + config, err := k8sutil.NewRestConfig(s.K8SConfPath) + if err != nil { + return err + } + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + return err } //create cluster node manage diff --git a/cmd/worker/server/server.go b/cmd/worker/server/server.go index 9f17d5d2a..d68c45ecc 100644 --- a/cmd/worker/server/server.go +++ b/cmd/worker/server/server.go @@ -72,7 +72,11 @@ func Run(s *option.Worker) error { logrus.Errorf("create kube rest config error: %s", err.Error()) return err } - clientset, _ := kubernetes.NewForConfig(restConfig) + clientset, err := kubernetes.NewForConfig(restConfig) + if err != nil { + logrus.Error("Error creating clientset: %v", err) + return err + } s.Config.KubeClient = clientset kubeaggregatorclientset, err := kubeaggregatorclientset.NewForConfig(restConfig) diff --git a/grctl/clients/kubernetes.go b/grctl/clients/kubernetes.go index 2de34b1ae..f61028df6 100644 --- a/grctl/clients/kubernetes.go +++ b/grctl/clients/kubernetes.go @@ -22,8 +22,9 @@ import ( "path" "github.com/goodrain/rainbond/builder/sources" - k8sutil "github.com/goodrain/rainbond/util/k8s" + + "github.com/Sirupsen/logrus" "k8s.io/client-go/kubernetes" ) @@ -44,6 +45,10 @@ func InitClient(kubeconfig string) error { config.QPS = 50 config.Burst = 100 - K8SClient, _ = kubernetes.NewForConfig(config) + K8SClient, err = kubernetes.NewForConfig(config) + if err != nil { + logrus.Error("Create kubernetes client error.", err.Error()) + return err + } return nil } diff --git a/node/kubecache/kube_cache.go b/node/kubecache/kube_cache.go index 13b96218e..884aff6e7 100644 --- a/node/kubecache/kube_cache.go +++ b/node/kubecache/kube_cache.go @@ -80,7 +80,10 @@ func NewKubeClient(cfg *conf.Conf) (KubeClient, error) { config.QPS = 50 config.Burst = 100 - cli, _ := kubernetes.NewForConfig(config) + cli, err := kubernetes.NewForConfig(config) + if err != nil { + return nil, err + } stop := make(chan struct{}) sharedInformers := informers.NewFilteredSharedInformerFactory(cli, cfg.MinResyncPeriod, v1.NamespaceAll,