From e9de696a40a17ad7f0de15eb2e01e805a04d01b5 Mon Sep 17 00:00:00 2001 From: Mattia Lavacca Date: Mon, 17 Jun 2024 11:49:23 +0200 Subject: [PATCH 1/3] test: gatewayPort8080 conformance Signed-off-by: Mattia Lavacca --- test/conformance/conformance_test.go | 41 ++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index f283065c7..f232c47be 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -42,24 +42,31 @@ var skippedTestsForTraditionalCompatibleRouter = []string{ tests.HTTPRouteWeight.ShortName, } -var traditionalCompatibleRouterSupportedFeatures = sets.New( - // core features - features.SupportHTTPRoute, - // extended - features.SupportHTTPRouteResponseHeaderModification, - features.SupportHTTPRoutePathRewrite, - features.SupportHTTPRouteHostRewrite, -) +var ( + commonSupportedFeatures = sets.New( + // core features + features.SupportHTTPRoute, + features.SupportGateway, + features.SupportReferenceGrant, + + // Gateway extended + features.SupportGatewayPort8080, + + // HTTPRoute extended + features.SupportHTTPRouteResponseHeaderModification, + features.SupportHTTPRoutePathRewrite, + features.SupportHTTPRouteHostRewrite, + ) -var expressionsRouterSupportedFeatures = sets.New( - // core features - features.SupportHTTPRoute, - // extended - features.SupportHTTPRouteResponseHeaderModification, - features.SupportHTTPRouteMethodMatching, - features.SupportHTTPRouteQueryParamMatching, - features.SupportHTTPRoutePathRewrite, - features.SupportHTTPRouteHostRewrite, + traditionalCompatibleRouterSupportedFeatures = commonSupportedFeatures.Insert( + // add here the traditional compatible router specific features + ) + + expressionsRouterSupportedFeatures = commonSupportedFeatures.Insert( + // extended + features.SupportHTTPRouteMethodMatching, + features.SupportHTTPRouteQueryParamMatching, + ) ) type ConformanceConfig struct { From d997a4901a34f3a812db3e89cd55237f444f28c8 Mon Sep 17 00:00:00 2001 From: Mattia Lavacca Date: Tue, 18 Jun 2024 10:43:18 +0200 Subject: [PATCH 2/3] feat: sectionName check on attachedRoutes Signed-off-by: Mattia Lavacca --- .../gateway/controller_reconciler_utils.go | 17 +++++++++++++++-- test/conformance/conformance_test.go | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/controller/gateway/controller_reconciler_utils.go b/controller/gateway/controller_reconciler_utils.go index 6a975d94d..94c3c5c38 100644 --- a/controller/gateway/controller_reconciler_utils.go +++ b/controller/gateway/controller_reconciler_utils.go @@ -702,7 +702,7 @@ func countAttachedRoutesForGatewayListener(ctx context.Context, g *gwtypes.Gatew client.ObjectKeyFromObject(g), err, ) } - count += int32(len(httpRoutes)) + count += countAttachedHTTPRoutes(listener.Name, httpRoutes) default: return 0, fmt.Errorf("unsupported route kind: %T", k) } @@ -723,13 +723,26 @@ func countAttachedRoutesForGatewayListener(ctx context.Context, g *gwtypes.Gatew ) } - count += int32(len(httpRoutes)) + count += countAttachedHTTPRoutes(listener.Name, httpRoutes) } } return count, nil } +func countAttachedHTTPRoutes(listenerName gatewayv1.SectionName, httpRoutes []gatewayv1.HTTPRoute) int32 { + var count int32 + for _, httpRoute := range httpRoutes { + if lo.ContainsBy(httpRoute.Spec.ParentRefs, func(item gatewayv1.ParentReference) bool { + return item.SectionName == nil || *item.SectionName == listenerName + }) { + count++ + } + } + + return count +} + // setConflicted sets the gateway Conflicted condition according to the Gateway API specification. func (g *gatewayConditionsAndListenersAwareT) setConflicted() { for i, l := range g.Spec.Listeners { diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index f232c47be..d2a39d8b4 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -58,11 +58,11 @@ var ( features.SupportHTTPRouteHostRewrite, ) - traditionalCompatibleRouterSupportedFeatures = commonSupportedFeatures.Insert( + traditionalCompatibleRouterSupportedFeatures = commonSupportedFeatures.Clone().Insert( // add here the traditional compatible router specific features ) - expressionsRouterSupportedFeatures = commonSupportedFeatures.Insert( + expressionsRouterSupportedFeatures = commonSupportedFeatures.Clone().Insert( // extended features.SupportHTTPRouteMethodMatching, features.SupportHTTPRouteQueryParamMatching, From b15962ed2472dd35eb04fd4e818b7cde579ef90c Mon Sep 17 00:00:00 2001 From: Mattia Lavacca Date: Wed, 19 Jun 2024 09:57:06 +0200 Subject: [PATCH 3/3] chore: address comments Signed-off-by: Mattia Lavacca --- controller/gateway/controller_reconciler_utils.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/controller/gateway/controller_reconciler_utils.go b/controller/gateway/controller_reconciler_utils.go index 94c3c5c38..0ddf5015e 100644 --- a/controller/gateway/controller_reconciler_utils.go +++ b/controller/gateway/controller_reconciler_utils.go @@ -730,11 +730,14 @@ func countAttachedRoutesForGatewayListener(ctx context.Context, g *gwtypes.Gatew return count, nil } +// countAttachedHTTPRoutes counts the number of attached HTTPRoutes for a given listener, +// taking into account the ParentRefs' sectionName. func countAttachedHTTPRoutes(listenerName gatewayv1.SectionName, httpRoutes []gatewayv1.HTTPRoute) int32 { var count int32 + for _, httpRoute := range httpRoutes { - if lo.ContainsBy(httpRoute.Spec.ParentRefs, func(item gatewayv1.ParentReference) bool { - return item.SectionName == nil || *item.SectionName == listenerName + if lo.ContainsBy(httpRoute.Spec.ParentRefs, func(parentRef gatewayv1.ParentReference) bool { + return parentRef.SectionName == nil || *parentRef.SectionName == listenerName }) { count++ }