Skip to content

Commit 920d1a6

Browse files
authored
Merge pull request #2256 from LiorLieberman/grpc-mutlitple-mirrors
Grpc mutlitple mirrors
2 parents aef23fb + 78fcd34 commit 920d1a6

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

apis/v1alpha2/grpcroute_types.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ type GRPCRouteRule struct {
223223
// - Implementation-specific custom filters have no API guarantees across
224224
// implementations.
225225
//
226-
// Specifying a core filter multiple times has unspecified or
227-
// implementation-specific conformance.
226+
// Specifying the same filter multiple times is not supported unless explicitly
227+
// indicated in the filter.
228228
//
229229
// If an implementation can not support a combinations of filters, they must clearly
230230
// document that limitation. In cases where incompatible or unsupported
@@ -515,6 +515,10 @@ type GRPCRouteFilter struct {
515515
// Requests are sent to the specified destination, but responses from
516516
// that destination are ignored.
517517
//
518+
// This filter can be used multiple times within the same rule. Note that
519+
// not all implementations will be able to support mirroring to multiple
520+
// backends.
521+
//
518522
// Support: Extended
519523
//
520524
// +optional
@@ -527,6 +531,7 @@ type GRPCRouteFilter struct {
527531
//
528532
// Support: Implementation-specific
529533
//
534+
// This filter can be used multiple times within the same rule.
530535
// +optional
531536
ExtensionRef *LocalObjectReference `json:"extensionRef,omitempty"`
532537
}

apis/v1alpha2/validation/grpcroute.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
// repeated multiple times in a rule.
3333
repeatableGRPCRouteFilters = []gatewayv1a2.GRPCRouteFilterType{
3434
gatewayv1a2.GRPCRouteFilterExtensionRef,
35+
gatewayv1a2.GRPCRouteFilterRequestMirror,
3536
}
3637
validServiceName = `^(?i)\.?[a-z_][a-z_0-9]*(\.[a-z_][a-z_0-9]*)*$`
3738
validServiceNameRegex = regexp.MustCompile(validServiceName)
@@ -165,7 +166,7 @@ func validateGRPCRouteFilters(filters []gatewayv1a2.GRPCRouteFilter, path *field
165166
}
166167
errs = append(errs, validateGRPCRouteFilterType(filter, path.Index(i))...)
167168
}
168-
// custom filters don't have any validation
169+
// repeatableGRPCRouteFilters filters can be used more than once
169170
for _, key := range repeatableGRPCRouteFilters {
170171
delete(counts, key)
171172
}

apis/v1alpha2/validation/grpcroute_test.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,38 @@ func TestValidateGRPCRoute(t *testing.T) {
236236
}},
237237
},
238238
},
239+
},
240+
{
241+
name: "invalid GRPCRoute with duplicate RequestHeaderModifier filters",
242+
rules: []gatewayv1a2.GRPCRouteRule{
243+
{
244+
Filters: []gatewayv1a2.GRPCRouteFilter{{
245+
Type: "RequestHeaderModifier",
246+
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
247+
Set: []gatewayv1a2.HTTPHeader{
248+
{
249+
Name: "special-header",
250+
Value: "foo",
251+
},
252+
},
253+
},
254+
}, {
255+
Type: "RequestHeaderModifier",
256+
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
257+
Add: []gatewayv1a2.HTTPHeader{
258+
{
259+
Name: "my-header",
260+
Value: "bar",
261+
},
262+
},
263+
},
264+
}},
265+
},
266+
},
239267
errs: field.ErrorList{
240268
{
241269
Type: field.ErrorTypeInvalid,
242-
BadValue: "RequestMirror",
270+
BadValue: "RequestHeaderModifier",
243271
Field: "spec.rules[0].filters",
244272
Detail: "cannot be used multiple times in the same rule",
245273
},
@@ -305,8 +333,8 @@ func TestValidateGRPCBackendUniqueFilters(t *testing.T) {
305333
},
306334
}},
307335
}, {
308-
name: "invalid grpcRoute Rules duplicate mirror filter",
309-
errCount: 1,
336+
name: "valid grpcRoute Rules duplicate mirror filter",
337+
errCount: 0,
310338
rules: []gatewayv1a2.GRPCRouteRule{{
311339
BackendRefs: []gatewayv1a2.GRPCBackendRef{
312340
{

config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)