Skip to content

Commit 1c2fbc4

Browse files
authored
Merge pull request #4454 from shuqz/conformance-no-matching-parent
[feat gw-api]handle noMatchingParent in route status
2 parents bfc7e6b + 8af0683 commit 1c2fbc4

File tree

7 files changed

+83
-24
lines changed

7 files changed

+83
-24
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ require (
7272
github.com/blang/semver/v4 v4.0.0 // indirect
7373
github.com/cespare/xxhash/v2 v2.3.0 // indirect
7474
github.com/chai2010/gettext-go v1.0.2 // indirect
75-
github.com/containerd/containerd v1.7.28 // indirect
75+
github.com/containerd/containerd v1.7.29 // indirect
7676
github.com/containerd/errdefs v0.3.0 // indirect
7777
github.com/containerd/log v0.1.0 // indirect
7878
github.com/containerd/platforms v0.2.1 // indirect
@@ -148,7 +148,6 @@ require (
148148
github.com/sirupsen/logrus v1.9.3 // indirect
149149
github.com/spf13/cast v1.7.0 // indirect
150150
github.com/spf13/cobra v1.9.1 // indirect
151-
github.com/stretchr/objx v0.5.2 // indirect
152151
github.com/valyala/bytebufferpool v1.0.0 // indirect
153152
github.com/valyala/fasthttp v1.34.0 // indirect
154153
github.com/x448/float16 v0.8.4 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
8787
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
8888
github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk=
8989
github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA=
90-
github.com/containerd/containerd v1.7.28 h1:Nsgm1AtcmEh4AHAJ4gGlNSaKgXiNccU270Dnf81FQ3c=
91-
github.com/containerd/containerd v1.7.28/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
90+
github.com/containerd/containerd v1.7.29 h1:90fWABQsaN9mJhGkoVnuzEY+o1XDPbg9BTC9QTAHnuE=
91+
github.com/containerd/containerd v1.7.29/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
9292
github.com/containerd/errdefs v0.3.0 h1:FSZgGOeK4yuT/+DnF07/Olde/q4KBoMsaamhXxIMDp4=
9393
github.com/containerd/errdefs v0.3.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
9494
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=

pkg/gateway/routeutils/route_attachment_helper.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// routeAttachmentHelper is an internal utility that is responsible for providing functionality related to route filtering.
99
type routeAttachmentHelper interface {
1010
doesRouteAttachToGateway(gw gwv1.Gateway, route preLoadRouteDescriptor) bool
11-
routeAllowsAttachmentToListener(listener gwv1.Listener, route preLoadRouteDescriptor) bool
11+
routeAllowsAttachmentToListener(gw gwv1.Gateway, listener gwv1.Listener, route preLoadRouteDescriptor) (bool, []RouteData)
1212
}
1313

1414
var _ routeAttachmentHelper = &routeAttachmentHelperImpl{}
@@ -56,19 +56,24 @@ func (rah *routeAttachmentHelperImpl) doesRouteAttachToGateway(gw gwv1.Gateway,
5656
// This function implements the Gateway API spec for route -> listener attachment.
5757
// This function assumes that the caller has already validated that the gateway that owns the listener allows for route
5858
// attachment.
59-
func (rah *routeAttachmentHelperImpl) routeAllowsAttachmentToListener(listener gwv1.Listener, route preLoadRouteDescriptor) bool {
59+
// Returns: (allowed, failedRouteDataList)
60+
func (rah *routeAttachmentHelperImpl) routeAllowsAttachmentToListener(gw gwv1.Gateway, listener gwv1.Listener, route preLoadRouteDescriptor) (bool, []RouteData) {
61+
var failedRouteData []RouteData
6062
for _, parentRef := range route.GetParentRefs() {
61-
6263
if parentRef.SectionName != nil && string(*parentRef.SectionName) != string(listener.Name) {
64+
rd := GenerateRouteData(false, true, string(gwv1.RouteReasonNoMatchingParent), RouteStatusInfoRejectedMessageParentSectionNameNotMatch, route.GetRouteNamespacedName(), route.GetRouteKind(), route.GetRouteGeneration(), gw)
65+
failedRouteData = append(failedRouteData, rd)
6366
continue
6467
}
6568

6669
if parentRef.Port != nil && *parentRef.Port != listener.Port {
70+
rd := GenerateRouteData(false, true, string(gwv1.RouteReasonNoMatchingParent), RouteStatusInfoRejectedMessageParentPortNotMatch, route.GetRouteNamespacedName(), route.GetRouteKind(), route.GetRouteGeneration(), gw)
71+
failedRouteData = append(failedRouteData, rd)
6772
continue
6873
}
6974

70-
return true
75+
return true, failedRouteData
7176
}
7277

73-
return false
78+
return false, failedRouteData
7479
}

pkg/gateway/routeutils/route_attachment_helper_test.go

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package routeutils
22

33
import (
4+
"testing"
5+
46
awssdk "github.com/aws/aws-sdk-go-v2/aws"
57
"github.com/go-logr/logr"
68
"github.com/stretchr/testify/assert"
79
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
810
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
9-
"testing"
1011
)
1112

1213
func Test_doesRouteAttachToGateway(t *testing.T) {
@@ -231,11 +232,18 @@ func Test_doesRouteAttachToGateway(t *testing.T) {
231232
}
232233

233234
func Test_routeAllowsAttachmentToListener(t *testing.T) {
235+
gw := gwv1.Gateway{
236+
ObjectMeta: metav1.ObjectMeta{
237+
Name: "gw",
238+
Namespace: "ns1",
239+
},
240+
}
234241
testCases := []struct {
235-
name string
236-
listener gwv1.Listener
237-
route preLoadRouteDescriptor
238-
result bool
242+
name string
243+
listener gwv1.Listener
244+
route preLoadRouteDescriptor
245+
result bool
246+
failedRouteCount int
239247
}{
240248
{
241249
name: "allows attachment section and port correct",
@@ -325,7 +333,8 @@ func Test_routeAllowsAttachmentToListener(t *testing.T) {
325333
Name: "sectionname",
326334
Port: 80,
327335
},
328-
result: true,
336+
result: true,
337+
failedRouteCount: 3,
329338
},
330339
{
331340
name: "multiple parent refs one ref none attachment",
@@ -357,6 +366,45 @@ func Test_routeAllowsAttachmentToListener(t *testing.T) {
357366
Name: "sectionname",
358367
Port: 80,
359368
},
369+
failedRouteCount: 4,
370+
},
371+
{
372+
name: "section name mismatch",
373+
route: convertHTTPRoute(gwv1.HTTPRoute{
374+
Spec: gwv1.HTTPRouteSpec{
375+
CommonRouteSpec: gwv1.CommonRouteSpec{
376+
ParentRefs: []gwv1.ParentReference{
377+
{
378+
SectionName: (*gwv1.SectionName)(awssdk.String("wrongsection")),
379+
},
380+
},
381+
},
382+
},
383+
}),
384+
listener: gwv1.Listener{
385+
Name: "sectionname",
386+
Port: 80,
387+
},
388+
failedRouteCount: 1,
389+
},
390+
{
391+
name: "port mismatch",
392+
route: convertHTTPRoute(gwv1.HTTPRoute{
393+
Spec: gwv1.HTTPRouteSpec{
394+
CommonRouteSpec: gwv1.CommonRouteSpec{
395+
ParentRefs: []gwv1.ParentReference{
396+
{
397+
Port: (*gwv1.PortNumber)(awssdk.Int32(443)),
398+
},
399+
},
400+
},
401+
},
402+
}),
403+
listener: gwv1.Listener{
404+
Name: "sectionname",
405+
Port: 80,
406+
},
407+
failedRouteCount: 1,
360408
},
361409
}
362410

@@ -365,7 +413,9 @@ func Test_routeAllowsAttachmentToListener(t *testing.T) {
365413
helper := &routeAttachmentHelperImpl{
366414
logger: logr.Discard(),
367415
}
368-
assert.Equal(t, tc.result, helper.routeAllowsAttachmentToListener(tc.listener, tc.route))
416+
allowed, failedRouteData := helper.routeAllowsAttachmentToListener(gw, tc.listener, tc.route)
417+
assert.Equal(t, tc.result, allowed)
418+
assert.Equal(t, tc.failedRouteCount, len(failedRouteData))
369419
})
370420
}
371421
}

pkg/gateway/routeutils/route_listener_mapper.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ func (ltr *listenerToRouteMapperImpl) mapGatewayAndRoutes(ctx context.Context, g
5959
for _, route := range routesForGateway {
6060
// We need to check both paths (route -> listener) and (listener -> route)
6161
// for connection viability.
62-
if !ltr.routeAttachmentHelper.routeAllowsAttachmentToListener(listener, route) {
62+
allowed, failedRouteDataList := ltr.routeAttachmentHelper.routeAllowsAttachmentToListener(gw, listener, route)
63+
// Collect any failed parentRefs no matter route is allowed to attach
64+
failedRoutes = append(failedRoutes, failedRouteDataList...)
65+
if !allowed {
6366
ltr.logger.V(1).Info("Route doesnt allow attachment")
6467
continue
6568
}

pkg/gateway/routeutils/route_listener_mapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func (m *mockRouteAttachmentHelper) doesRouteAttachToGateway(gw gwv1.Gateway, ro
4141
return m.routeGatewayMap[k]
4242
}
4343

44-
func (m *mockRouteAttachmentHelper) routeAllowsAttachmentToListener(listener gwv1.Listener, route preLoadRouteDescriptor) bool {
44+
func (m *mockRouteAttachmentHelper) routeAllowsAttachmentToListener(gw gwv1.Gateway, listener gwv1.Listener, route preLoadRouteDescriptor) (bool, []RouteData) {
4545
k := makeListenerAttachmentMapKey(listener, route)
46-
return m.routeListenerMap[k]
46+
return m.routeListenerMap[k], nil
4747
}
4848

4949
func Test_mapGatewayAndRoutes(t *testing.T) {

pkg/gateway/routeutils/route_reconciler_utils.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ type RouteReconcilerSubmitter interface {
4848
// constants
4949

5050
const (
51-
RouteStatusInfoAcceptedMessage = "Route is accepted by Gateway"
52-
RouteStatusInfoRejectedMessageNoMatchingHostname = "Listener does not allow route attachment, no matching hostname"
53-
RouteStatusInfoRejectedMessageNamespaceNotMatch = "Listener does not allow route attachment, namespace does not match between listener and route"
54-
RouteStatusInfoRejectedMessageKindNotMatch = "Listener does not allow route attachment, kind does not match between listener and route"
55-
RouteStatusInfoRejectedParentRefNotExist = "ParentRefDoesNotExist"
51+
RouteStatusInfoAcceptedMessage = "Route is accepted by Gateway"
52+
RouteStatusInfoRejectedMessageNoMatchingHostname = "Listener does not allow route attachment, no matching hostname"
53+
RouteStatusInfoRejectedMessageNamespaceNotMatch = "Listener does not allow route attachment, namespace does not match between listener and route"
54+
RouteStatusInfoRejectedMessageKindNotMatch = "Listener does not allow route attachment, kind does not match between listener and route"
55+
RouteStatusInfoRejectedParentRefNotExist = "ParentRefDoesNotExist"
56+
RouteStatusInfoRejectedMessageParentSectionNameNotMatch = "Route parentRef sectionName does not match listener name"
57+
RouteStatusInfoRejectedMessageParentPortNotMatch = "Route parentRef port does not match listener port"
5658
)
5759

5860
func GenerateRouteData(accepted bool, resolvedRefs bool, reason string, message string, routeNamespaceName types.NamespacedName, routeKind RouteKind, routeGeneration int64, gw gwv1.Gateway) RouteData {

0 commit comments

Comments
 (0)