Skip to content

Commit 38538dc

Browse files
committed
fix test description
1 parent be047a9 commit 38538dc

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

internal/mode/static/state/graph/gateway_listener.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,15 @@ func validateListenerHostname(listener v1.Listener) (conds []conditions.Conditio
225225
return nil, true
226226
}
227227

228+
// getAndValidateListenerSupportedKinds validates the route kind and returns the supported kinds for the listener.
229+
// The supported kinds are determined based on the listener's allowedRoutes field.
230+
// If the listener does not specify allowedRoutes, listener determines allowed routes based on its protocol.
228231
func getAndValidateListenerSupportedKinds(listener v1.Listener) (
229232
[]conditions.Condition,
230233
[]v1.RouteGroupKind,
231234
) {
232235
var conds []conditions.Condition
233-
supportedKinds := make([]v1.RouteGroupKind, 0)
236+
var supportedKinds []v1.RouteGroupKind
234237

235238
validRouteKind := func(kind v1.RouteGroupKind) bool {
236239
if kind.Kind != v1.Kind(kinds.HTTPRoute) && kind.Kind != v1.Kind(kinds.GRPCRoute) {
@@ -243,6 +246,7 @@ func getAndValidateListenerSupportedKinds(listener v1.Listener) (
243246
}
244247

245248
if listener.AllowedRoutes != nil && listener.AllowedRoutes.Kinds != nil {
249+
supportedKinds = make([]v1.RouteGroupKind, 0, len(listener.AllowedRoutes.Kinds))
246250
for _, kind := range listener.AllowedRoutes.Kinds {
247251
if !validRouteKind(kind) {
248252
msg := fmt.Sprintf("Unsupported route kind \"%s/%s\"", *kind.Group, kind.Kind)

internal/mode/static/state/graph/gateway_listener_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func TestGetAndValidateListenerSupportedKinds(t *testing.T) {
314314
protocol: v1.TCPProtocolType,
315315
expectErr: false,
316316
name: "unsupported protocol is ignored",
317-
expected: []v1.RouteGroupKind{},
317+
expected: nil,
318318
},
319319
{
320320
protocol: v1.HTTPProtocolType,

internal/mode/static/state/graph/gateway_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ func TestBuildGateway(t *testing.T) {
543543
Conditions: staticConds.NewListenerUnsupportedProtocol(
544544
`protocol: Unsupported value: "TCP": supported values: "HTTP", "HTTPS"`,
545545
),
546-
Routes: map[RouteKey]*L7Route{},
547-
SupportedKinds: []v1.RouteGroupKind{},
546+
Routes: map[RouteKey]*L7Route{},
548547
},
549548
},
550549
Valid: true,

internal/mode/static/state/graph/route_common.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,6 @@ func isRouteNamespaceAllowedByListener(
535535
}
536536

537537
// isRouteKindAllowedByListener checks if the route is allowed to attach to the listener.
538-
// If the listener specifies allowed kinds, the route kind must be in the list.
539-
// If the listener does not specify allowedRoutes, allowed routes are determined using the listener protocol.
540538
func isRouteTypeAllowedByListener(listener *Listener, routeType RouteType) bool {
541539
for _, kind := range listener.SupportedKinds {
542540
if kind.Kind == convertRouteType(routeType) {
@@ -553,7 +551,7 @@ func convertRouteType(routeType RouteType) v1.Kind {
553551
case RouteTypeGRPC:
554552
return kinds.GRPCRoute
555553
default:
556-
return ""
554+
panic(fmt.Sprintf("unsupported route type: %s", routeType))
557555
}
558556
}
559557

internal/mode/static/state/graph/route_common_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ func TestAllowedRouteType(t *testing.T) {
17431743
expResult bool
17441744
}{
17451745
{
1746-
name: "grpcRoute attaches to listener with allowedRoutes set to grpcRoute",
1746+
name: "grpcRoute is allowed when listener supports grpcRoute kind",
17471747
routeType: RouteTypeGRPC,
17481748
listener: &Listener{
17491749
SupportedKinds: []gatewayv1.RouteGroupKind{
@@ -1753,7 +1753,7 @@ func TestAllowedRouteType(t *testing.T) {
17531753
expResult: true,
17541754
},
17551755
{
1756-
name: "grpcRoute attaches to listener with allowedRoutes set to grpcRoute and httpRoute",
1756+
name: "grpcRoute is allowed when listener supports grpcRoute and httpRoute kind",
17571757
routeType: RouteTypeGRPC,
17581758
listener: &Listener{
17591759
SupportedKinds: []gatewayv1.RouteGroupKind{
@@ -1764,7 +1764,7 @@ func TestAllowedRouteType(t *testing.T) {
17641764
expResult: true,
17651765
},
17661766
{
1767-
name: "grpcRoute not allowed to attach to listener with allowedRoutes set to httpRoute",
1767+
name: "grpcRoute is allowed when listener supports httpRoute kind",
17681768
routeType: RouteTypeGRPC,
17691769
listener: &Listener{
17701770
SupportedKinds: []gatewayv1.RouteGroupKind{
@@ -1774,7 +1774,7 @@ func TestAllowedRouteType(t *testing.T) {
17741774
expResult: false,
17751775
},
17761776
{
1777-
name: "httpRoute not allowed to attach to listener with allowedRoutes set to grpcRoute",
1777+
name: "httpRoute not allowed when listener supports grpcRoute kind",
17781778
routeType: RouteTypeHTTP,
17791779
listener: &Listener{
17801780
SupportedKinds: []gatewayv1.RouteGroupKind{

0 commit comments

Comments
 (0)