remove default kubecofigpath and add handle error

This commit is contained in:
凡羊羊 2020-01-08 19:59:28 +08:00
parent b71fbd1f9f
commit c5cfc26a5b
7 changed files with 17 additions and 7 deletions

View File

@ -69,7 +69,7 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.DBType, "db-type", "mysql", "db type mysql or etcd")
fs.StringVar(&a.MysqlConnectionInfo, "mysql", "root:admin@tcp(127.0.0.1:3306)/region", "mysql db connection info")
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"127.0.0.1:6366"}, "event log server address. simple lb")
fs.StringVar(&a.KubeConfig, "kube-config", "/opt/rainbond/etc/kubernetes/kubecfg/admin.kubeconfig", "kubernetes api server config file")
fs.StringVar(&a.KubeConfig, "kube-config", "", "kubernetes api server config file")
fs.IntVar(&a.MaxTasks, "max-tasks", 0, "Maximum number of simultaneous build tasksIf set to 0, the maximum limit is twice the number of CPU cores")
fs.IntVar(&a.APIPort, "api-port", 3228, "the port for api server")
fs.StringVar(&a.MQAPI, "mq-api", "127.0.0.1:6300", "acp_mq api")

View File

@ -93,7 +93,7 @@ type ListenPorts struct {
// AddFlags adds flags
func (g *GWServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&g.LogLevel, "log-level", "debug", "the gateway log level")
fs.StringVar(&g.K8SConfPath, "kube-conf", "/opt/rainbond/etc/kubernetes/kubecfg/admin.kubeconfig", "absolute path to the kubeconfig file")
fs.StringVar(&g.K8SConfPath, "kube-conf", "", "absolute path to the kubeconfig file")
fs.IntVar(&g.ListenPorts.Status, "status-port", 18080, `Port to use for exposing NGINX status pages.`)
fs.IntVar(&g.WorkerProcesses, "worker-processes", 0, "Default get current compute cpu core number.This number should be, at maximum, the number of CPU cores on your system.")
fs.IntVar(&g.WorkerConnections, "worker-connections", 4000, "Determines how many clients will be served by each worker process.")

View File

@ -149,7 +149,7 @@ func (a *Conf) AddFlags(fs *pflag.FlagSet) {
fs.Int64Var(&a.TTL, "ttl", 10, "Frequency of node status reporting to master")
//fs.StringVar(&a.APIAddr, "api-addr", ":6100", "The node api server listen address")
fs.StringVar(&a.GrpcAPIAddr, "grpc-api-addr", ":6101", "The node grpc api server listen address")
fs.StringVar(&a.K8SConfPath, "kube-conf", "/opt/rainbond/etc/kubernetes/kubecfg/admin.kubeconfig", "absolute path to the kubeconfig file ./kubeconfig")
fs.StringVar(&a.K8SConfPath, "kube-conf", "", "absolute path to the kubeconfig file ./kubeconfig")
fs.StringVar(&a.RunMode, "run-mode", "worker", "the acp_node run mode,could be 'worker' or 'master'")
fs.StringVar(&a.NodeRule, "noderule", "compute", "current node rule,maybe is `compute` `manage` `storage` ")
fs.StringVar(&a.StatsdConfig.StatsdListenAddress, "statsd.listen-address", "", "The UDP address on which to receive statsd metric lines. DEPRECATED, use statsd.listen-udp instead.")

View File

@ -74,7 +74,7 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.DBType, "db-type", "mysql", "db type mysql or etcd")
fs.StringVar(&a.MysqlConnectionInfo, "mysql", "root:admin@tcp(127.0.0.1:3306)/region", "mysql db connection info")
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"127.0.0.1:6366"}, "event log server address. simple lb")
fs.StringVar(&a.KubeConfig, "kube-config", "/opt/rainbond/etc/kubernetes/kubecfg/admin.kubeconfig", "kubernetes api server config file")
fs.StringVar(&a.KubeConfig, "kube-config", "", "kubernetes api server config file")
fs.IntVar(&a.MaxTasks, "max-tasks", 50, "the max tasks for per node")
fs.StringVar(&a.MQAPI, "mq-api", "127.0.0.1:6300", "acp_mq api")
fs.StringVar(&a.RunMode, "run", "sync", "sync data when worker start")

View File

@ -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.Errorf("create kube client error: %s", err.Error())
return err
}
s.Config.KubeClient = clientset
kubeaggregatorclientset, err := kubeaggregatorclientset.NewForConfig(restConfig)

View File

@ -44,6 +44,9 @@ func InitClient(kubeconfig string) error {
config.QPS = 50
config.Burst = 100
K8SClient, _ = kubernetes.NewForConfig(config)
K8SClient, err = kubernetes.NewForConfig(config)
if err != nil {
return err
}
return nil
}

View File

@ -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,