Skip to content

Commit

Permalink
feat: add support for TCP Route
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
Xunzhuo committed Jan 3, 2023
1 parent 22131aa commit 5ffa0e6
Show file tree
Hide file tree
Showing 24 changed files with 646 additions and 29 deletions.
20 changes: 19 additions & 1 deletion internal/ir/xds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ var (
TLS: &TLSInspectorConfig{SNIs: []string{"example.com"}},
Destinations: []*RouteDestination{&happyRouteDestination},
}
emptySNITCPListenerTLSPassthrough = TCPListener{
Name: "empty-sni",
Address: "0.0.0.0",
Port: 80,
Destinations: []*RouteDestination{&happyRouteDestination},
}
invalidNameTCPListenerTLSPassthrough = TCPListener{
Address: "0.0.0.0",
Port: 80,
Expand Down Expand Up @@ -525,6 +531,11 @@ func TestValidateTCPListener(t *testing.T) {
input: happyTCPListenerTLSPassthrough,
want: nil,
},
{
name: "tcp empty SNIs",
input: emptySNITCPListenerTLSPassthrough,
want: nil,
},
{
name: "tls passthrough invalid name",
input: invalidNameTCPListenerTLSPassthrough,
Expand Down Expand Up @@ -794,7 +805,14 @@ func TestValidateRouteDestination(t *testing.T) {
want: ErrRouteDestinationHostInvalid,
},
{
name: "invalid port",
name: "missing ip",
input: RouteDestination{
Port: 8080,
},
want: ErrRouteDestinationHostInvalid,
},
{
name: "missing port",
input: RouteDestination{
Host: "10.11.12.13",
},
Expand Down
20 changes: 20 additions & 0 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tcp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
udp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/udp/udp_proxy/v3"
tls "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"google.golang.org/protobuf/types/known/anypb"

Expand Down Expand Up @@ -359,3 +360,22 @@ func buildXdsUDPListener(clusterName string, udpListener *ir.UDPListener) (*list

return xdsListener, nil
}

// Point to xds cluster.
func makeConfigSource() *core.ConfigSource {
source := &core.ConfigSource{}
source.ResourceApiVersion = resource.DefaultAPIVersion
source.ConfigSourceSpecifier = &core.ConfigSource_ApiConfigSource{
ApiConfigSource: &core.ApiConfigSource{
TransportApiVersion: resource.DefaultAPIVersion,
ApiType: core.ApiConfigSource_DELTA_GRPC,
SetNodeOnFirstMessageOnly: true,
GrpcServices: []*core.GrpcService{{
TargetSpecifier: &core.GrpcService_EnvoyGrpc_{
EnvoyGrpc: &core.GrpcService_EnvoyGrpc{ClusterName: "xds_cluster"},
},
}},
},
}
return source
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
http:
- name: "first-listener"
address: "0.0.0.0"
port: 10080
hostnames:
- "*"
routes:
- name: "first-route"
destinations:
- host: "1.1.1.1"
port: 50001
weight: 20
- host: "2.2.2.2"
port: 50002
weight: 40
- host: "3.3.3.3"
port: 50003
weight: 20
- host: "4.4.4.4"
port: 50004
weight: 20
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
tcp:
- name: "tcp-route-simple"
address: "0.0.0.0"
port: 10080
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
- name: "tcp-route-simple-1"
address: "0.0.0.0"
port: 10080
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
- name: "tcp-route-simple-2"
address: "0.0.0.0"
port: 10080
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
- name: "tcp-route-simple-3"
address: "0.0.0.0"
port: 10080
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
- name: "tcp-route-simple-4"
address: "0.0.0.0"
port: 10080
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
14 changes: 14 additions & 0 deletions internal/xds/translator/testdata/in/xds-ir/tcp-route-complex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tcp:
- name: "tcp-route-complex"
address: "0.0.0.0"
port: 10080
tls:
snis:
- foo.com
- bar.com
- example.com
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tcp:
- name: "tcp-route-simple"
address: "0.0.0.0"
port: 10080
destinations:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tcp:
- name: "tcp-route-weighted-backend"
address: "0.0.0.0"
port: 10080
tls:
snis:
- foo.com
- bar.com
- example.com
destinations:
- host: "1.1.1.1"
port: 50001
weight: 20
- host: "2.2.2.2"
port: 50002
weight: 40
- host: "3.3.3.3"
port: 50003
weight: 20
- host: "4.4.4.4"
port: 50004
weight: 20
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: first-route
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.1.1.1
portValue: 50001
loadBalancingWeight: 20
- endpoint:
address:
socketAddress:
address: 2.2.2.2
portValue: 50002
loadBalancingWeight: 40
- endpoint:
address:
socketAddress:
address: 3.3.3.3
portValue: 50003
loadBalancingWeight: 20
- endpoint:
address:
socketAddress:
address: 4.4.4.4
portValue: 50004
loadBalancingWeight: 20
loadBalancingWeight: 1
locality: {}
name: first-route
outlierDetection: {}
type: STATIC
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
defaultFilterChain:
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
rds:
configSource:
apiConfigSource:
apiType: DELTA_GRPC
grpcServices:
- envoyGrpc:
clusterName: xds_cluster
setNodeOnFirstMessageOnly: true
transportApiVersion: V3
resourceApiVersion: V3
routeConfigName: first-listener
statPrefix: http
name: first-listener
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: first-listener
virtualHosts:
- domains:
- '*'
name: first-listener
routes:
- match:
prefix: /
route:
cluster: first-route
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: tcp-route-simple
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
- endpoint:
address:
socketAddress:
address: 5.6.7.8
portValue: 50001
loadBalancingWeight: 1
locality: {}
name: tcp-route-simple
outlierDetection: {}
type: STATIC
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: tcp-route-simple-1
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
- endpoint:
address:
socketAddress:
address: 5.6.7.8
portValue: 50001
loadBalancingWeight: 1
locality: {}
name: tcp-route-simple-1
outlierDetection: {}
type: STATIC
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: tcp-route-simple-2
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
- endpoint:
address:
socketAddress:
address: 5.6.7.8
portValue: 50001
loadBalancingWeight: 1
locality: {}
name: tcp-route-simple-2
outlierDetection: {}
type: STATIC
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: tcp-route-simple-3
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
- endpoint:
address:
socketAddress:
address: 5.6.7.8
portValue: 50001
loadBalancingWeight: 1
locality: {}
name: tcp-route-simple-3
outlierDetection: {}
type: STATIC
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: tcp-route-simple-4
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
- endpoint:
address:
socketAddress:
address: 5.6.7.8
portValue: 50001
loadBalancingWeight: 1
locality: {}
name: tcp-route-simple-4
outlierDetection: {}
type: STATIC
Loading

0 comments on commit 5ffa0e6

Please sign in to comment.