diff --git a/internal/ir/xds_test.go b/internal/ir/xds_test.go index 7e10a7779f0e..3e775622362b 100644 --- a/internal/ir/xds_test.go +++ b/internal/ir/xds_test.go @@ -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, @@ -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, @@ -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", }, diff --git a/internal/xds/translator/listener.go b/internal/xds/translator/listener.go index 957e94607ad7..ce3d35e7b04a 100644 --- a/internal/xds/translator/listener.go +++ b/internal/xds/translator/listener.go @@ -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" @@ -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 +} diff --git a/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend.yaml b/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend.yaml new file mode 100644 index 000000000000..e6d314d1f5e9 --- /dev/null +++ b/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend.yaml @@ -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 diff --git a/internal/xds/translator/testdata/in/xds-ir/multiple-simple-tcp-route-same-port.yaml b/internal/xds/translator/testdata/in/xds-ir/multiple-simple-tcp-route-same-port.yaml new file mode 100644 index 000000000000..324de2128389 --- /dev/null +++ b/internal/xds/translator/testdata/in/xds-ir/multiple-simple-tcp-route-same-port.yaml @@ -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 diff --git a/internal/xds/translator/testdata/in/xds-ir/tcp-route-complex.yaml b/internal/xds/translator/testdata/in/xds-ir/tcp-route-complex.yaml new file mode 100644 index 000000000000..1de28530c7d1 --- /dev/null +++ b/internal/xds/translator/testdata/in/xds-ir/tcp-route-complex.yaml @@ -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 diff --git a/internal/xds/translator/testdata/in/xds-ir/tcp-route-simple.yaml b/internal/xds/translator/testdata/in/xds-ir/tcp-route-simple.yaml new file mode 100644 index 000000000000..b88d57dd3994 --- /dev/null +++ b/internal/xds/translator/testdata/in/xds-ir/tcp-route-simple.yaml @@ -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 diff --git a/internal/xds/translator/testdata/in/xds-ir/tcp-route-weighted-backend.yaml b/internal/xds/translator/testdata/in/xds-ir/tcp-route-weighted-backend.yaml new file mode 100644 index 000000000000..fe02dec82c70 --- /dev/null +++ b/internal/xds/translator/testdata/in/xds-ir/tcp-route-weighted-backend.yaml @@ -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 diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.clusters.yaml new file mode 100644 index 000000000000..bb307d77082f --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.clusters.yaml @@ -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 diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.listeners.yaml new file mode 100644 index 000000000000..6c5555739793 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.listeners.yaml @@ -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 diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.routes.yaml new file mode 100644 index 000000000000..ed122e552aa2 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend.routes.yaml @@ -0,0 +1,10 @@ +- name: first-listener + virtualHosts: + - domains: + - '*' + name: first-listener + routes: + - match: + prefix: / + route: + cluster: first-route diff --git a/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.clusters.yaml new file mode 100644 index 000000000000..9b23924af5a5 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.clusters.yaml @@ -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 diff --git a/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.listeners.yaml new file mode 100644 index 000000000000..128fd616fca6 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.listeners.yaml @@ -0,0 +1,70 @@ +- 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 + filterChains: + - filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-simple + statPrefix: tcp + - filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-simple-1 + statPrefix: tcp + - filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-simple-2 + statPrefix: tcp + - filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-simple-3 + statPrefix: tcp + - filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-simple-4 + statPrefix: tcp + name: tcp-route-simple diff --git a/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.routes.yaml new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/multiple-simple-tcp-route-same-port.routes.yaml @@ -0,0 +1 @@ +[] diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.clusters.yaml new file mode 100644 index 000000000000..eb1b767d85c2 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.clusters.yaml @@ -0,0 +1,23 @@ +- commonLbConfig: + localityWeightedLbConfig: {} + connectTimeout: 5s + dnsLookupFamily: V4_ONLY + loadAssignment: + clusterName: tcp-route-complex + 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-complex + outlierDetection: {} + type: STATIC diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.listeners.yaml new file mode 100644 index 000000000000..dfb2a30acf0a --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.listeners.yaml @@ -0,0 +1,35 @@ +- 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 + filterChains: + - filterChainMatch: + serverNames: + - foo.com + - bar.com + - example.com + filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-complex + statPrefix: passthrough + listenerFilters: + - name: envoy.filters.listener.tls_inspector + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector + name: tcp-route-complex diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.routes.yaml new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-complex.routes.yaml @@ -0,0 +1 @@ +[] diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.clusters.yaml new file mode 100644 index 000000000000..54c0cd9b4b35 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.clusters.yaml @@ -0,0 +1,23 @@ +- 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 diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.listeners.yaml new file mode 100644 index 000000000000..05e159719fbb --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.listeners.yaml @@ -0,0 +1,26 @@ +- 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 + filterChains: + - filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-simple + statPrefix: tcp + name: tcp-route-simple diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.routes.yaml new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-simple.routes.yaml @@ -0,0 +1 @@ +[] diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.clusters.yaml new file mode 100644 index 000000000000..c24165c14ea8 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.clusters.yaml @@ -0,0 +1,37 @@ +- commonLbConfig: + localityWeightedLbConfig: {} + connectTimeout: 5s + dnsLookupFamily: V4_ONLY + loadAssignment: + clusterName: tcp-route-weighted-backend + 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: tcp-route-weighted-backend + outlierDetection: {} + type: STATIC diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.listeners.yaml new file mode 100644 index 000000000000..e16c3a238494 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.listeners.yaml @@ -0,0 +1,35 @@ +- 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 + filterChains: + - filterChainMatch: + serverNames: + - foo.com + - bar.com + - example.com + filters: + - name: envoy.filters.network.tcp_proxy + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy + accessLog: + - name: envoy.access_loggers.file + typedConfig: + '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog + path: /dev/stdout + cluster: tcp-route-weighted-backend + statPrefix: passthrough + listenerFilters: + - name: envoy.filters.listener.tls_inspector + typedConfig: + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector + name: tcp-route-weighted-backend diff --git a/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.routes.yaml new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/internal/xds/translator/testdata/out/xds-ir/tcp-route-weighted-backend.routes.yaml @@ -0,0 +1 @@ +[] diff --git a/internal/xds/translator/translator.go b/internal/xds/translator/translator.go index 78f0b241fa7f..a3bb2795df4d 100644 --- a/internal/xds/translator/translator.go +++ b/internal/xds/translator/translator.go @@ -26,7 +26,23 @@ func Translate(ir *ir.Xds) (*types.ResourceVersionTable, error) { tCtx := new(types.ResourceVersionTable) - for _, httpListener := range ir.HTTP { + if err := processHTTPListenerXdsTranslation(tCtx, ir.HTTP); err != nil { + return nil, err + } + + if err := processTCPListenerXdsTranslation(tCtx, ir.TCP); err != nil { + return nil, err + } + + if err := processUDPListenerXdsTranslation(tCtx, ir.UDP); err != nil { + return nil, err + } + + return tCtx, nil +} + +func processHTTPListenerXdsTranslation(tCtx *types.ResourceVersionTable, httpListeners []*ir.HTTPListener) error { + for _, httpListener := range httpListeners { addFilterChain := true var xdsRouteCfg *route.RouteConfiguration @@ -46,14 +62,14 @@ func Translate(ir *ir.Xds) (*types.ResourceVersionTable, error) { addFilterChain = false xdsRouteCfg = findXdsRouteConfig(tCtx, routeName) if xdsRouteCfg == nil { - return nil, errors.New("unable to find xds route config") + return errors.New("unable to find xds route config") } } } if addFilterChain { if err := addXdsHTTPFilterChain(xdsListener, httpListener); err != nil { - return nil, err + return err } } @@ -89,13 +105,15 @@ func Translate(ir *ir.Xds) (*types.ResourceVersionTable, error) { } xdsCluster := buildXdsCluster(httpRoute.Name, httpRoute.Destinations, httpListener.IsHTTP2) tCtx.AddXdsResource(resource.ClusterType, xdsCluster) - } xdsRouteCfg.VirtualHosts = append(xdsRouteCfg.VirtualHosts, vHost) } + return nil +} - for _, tcpListener := range ir.TCP { +func processTCPListenerXdsTranslation(tCtx *types.ResourceVersionTable, tcpListeners []*ir.TCPListener) error { + for _, tcpListener := range tcpListeners { // 1:1 between IR TCPListener and xDS Cluster xdsCluster := buildXdsCluster(tcpListener.Name, tcpListener.Destinations, false /*isHTTP2 */) tCtx.AddXdsResource(resource.ClusterType, xdsCluster) @@ -108,11 +126,14 @@ func Translate(ir *ir.Xds) (*types.ResourceVersionTable, error) { } if err := addXdsTCPFilterChain(xdsListener, tcpListener, xdsCluster.Name); err != nil { - return nil, err + return err } } + return nil +} - for _, udpListener := range ir.UDP { +func processUDPListenerXdsTranslation(tCtx *types.ResourceVersionTable, udpListeners []*ir.UDPListener) error { + for _, udpListener := range udpListeners { // 1:1 between IR UDPListener and xDS Cluster xdsCluster := buildXdsCluster(udpListener.Name, udpListener.Destinations, false /*isHTTP2 */) tCtx.AddXdsResource(resource.ClusterType, xdsCluster) @@ -121,11 +142,11 @@ func Translate(ir *ir.Xds) (*types.ResourceVersionTable, error) { // translator xdsListener, err := buildXdsUDPListener(xdsCluster.Name, udpListener) if err != nil { - return nil, multierror.Append(err, errors.New("error building xds cluster")) + return multierror.Append(err, errors.New("error building xds cluster")) } tCtx.AddXdsResource(resource.ListenerType, xdsListener) } - return tCtx, nil + return nil } // findXdsListener finds a xds listener with the same address, port and protocol, and returns nil if there is no match. @@ -162,22 +183,3 @@ func findXdsRouteConfig(tCtx *types.ResourceVersionTable, name string) *route.Ro return 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 -} diff --git a/internal/xds/translator/translator_test.go b/internal/xds/translator/translator_test.go index a785ee4e6b31..3d8df2245348 100644 --- a/internal/xds/translator/translator_test.go +++ b/internal/xds/translator/translator_test.go @@ -67,6 +67,21 @@ func TestTranslate(t *testing.T) { { name: "tls-route-passthrough", }, + { + name: "tcp-route-simple", + }, + { + name: "tcp-route-complex", + }, + { + name: "multiple-simple-tcp-route-same-port", + }, + { + name: "http-route-weighted-backend", + }, + { + name: "tcp-route-weighted-backend", + }, { name: "multiple-listeners-same-port", requireSecrets: true,