From a6721eaf498e46a7f4bf52e900641c4c155ce371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E6=96=8C?= Date: Tue, 14 Nov 2017 18:45:58 +0800 Subject: [PATCH] =?UTF-8?q?[REV]=E4=BD=BF=E7=94=A8=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E8=8E=B7=E5=8F=96=E7=9A=84?= =?UTF-8?q?tenant=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/node/server/server.go | 2 +- pkg/node/api/controller/discoverController.go | 4 +- pkg/node/api/router/discoverRouter.go | 4 +- pkg/node/core/service/discover_server.go | 38 ++++++------------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/cmd/node/server/server.go b/cmd/node/server/server.go index 563052d0c..47ea45f97 100644 --- a/cmd/node/server/server.go +++ b/cmd/node/server/server.go @@ -95,7 +95,7 @@ func Run(c *option.Conf) error { } if err := db.CreateManager(dbconfig); err != nil { logrus.Warnf("create db manager error, %v", err) - logrus.Warnf("Ignore this db error for node main functions, but discover services in this node will not work.") + logrus.Warnf("Ignore this db error for node main functions, but discover services in this node may be influenced.") //return err } defer db.CloseManager() diff --git a/pkg/node/api/controller/discoverController.go b/pkg/node/api/controller/discoverController.go index 7d9e03473..dadcaa8b5 100644 --- a/pkg/node/api/controller/discoverController.go +++ b/pkg/node/api/controller/discoverController.go @@ -46,7 +46,7 @@ func ServiceDiscover(w http.ResponseWriter, r *http.Request) { //ListenerDiscover ListenerDiscover func ListenerDiscover(w http.ResponseWriter, r *http.Request) { - tenantName := chi.URLParam(r, "tenant_name") + tenantName := chi.URLParam(r, "tenant_id") serviceNodes := chi.URLParam(r, "service_nodes") lds, err := discoverService.DiscoverListeners(tenantName, serviceNodes) if err != nil { @@ -64,7 +64,7 @@ func ListenerDiscover(w http.ResponseWriter, r *http.Request) { //ClusterDiscover ClusterDiscover func ClusterDiscover(w http.ResponseWriter, r *http.Request) { - tenantName := chi.URLParam(r, "tenant_name") + tenantName := chi.URLParam(r, "tenant_id") serviceNodes := chi.URLParam(r, "service_nodes") cds, err := discoverService.DiscoverClusters(tenantName, serviceNodes) if err != nil { diff --git a/pkg/node/api/router/discoverRouter.go b/pkg/node/api/router/discoverRouter.go index 78bab2d21..7fdf6769f 100644 --- a/pkg/node/api/router/discoverRouter.go +++ b/pkg/node/api/router/discoverRouter.go @@ -39,7 +39,7 @@ func DisconverRoutes() chi.Router { func ListenersRoutes() chi.Router { r := chi.NewRouter() r.Get("/ping", controller.Ping) - r.Get("/{tenant_name}/{service_nodes}", controller.ListenerDiscover) + r.Get("/{tenant_id}/{service_nodes}", controller.ListenerDiscover) return r } @@ -48,7 +48,7 @@ func ListenersRoutes() chi.Router { func ClustersRoutes() chi.Router { r := chi.NewRouter() r.Get("/ping", controller.Ping) - r.Get("/{tenant_name}/{service_nodes}", controller.ClusterDiscover) + r.Get("/{tenant_id}/{service_nodes}", controller.ClusterDiscover) return r } diff --git a/pkg/node/core/service/discover_server.go b/pkg/node/core/service/discover_server.go index 0399901b5..965a2136d 100644 --- a/pkg/node/core/service/discover_server.go +++ b/pkg/node/core/service/discover_server.go @@ -49,19 +49,11 @@ func (d *DiscoverAction) DiscoverService(serviceInfo string) (*node_model.SDS, * if len(mm) < 3 { return nil, util.CreateAPIHandleError(400, fmt.Errorf("service_name is not in good format")) } - tenantName := mm[0] + namespace := mm[0] serviceAlias := mm[1] dPort := mm[2] //deployVersion := mm[3] - namespace, err := d.ToolsGetTenantUUID(tenantName) - if err != nil { - return nil, util.CreateAPIHandleErrorFromDBError("get tenant uuid ", err) - } - // serviceID, err := d.ToolsGetServiceID(uuid, serviceAlias) - // if err != nil { - // return nil, util.CreateAPIHandleErrorFromDBError("get service id ", err) - // } labelname := fmt.Sprintf("name=%sService", serviceAlias) endpoint, err := k8s.K8S.Core().Endpoints(namespace).List(metav1.ListOptions{LabelSelector: labelname}) if err != nil { @@ -100,15 +92,11 @@ func (d *DiscoverAction) DiscoverService(serviceInfo string) (*node_model.SDS, * } //DiscoverListeners DiscoverListeners -func (d *DiscoverAction) DiscoverListeners(tenantName, serviceCluster string) (*node_model.LDS, *util.APIHandleError) { +func (d *DiscoverAction) DiscoverListeners(namespace, serviceCluster string) (*node_model.LDS, *util.APIHandleError) { mm := strings.Split(serviceCluster, "_") if len(mm) == 0 { return nil, util.CreateAPIHandleError(400, fmt.Errorf("service_name is not in good format")) } - namespace, err := d.ToolsGetTenantUUID(tenantName) - if err != nil { - return nil, util.CreateAPIHandleErrorFromDBError("get tenant uuid ", err) - } var ldsL []*node_model.PieceLDS for _, serviceAlias := range mm { labelname := fmt.Sprintf("name=%sService", serviceAlias) @@ -143,13 +131,13 @@ func (d *DiscoverAction) DiscoverListeners(tenantName, serviceCluster string) (* switch port.Protocol { case "TCP": ptr := &node_model.PieceTCPRoute{ - Cluster: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + Cluster: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), } lrs := &node_model.LDSTCPRoutes{ Routes: []*node_model.PieceTCPRoute{ptr}, } lcg := &node_model.LDSTCPConfig{ - StatPrefix: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + StatPrefix: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), RouteConfig: lrs, } lfs := &node_model.LDSFilters{ @@ -157,7 +145,7 @@ func (d *DiscoverAction) DiscoverListeners(tenantName, serviceCluster string) (* Config: lcg, } plds := &node_model.PieceLDS{ - Name: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + Name: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), Address: fmt.Sprintf("tcp://0.0.0.0:%v", port.Port), Filters: []*node_model.LDSFilters{lfs}, } @@ -171,14 +159,14 @@ func (d *DiscoverAction) DiscoverListeners(tenantName, serviceCluster string) (* prs := &node_model.PieceHTTPRoutes{ TimeoutMS: 0, Prefix: "/", - Cluster: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + Cluster: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), } domain, ok := service.Labels["domain"] if !ok { domain = "*" } pvh := &node_model.PieceHTTPVirtualHost{ - Name: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + Name: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), Domains: []string{domain}, Routes: []*node_model.PieceHTTPRoutes{prs}, } @@ -196,7 +184,7 @@ func (d *DiscoverAction) DiscoverListeners(tenantName, serviceCluster string) (* Config: lhc, } plds := &node_model.PieceLDS{ - Name: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + Name: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), Address: fmt.Sprintf("tcp://0.0.0.0:%v", port.TargetPort), Filters: []*node_model.LDSFilters{lfs}, } @@ -213,15 +201,11 @@ func (d *DiscoverAction) DiscoverListeners(tenantName, serviceCluster string) (* } //DiscoverClusters DiscoverClusters -func (d *DiscoverAction) DiscoverClusters(tenantName, serviceCluster string) (*node_model.CDS, *util.APIHandleError) { +func (d *DiscoverAction) DiscoverClusters(namespace, serviceCluster string) (*node_model.CDS, *util.APIHandleError) { mm := strings.Split(serviceCluster, "_") if len(mm) == 0 { return nil, util.CreateAPIHandleError(400, fmt.Errorf("service_name is not in good format")) } - namespace, err := d.ToolsGetTenantUUID(tenantName) - if err != nil { - return nil, util.CreateAPIHandleErrorFromDBError("get tenant uuid ", err) - } var cdsL []*node_model.PieceCDS for _, serviceAlias := range mm { labelname := fmt.Sprintf("name=%sService", serviceAlias) @@ -232,11 +216,11 @@ func (d *DiscoverAction) DiscoverClusters(tenantName, serviceCluster string) (*n for _, service := range services.Items { for _, port := range service.Spec.Ports { pcds := &node_model.PieceCDS{ - Name: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + Name: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), Type: "sds", ConnectTimeoutMS: 250, LBType: "round_robin", - ServiceName: fmt.Sprintf("%s_%s_%v", tenantName, serviceAlias, port.Port), + ServiceName: fmt.Sprintf("%s_%s_%v", namespace, serviceAlias, port.Port), } cdsL = append(cdsL, pcds) continue