From 1aa0799c572c9d254b019d92624db06dc6781940 Mon Sep 17 00:00:00 2001 From: Mattia Lavacca Date: Wed, 19 Jun 2024 10:23:44 +0200 Subject: [PATCH] test: gatewayPort8080 conformance (#339) * test: gatewayPort8080 conformance Signed-off-by: Mattia Lavacca * feat: sectionName check on attachedRoutes Signed-off-by: Mattia Lavacca * chore: address comments Signed-off-by: Mattia Lavacca --------- Signed-off-by: Mattia Lavacca --- .../gateway/controller_reconciler_utils.go | 20 ++++++++- test/conformance/conformance_test.go | 41 +++++++++++-------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/controller/gateway/controller_reconciler_utils.go b/controller/gateway/controller_reconciler_utils.go index 6a975d94d..0ddf5015e 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,29 @@ func countAttachedRoutesForGatewayListener(ctx context.Context, g *gwtypes.Gatew ) } - count += int32(len(httpRoutes)) + count += countAttachedHTTPRoutes(listener.Name, httpRoutes) } } 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(parentRef gatewayv1.ParentReference) bool { + return parentRef.SectionName == nil || *parentRef.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 f283065c7..d2a39d8b4 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.Clone().Insert( + // add here the traditional compatible router specific features + ) + + expressionsRouterSupportedFeatures = commonSupportedFeatures.Clone().Insert( + // extended + features.SupportHTTPRouteMethodMatching, + features.SupportHTTPRouteQueryParamMatching, + ) ) type ConformanceConfig struct {