Skip to content

Commit

Permalink
wip: add the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Sep 5, 2023
1 parent 6217a6d commit 5b74f9d
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
9 changes: 9 additions & 0 deletions internal/dataplane/parser/translators/l4route_atc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func ApplyExpressionToL4KongRoute(r *kongstate.Route) {

// TODO(rodman10): replace with helper function.
portMatchers := make([]atc.Matcher, 0, len(r.Destinations))
// (and (or sources) (or destinations))

// Kong route sources and destinations support IP criteria, but Gateway API routes do not (Listeners apply to all IPs
// assigned to a Gateway) and neither do our TCPIngress and UDPIngress CRs (we simply never added an IP field).
// If we multiplex multiple Gateways (with different assigned IPs) onto a single Kong instance, we would need to add
// IP criteria for full compliance. We already break this rule for HTTP Listeners, since Kong HTTP routes do not
// support sources and destinations.
//
// Neither GWAPI Routes nor TCP/UDPIngress support sources either, so this only adds destinations.
for _, dst := range r.Destinations {
portMatchers = append(portMatchers, atc.NewPredicate(atc.FieldNetDstPort, atc.OpEqual, atc.IntLiteral(*dst.Port)))
}
Expand Down
105 changes: 105 additions & 0 deletions internal/dataplane/parser/translators/l4route_atc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package translators

import (
"testing"

"github.com/kong/go-kong/kong"
"github.com/samber/lo"
"github.com/stretchr/testify/require"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane/kongstate"
)

func TestApplyExpressionToL4KongRoute(t *testing.T) {
testCases := []struct {
name string
route kong.Route
subExpr string
}{
{
name: "destination port",
subExpr: "net.dst.port == 1234",
route: kong.Route{
Destinations: []*kong.CIDRPort{
{
Port: lo.ToPtr(1234),
},
},
Protocols: []*string{
lo.ToPtr("tcp"),
},
},
},
{
name: "multiple destination ports",
subExpr: "(net.dst.port == 1234) || (net.dst.port == 5678)",
route: kong.Route{
Destinations: []*kong.CIDRPort{
{
Port: lo.ToPtr(1234),
},
{
Port: lo.ToPtr(5678),
},
},
Protocols: []*string{
lo.ToPtr("tcp"),
},
},
},
{
name: "SNI host",
subExpr: "tls.sni == \"example.com\"",
route: kong.Route{
SNIs: []*string{
lo.ToPtr("example.com"),
},
Protocols: []*string{
lo.ToPtr("tcp"),
},
},
},
{
name: "multiple SNI hosts",
subExpr: "(tls.sni == \"example.com\") || (tls.sni == \"example.net\")",
route: kong.Route{
SNIs: []*string{
lo.ToPtr("example.com"),
lo.ToPtr("example.net"),
},
Protocols: []*string{
lo.ToPtr("tcp"),
},
},
},
{
name: "SNI host and multiple destination ports",
subExpr: "(tls.sni == \"example.com\") && ((net.dst.port == 1234) || (net.dst.port == 5678))",
route: kong.Route{
Destinations: []*kong.CIDRPort{
{
Port: lo.ToPtr(1234),
},
{
Port: lo.ToPtr(5678),
},
},
SNIs: []*string{
lo.ToPtr("example.com"),
},
Protocols: []*string{
lo.ToPtr("tcp"),
},
},
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
wrapped := kongstate.Route{Route: tc.route}
ApplyExpressionToL4KongRoute(&wrapped)
require.Contains(t, *wrapped.Route.Expression, tc.subExpr)
})
}
}
1 change: 0 additions & 1 deletion test/integration/tcpingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var (
)

func TestTCPIngressEssentials(t *testing.T) {
skipTestForExpressionRouter(t)
ctx := context.Background()

t.Parallel()
Expand Down
1 change: 0 additions & 1 deletion test/integration/udpingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var udpMutex sync.Mutex
const coreDNSImage = "registry.k8s.io/coredns/coredns:v1.8.6"

func TestUDPIngressEssentials(t *testing.T) {
skipTestForExpressionRouter(t)
t.Parallel()

// Ensure no other UDP tests run concurrently to avoid fights over the port
Expand Down

0 comments on commit 5b74f9d

Please sign in to comment.