Skip to content

Commit 1941f61

Browse files
committed
Add default path with matches are nil
1 parent 633ccce commit 1941f61

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func TestBuildGraph(t *testing.T) {
399399
Spec: L7RouteSpec{
400400
Hostnames: gr.Spec.Hostnames,
401401
Rules: []RouteRule{
402-
createValidRuleWithBackendRefs([]gatewayv1.HTTPRouteMatch{}),
402+
createValidRuleWithBackendRefs(routeMatches),
403403
},
404404
},
405405
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ func processGRPCRouteRules(
132132
}
133133

134134
func convertGRPCMatches(grpcMatches []v1alpha2.GRPCRouteMatch) []v1.HTTPRouteMatch {
135+
pathValue := "/"
136+
pathType := v1.PathMatchType("PathPrefix")
137+
// If no matches are specified, the implementation MUST match every gRPC request.
138+
if len(grpcMatches) == 0 {
139+
return []v1.HTTPRouteMatch{
140+
{
141+
Path: &v1.HTTPPathMatch{
142+
Type: &pathType,
143+
Value: helpers.GetPointer(pathValue),
144+
},
145+
},
146+
}
147+
}
148+
135149
hms := make([]v1.HTTPRouteMatch, 0, len(grpcMatches))
136150

137151
for _, gm := range grpcMatches {
@@ -145,8 +159,6 @@ func convertGRPCMatches(grpcMatches []v1alpha2.GRPCRouteMatch) []v1.HTTPRouteMat
145159
}
146160
hm.Headers = hmHeaders
147161

148-
pathValue := "/"
149-
pathType := v1.PathMatchType("PathPrefix")
150162
if gm.Method != nil && gm.Method.Service != nil && gm.Method.Method != nil {
151163
// if method match is provided, service and method are required
152164
// as the only method type supported is exact.

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ func TestBuildGRPCRoute(t *testing.T) {
154154
[]v1alpha2.GRPCRouteRule{methodMatchRule, headersMatchRule},
155155
)
156156

157+
backendRef := v1.BackendRef{
158+
BackendObjectReference: v1.BackendObjectReference{
159+
Kind: helpers.GetPointer[v1.Kind]("Service"),
160+
Name: "service1",
161+
Namespace: helpers.GetPointer[v1.Namespace]("test"),
162+
Port: helpers.GetPointer[v1.PortNumber](80),
163+
},
164+
}
165+
166+
grpcBackendRef := v1alpha2.GRPCBackendRef{
167+
BackendRef: backendRef,
168+
}
169+
170+
grEmptyMatch := createGRPCRoute(
171+
"gr-1",
172+
gatewayNsName.Name,
173+
"example.com",
174+
[]v1alpha2.GRPCRouteRule{{BackendRefs: []v1alpha2.GRPCBackendRef{grpcBackendRef}}},
175+
)
176+
157177
grInvalidHostname := createGRPCRoute("gr-1", gatewayNsName.Name, "", []v1alpha2.GRPCRouteRule{methodMatchRule})
158178
grNotNGF := createGRPCRoute("gr", "some-gateway", "example.com", []v1alpha2.GRPCRouteRule{methodMatchRule})
159179

@@ -261,6 +281,35 @@ func TestBuildGRPCRoute(t *testing.T) {
261281
},
262282
name: "normal case with both",
263283
},
284+
{
285+
validator: createAllValidValidator(),
286+
gr: grEmptyMatch,
287+
expected: &L7Route{
288+
RouteType: RouteTypeGRPC,
289+
Source: grEmptyMatch,
290+
ParentRefs: []ParentRef{
291+
{
292+
Idx: 0,
293+
Gateway: gatewayNsName,
294+
SectionName: grEmptyMatch.Spec.ParentRefs[0].SectionName,
295+
},
296+
},
297+
Valid: true,
298+
Attachable: true,
299+
Spec: L7RouteSpec{
300+
Hostnames: grEmptyMatch.Spec.Hostnames,
301+
Rules: []RouteRule{
302+
{
303+
ValidMatches: true,
304+
ValidFilters: true,
305+
Matches: convertGRPCMatches(grEmptyMatch.Spec.Rules[0].Matches),
306+
RouteBackendRefs: []RouteBackendRef{{BackendRef: backendRef}},
307+
},
308+
},
309+
},
310+
},
311+
name: "valid rule with empty match",
312+
},
264313
{
265314
validator: createAllValidValidator(),
266315
gr: grInvalidMatchesEmptyMethodFields,

0 commit comments

Comments
 (0)