From c4a607a9417cff1e74381f6a435b1b7e1ed6d0dd Mon Sep 17 00:00:00 2001 From: barnett Date: Mon, 9 Apr 2018 19:07:01 +0800 Subject: [PATCH] [REV] create listener for all app upstream,but it's not repeat. --- pkg/node/core/service/discover_server.go | 48 ++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/pkg/node/core/service/discover_server.go b/pkg/node/core/service/discover_server.go index cd25c6dd5..ab217236d 100644 --- a/pkg/node/core/service/discover_server.go +++ b/pkg/node/core/service/discover_server.go @@ -185,6 +185,7 @@ func (d *DiscoverAction) DiscoverListeners( continue } } + var portMap = make(map[int32]int, 0) for _, service := range services.Items { serviceType, ok := service.Labels["service_type"] if !ok || serviceType != "inner" { @@ -193,12 +194,35 @@ func (d *DiscoverAction) DiscoverListeners( } } port := service.Spec.Ports[0].Port + clusterName := fmt.Sprintf("%s_%s_%s_%d", namespace, serviceAlias, destServiceAlias, port) + if _, ok := portMap[port]; !ok { + ptr := &envoyv1.TCPRoute{ + Cluster: clusterName, + } + lrs := &envoyv1.TCPRouteConfig{ + Routes: []*envoyv1.TCPRoute{ptr}, + } + lcg := &envoyv1.TCPProxyFilterConfig{ + StatPrefix: clusterName, + RouteConfig: lrs, + } + lfs := &envoyv1.NetworkFilter{ + Name: "tcp_proxy", + Config: lcg, + } + plds := &envoyv1.Listener{ + Name: clusterName, + Address: fmt.Sprintf("tcp://127.0.0.1:%d", port), + Filters: []*envoyv1.NetworkFilter{lfs}, + BindToPort: true, + } + ldsL = append(ldsL, plds) + } portProtocol, ok := service.Labels["port_protocol"] if !ok { logrus.Debugf("have no port Protocol") } if ok { - clusterName := fmt.Sprintf("%s_%s_%s_%d", namespace, serviceAlias, destServiceAlias, port) //TODO: support more protocol switch portProtocol { case "http", "https": @@ -279,29 +303,7 @@ func (d *DiscoverAction) DiscoverListeners( vhL = append(vhL, pvh) } continue - default: - ptr := &envoyv1.TCPRoute{ - Cluster: clusterName, - } - lrs := &envoyv1.TCPRouteConfig{ - Routes: []*envoyv1.TCPRoute{ptr}, - } - lcg := &envoyv1.TCPProxyFilterConfig{ - StatPrefix: clusterName, - RouteConfig: lrs, - } - lfs := &envoyv1.NetworkFilter{ - Name: "tcp_proxy", - Config: lcg, - } - plds := &envoyv1.Listener{ - Name: clusterName, - Address: fmt.Sprintf("tcp://127.0.0.1:%d", port), - Filters: []*envoyv1.NetworkFilter{lfs}, - BindToPort: true, - } - ldsL = append(ldsL, plds) continue } }