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 Nov 17, 2022
1 parent cede77e commit 69b3873
Show file tree
Hide file tree
Showing 25 changed files with 655 additions and 38 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/envoyproxy/gateway
go 1.18

require (
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc
github.com/envoyproxy/go-control-plane v0.10.3-0.20221028143534-ed9652aebfd9
github.com/go-logr/zapr v1.2.0
github.com/google/go-cmp v0.5.8
Expand Down Expand Up @@ -51,7 +52,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.7 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
Expand Down
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 @@ -424,6 +430,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 @@ -663,7 +674,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
22 changes: 21 additions & 1 deletion internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ 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"

"github.com/envoyproxy/gateway/internal/ir"
)

func buildXdsTCPListener(name, address string, port uint32) *listener.Listener {
func buildXdsListener(name, address string, port uint32) *listener.Listener {
accesslogAny, _ := anypb.New(stdoutFileAccessLog)
return &listener.Listener{
Name: name,
Expand Down Expand Up @@ -363,3 +364,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
Loading

0 comments on commit 69b3873

Please sign in to comment.