Skip to content

Commit

Permalink
More test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Lubron Zhan <lubronzhan@gmail.com>
  • Loading branch information
lubronzhan committed Jul 17, 2024
1 parent dcf568b commit 0f02e9c
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 164 deletions.
10 changes: 6 additions & 4 deletions internal/dag/gatewayapi_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,9 @@ func (p *GatewayAPIProcessor) computeHTTPRouteForListener(
timeoutPolicy)
}

// check all the routes whether there is conflict against previous rules
// Check all the routes whether there is conflict against previous rules.
if !p.hasConflictRoute(listener, hosts, routes) {
// add the route if there is conflict
// Add the route if there is no conflict at the same rule level.
// Add each route to the relevant vhost(s)/svhosts(s).
for host := range hosts {
for _, route := range routes {
Expand All @@ -1507,6 +1507,7 @@ func (p *GatewayAPIProcessor) computeHTTPRouteForListener(
// No rules under the route is valid, mark it as not accepted.
addRouteNotAcceptedConditionDueToMatchConflict(routeAccessor, KindHTTPRoute)
} else if invalidRuleCnt > 0 {
// Some of the rules are conflicted, mark it as partially invalid.
addRoutePartiallyInvalidConditionDueToMatchPartiallyConflict(routeAccessor, KindHTTPRoute)
}
}
Expand Down Expand Up @@ -1657,9 +1658,9 @@ func (p *GatewayAPIProcessor) computeGRPCRouteForListener(route *gatewayapi_v1.G
nil,
)

// check all the routes whether there is conflict against previous rules
// Check all the routes whether there is conflict against previous rules.
if !p.hasConflictRoute(listener, hosts, routes) {
// add the route if there is conflict
// Add the route if there is no conflict at the same rule level.
// Add each route to the relevant vhost(s)/svhosts(s).
for host := range hosts {
for _, route := range routes {
Expand All @@ -1684,6 +1685,7 @@ func (p *GatewayAPIProcessor) computeGRPCRouteForListener(route *gatewayapi_v1.G
// No rules under the route is valid, mark it as not accepted.
addRouteNotAcceptedConditionDueToMatchConflict(routeAccessor, KindGRPCRoute)
} else if invalidRuleCnt > 0 {
// Some of the rules are conflicted, mark it as partially invalid.
addRoutePartiallyInvalidConditionDueToMatchPartiallyConflict(routeAccessor, KindGRPCRoute)
}

Expand Down
39 changes: 38 additions & 1 deletion internal/dag/gatewayapi_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ func TestHasConflictRoute(t *testing.T) {
expectedConflict bool
}{
{
name: "There are 2 existing route, the 3rd route to add doesn't have conflict, listen doesn't have tls, no conflict expected",
name: "There are 2 existing httproute, the 3rd route to add doesn't have conflict, listen doesn't have tls, no conflict expected",
existingRoutes: []*Route{
{
Name: "route1",
Expand Down Expand Up @@ -1511,6 +1511,43 @@ func TestHasConflictRoute(t *testing.T) {
},
listener: listener,
},
{
name: "There are 2 existing grpcroute, the 3rd route to add doesn't have conflict, listen doesn't have tls, no conflict expected",
existingRoutes: []*Route{
{
Name: "route1",
Namespace: "default",
PathMatchCondition: prefixSegment("/path1"),
HeaderMatchConditions: []HeaderMatchCondition{
{Name: ":authority", MatchType: HeaderMatchTypeRegex, Value: "^[a-z0-9]([-a-z0-9]*[a-z0-9])?\\.example\\.com(:[0-9]+)?"},
},
QueryParamMatchConditions: []QueryParamMatchCondition{
{Name: "param-1", Value: "value-1", MatchType: QueryParamMatchTypeExact},
},
},
{
Kind: KindGRPCRoute,
Name: "route2",
Namespace: "default",
PathMatchCondition: prefixSegment("/path2"),
HeaderMatchConditions: []HeaderMatchCondition{
{Name: "version", Value: "2", MatchType: "exact", Invert: false},
},
},
},
routes: []*Route{
{
Kind: KindGRPCRoute,
Name: "route3",
Namespace: "default",
PathMatchCondition: prefixSegment("/path2"),
HeaderMatchConditions: []HeaderMatchCondition{
{Name: "e-tag", Value: "abc", MatchType: "contains", Invert: true},
},
},
},
listener: listener,
},
{
name: "There are 2 existing route, the 3rd route to add doesn't have conflict, listen has tls, no conflict expected",
existingRoutes: []*Route{
Expand Down
Loading

0 comments on commit 0f02e9c

Please sign in to comment.