Skip to content

Commit

Permalink
test: gatewayPort8080 conformance (#339)
Browse files Browse the repository at this point in the history
* test: gatewayPort8080 conformance

Signed-off-by: Mattia Lavacca <[email protected]>

* feat: sectionName check on attachedRoutes

Signed-off-by: Mattia Lavacca <[email protected]>

* chore: address comments

Signed-off-by: Mattia Lavacca <[email protected]>

---------

Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca authored Jun 19, 2024
1 parent 3530885 commit 1aa0799
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
20 changes: 18 additions & 2 deletions controller/gateway/controller_reconciler_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
41 changes: 24 additions & 17 deletions test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1aa0799

Please sign in to comment.