Skip to content

Commit

Permalink
feat(XDS): Add internal support for outbound UDP listeners
Browse files Browse the repository at this point in the history
This enables generators to add outbound listeners.
This is not first class support for UDP and only enables generators
to create listeners using UDP

Signed-off-by: Charly Molter <charly@koyeb.com>
  • Loading branch information
Charly Molter committed Mar 17, 2021
1 parent 0fd45e6 commit d768d81
Show file tree
Hide file tree
Showing 22 changed files with 178 additions and 122 deletions.
4 changes: 3 additions & 1 deletion pkg/xds/envoy/listeners/configurers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ func NetworkRBAC(statsName string, rbacEnabled bool, permission *mesh_core.Traff
})
}

func OutboundListener(listenerName string, address string, port uint32) ListenerBuilderOpt {
func OutboundListener(listenerName string, address string, port uint32, protocol core_xds.SocketAddressProtocol) ListenerBuilderOpt {
return ListenerBuilderOptFunc(func(config *ListenerBuilderConfig) {
config.AddV2(&v2.OutboundListenerConfigurer{
Protocol: protocol,
ListenerName: listenerName,
Address: address,
Port: port,
})
config.AddV3(&v3.OutboundListenerConfigurer{
Protocol: protocol,
ListenerName: listenerName,
Address: address,
Port: port,
Expand Down
17 changes: 9 additions & 8 deletions pkg/xds/envoy/listeners/v2/http_access_log_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
var _ = Describe("HttpAccessLogConfigurer", func() {

type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
statsName string
routeName string
backend *mesh_proto.LoggingBackend
expected string
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
statsName string
routeName string
backend *mesh_proto.LoggingBackend
expected string
}

DescribeTable("should generate proper Envoy config",
Expand Down Expand Up @@ -60,7 +61,7 @@ var _ = Describe("HttpAccessLogConfigurer", func() {

// when
listener, err := NewListenerBuilder(envoy.APIV2).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy.APIV2).
Configure(HttpConnectionManager(given.statsName)).
Configure(HttpAccessLog(mesh, envoy.TrafficDirectionOutbound, sourceService, destinationService, given.backend, proxy)))).
Expand Down
21 changes: 12 additions & 9 deletions pkg/xds/envoy/listeners/v2/http_outbound_route_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

core_xds "github.com/kumahq/kuma/pkg/core/xds"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
envoy_common "github.com/kumahq/kuma/pkg/xds/envoy"
. "github.com/kumahq/kuma/pkg/xds/envoy/listeners"
Expand All @@ -15,21 +17,22 @@ import (
var _ = Describe("HttpOutboundRouteConfigurer", func() {

type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
statsName string
service string
subsets []envoy_common.ClusterSubset
dpTags mesh_proto.MultiValueTagSet
expected string
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
statsName string
service string
subsets []envoy_common.ClusterSubset
dpTags mesh_proto.MultiValueTagSet
expected string
}

DescribeTable("should generate proper Envoy config",
func(given testCase) {
// when
listener, err := NewListenerBuilder(envoy_common.APIV2).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy_common.APIV2).
Configure(HttpConnectionManager(given.statsName)).
Configure(HttpOutboundRoute(given.service, given.subsets, given.dpTags)))).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ var _ = Describe("InboundListenerConfigurer", func() {
trafficDirection: INBOUND
address:
socketAddress:
protocol: UDP
address: 192.168.0.1
portValue: 8080
protocol: UDP
`,
}),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

core_xds "github.com/kumahq/kuma/pkg/core/xds"

. "github.com/kumahq/kuma/pkg/xds/envoy/listeners"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
Expand All @@ -18,6 +20,7 @@ var _ = Describe("MaxConnectAttemptsConfigurer", func() {
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
statsName string
clusters []envoy_common.ClusterSubset
maxConnectAttempts uint32
Expand All @@ -42,11 +45,7 @@ var _ = Describe("MaxConnectAttemptsConfigurer", func() {

// when
listener, err := NewListenerBuilder(envoy_common.APIV2).
Configure(OutboundListener(
given.listenerName,
given.listenerAddress,
given.listenerPort,
)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy_common.APIV2).
Configure(TcpProxy(given.statsName, given.clusters...)).
Configure(MaxConnectAttempts(retry)))).
Expand Down
17 changes: 9 additions & 8 deletions pkg/xds/envoy/listeners/v2/network_access_log_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
var _ = Describe("NetworkAccessLogConfigurer", func() {

type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
statsName string
clusters []envoy_common.ClusterSubset
backend *mesh_proto.LoggingBackend
expected string
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
statsName string
clusters []envoy_common.ClusterSubset
backend *mesh_proto.LoggingBackend
expected string
}

DescribeTable("should generate proper Envoy config",
Expand Down Expand Up @@ -60,7 +61,7 @@ var _ = Describe("NetworkAccessLogConfigurer", func() {

// when
listener, err := NewListenerBuilder(envoy_common.APIV2).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy_common.APIV2).
Configure(TcpProxy(given.statsName, given.clusters...)).
Configure(NetworkAccessLog(meshName, envoy_common.TrafficDirectionUnspecified, sourceService, destinationService, given.backend, proxy)))).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

core_xds "github.com/kumahq/kuma/pkg/core/xds"

. "github.com/kumahq/kuma/pkg/xds/envoy/listeners"

util_proto "github.com/kumahq/kuma/pkg/util/proto"
Expand All @@ -14,19 +16,20 @@ import (
var _ = Describe("OriginalDstForwarderConfigurer", func() {

type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
statsName string
clusters []envoy_common.ClusterSubset
expected string
listenerName string
listenerAddress string
listenerPort uint32
statsName string
listenerProtocol core_xds.SocketAddressProtocol
clusters []envoy_common.ClusterSubset
expected string
}

DescribeTable("should generate proper Envoy config",
func(given testCase) {
// when
listener, err := NewListenerBuilder(envoy_common.APIV2).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy_common.APIV2).
Configure(TcpProxy(given.statsName, given.clusters...)))).
Configure(OriginalDstForwarder()).
Expand Down
5 changes: 4 additions & 1 deletion pkg/xds/envoy/listeners/v2/outbound_listener_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package v2
import (
envoy_api "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoy_core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"

core_xds "github.com/kumahq/kuma/pkg/core/xds"
)

type OutboundListenerConfigurer struct {
ListenerName string
Address string
Port uint32
Protocol core_xds.SocketAddressProtocol
}

func (c *OutboundListenerConfigurer) Configure(l *envoy_api.Listener) error {
Expand All @@ -17,7 +20,7 @@ func (c *OutboundListenerConfigurer) Configure(l *envoy_api.Listener) error {
l.Address = &envoy_core.Address{
Address: &envoy_core.Address_SocketAddress{
SocketAddress: &envoy_core.SocketAddress{
Protocol: envoy_core.SocketAddress_TCP,
Protocol: envoy_core.SocketAddress_Protocol(c.Protocol),
Address: c.Address,
PortSpecifier: &envoy_core.SocketAddress_PortValue{
PortValue: c.Port,
Expand Down
28 changes: 23 additions & 5 deletions pkg/xds/envoy/listeners/v2/outbound_listener_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

core_xds "github.com/kumahq/kuma/pkg/core/xds"

"github.com/kumahq/kuma/pkg/xds/envoy"
. "github.com/kumahq/kuma/pkg/xds/envoy/listeners"

Expand All @@ -14,17 +16,18 @@ import (
var _ = Describe("OutboundListenerConfigurer", func() {

type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
expected string
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
expected string
}

DescribeTable("should generate proper Envoy config",
func(given testCase) {
// when
listener, err := NewListenerBuilder(envoy.APIV2).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Build()
// then
Expect(err).ToNot(HaveOccurred())
Expand All @@ -46,6 +49,21 @@ var _ = Describe("OutboundListenerConfigurer", func() {
socketAddress:
address: 192.168.0.1
portValue: 8080
`,
}),
Entry("basic UDP listener", testCase{
listenerName: "outbound:192.168.0.1:8080",
listenerAddress: "192.168.0.1",
listenerPort: 8080,
listenerProtocol: core_xds.SocketAddressProtocolUDP,
expected: `
name: outbound:192.168.0.1:8080
trafficDirection: OUTBOUND
address:
socketAddress:
protocol: UDP
address: 192.168.0.1
portValue: 8080
`,
}),
)
Expand Down
29 changes: 14 additions & 15 deletions pkg/xds/envoy/listeners/v2/retry_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

core_xds "github.com/kumahq/kuma/pkg/core/xds"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
mesh_core "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
Expand All @@ -16,27 +18,24 @@ import (

var _ = Describe("RetryConfigurer", func() {
type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
statsName string
service string
subsets []envoy_common.ClusterSubset
dpTags mesh_proto.MultiValueTagSet
protocol mesh_core.Protocol
retry *mesh_core.RetryResource
expected string
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
statsName string
service string
subsets []envoy_common.ClusterSubset
dpTags mesh_proto.MultiValueTagSet
protocol mesh_core.Protocol
retry *mesh_core.RetryResource
expected string
}

DescribeTable("should generate proper Envoy config",
func(given testCase) {
// when
listener, err := NewListenerBuilder(envoy_common.APIV2).
Configure(OutboundListener(
given.listenerName,
given.listenerAddress,
given.listenerPort,
)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy_common.APIV2).
Configure(HttpConnectionManager(given.statsName)).
Configure(HttpOutboundRoute(
Expand Down
2 changes: 1 addition & 1 deletion pkg/xds/envoy/listeners/v2/timeout_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func (c *TimeoutConfigurer) Configure(filterChain *envoy_listener.FilterChain) e
return nil
})
default:
return errors.Errorf("unsupported protocol %s", c.Protocol)
return errors.Errorf("unsupported listenerProtocol %s", c.Protocol)
}
}
17 changes: 9 additions & 8 deletions pkg/xds/envoy/listeners/v3/http_access_log_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
var _ = Describe("HttpAccessLogConfigurer", func() {

type testCase struct {
listenerName string
listenerAddress string
listenerPort uint32
statsName string
routeName string
backend *mesh_proto.LoggingBackend
expected string
listenerName string
listenerAddress string
listenerPort uint32
listenerProtocol core_xds.SocketAddressProtocol
statsName string
routeName string
backend *mesh_proto.LoggingBackend
expected string
}

DescribeTable("should generate proper Envoy config",
Expand Down Expand Up @@ -60,7 +61,7 @@ var _ = Describe("HttpAccessLogConfigurer", func() {

// when
listener, err := NewListenerBuilder(envoy.APIV3).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort)).
Configure(OutboundListener(given.listenerName, given.listenerAddress, given.listenerPort, given.listenerProtocol)).
Configure(FilterChain(NewFilterChainBuilder(envoy.APIV3).
Configure(HttpConnectionManager(given.statsName)).
Configure(HttpAccessLog(mesh, envoy.TrafficDirectionOutbound, sourceService, destinationService, given.backend, proxy)))).
Expand Down
Loading

0 comments on commit d768d81

Please sign in to comment.