Skip to content

Commit 88d0a9b

Browse files
adding support for more than one mirror backends + adding clarificati… (#2199)
* adding support for more than one mirror backends + adding clarification on mulitple same type filters within the same rule * aligning tests with the change * add missing braces * attempt to fix test * after make generate * address feedback * after make generate
1 parent fe202d4 commit 88d0a9b

File tree

7 files changed

+116
-113
lines changed

7 files changed

+116
-113
lines changed

apis/v1alpha2/validation/httproute_test.go

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
func TestValidateHTTPRoute(t *testing.T) {
3131
testService := gatewayv1a2.ObjectName("test-service")
32-
specialService := gatewayv1a2.ObjectName("special-service")
3332
pathPrefixMatchType := gatewayv1b1.PathMatchPathPrefix
3433

3534
tests := []struct {
@@ -103,20 +102,20 @@ func TestValidateHTTPRoute(t *testing.T) {
103102
},
104103
Filters: []gatewayv1a2.HTTPRouteFilter{
105104
{
106-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
107-
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
108-
BackendRef: gatewayv1a2.BackendObjectReference{
109-
Name: testService,
110-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
105+
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
106+
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
107+
Path: &gatewayv1b1.HTTPPathModifier{
108+
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
109+
ReplacePrefixMatch: ptrTo("foo"),
111110
},
112111
},
113112
},
114113
{
115-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
116-
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
117-
BackendRef: gatewayv1a2.BackendObjectReference{
118-
Name: specialService,
119-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
114+
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
115+
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
116+
Path: &gatewayv1b1.HTTPPathModifier{
117+
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
118+
ReplacePrefixMatch: ptrTo("bar"),
120119
},
121120
},
122121
},
@@ -186,11 +185,13 @@ func TestValidateHTTPRoute(t *testing.T) {
186185
},
187186
Filters: []gatewayv1a2.HTTPRouteFilter{
188187
{
189-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
190-
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
191-
BackendRef: gatewayv1a2.BackendObjectReference{
192-
Name: testService,
193-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
188+
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
189+
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
190+
Add: []gatewayv1b1.HTTPHeader{
191+
{
192+
Name: "extra-header",
193+
Value: "foo",
194+
},
194195
},
195196
},
196197
},
@@ -206,11 +207,13 @@ func TestValidateHTTPRoute(t *testing.T) {
206207
},
207208
},
208209
{
209-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
210-
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
211-
BackendRef: gatewayv1a2.BackendObjectReference{
212-
Name: testService,
213-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
210+
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
211+
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
212+
Set: []gatewayv1b1.HTTPHeader{
213+
{
214+
Name: "other-header",
215+
Value: "bat",
216+
},
214217
},
215218
},
216219
},
@@ -225,15 +228,6 @@ func TestValidateHTTPRoute(t *testing.T) {
225228
},
226229
},
227230
},
228-
{
229-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
230-
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
231-
BackendRef: gatewayv1a2.BackendObjectReference{
232-
Name: specialService,
233-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
234-
},
235-
},
236-
},
237231
},
238232
},
239233
},
@@ -471,8 +465,8 @@ func TestValidateHTTPBackendUniqueFilters(t *testing.T) {
471465
},
472466
}},
473467
}, {
474-
name: "invalid httpRoute Rules duplicate mirror filter",
475-
errCount: 1,
468+
name: "valid httpRoute Rules duplicate mirror filter",
469+
errCount: 0,
476470
rules: []gatewayv1a2.HTTPRouteRule{{
477471
BackendRefs: []gatewayv1a2.HTTPBackendRef{
478472
{

apis/v1beta1/httproute_types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ type HTTPRouteRule struct {
201201
// - Implementation-specific custom filters have no API guarantees across
202202
// implementations.
203203
//
204-
// Specifying a core filter multiple times has unspecified or
205-
// implementation-specific conformance.
204+
// Specifying the same filter multiple times is not supported unless explicitly
205+
// indicated in the filter.
206206
//
207207
// All filters are expected to be compatible with each other except for the
208208
// URLRewrite and RequestRedirect filters, which may not be combined. If an
@@ -618,6 +618,10 @@ type HTTPRouteFilter struct {
618618
// Requests are sent to the specified destination, but responses from
619619
// that destination are ignored.
620620
//
621+
// This filter can be used multiple times within the same rule. Note that
622+
// not all implementations will be able to support mirroring to multiple
623+
// backends.
624+
//
621625
// Support: Extended
622626
//
623627
// +optional
@@ -643,6 +647,8 @@ type HTTPRouteFilter struct {
643647
// "networking.example.net"). ExtensionRef MUST NOT be used for core and
644648
// extended filters.
645649
//
650+
// This filter can be used multiple times within the same rule.
651+
//
646652
// Support: Implementation-specific
647653
//
648654
// +optional

apis/v1beta1/validation/httproute.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
// repeated multiple times in a rule.
3333
repeatableHTTPRouteFilters = []gatewayv1b1.HTTPRouteFilterType{
3434
gatewayv1b1.HTTPRouteFilterExtensionRef,
35+
gatewayv1b1.HTTPRouteFilterRequestMirror,
3536
}
3637

3738
// Invalid path sequences and suffixes, primarily related to directory traversal
@@ -137,15 +138,16 @@ func validateHTTPRouteFilters(filters []gatewayv1b1.HTTPRouteFilter, matches []g
137138
}
138139
errs = append(errs, validateHTTPRouteFilterTypeMatchesValue(filter, path.Index(i))...)
139140
}
140-
// custom filters don't have any validation
141-
for _, key := range repeatableHTTPRouteFilters {
142-
delete(counts, key)
143-
}
144141

145142
if counts[gatewayv1b1.HTTPRouteFilterRequestRedirect] > 0 && counts[gatewayv1b1.HTTPRouteFilterURLRewrite] > 0 {
146143
errs = append(errs, field.Invalid(path.Child("filters"), gatewayv1b1.HTTPRouteFilterRequestRedirect, "may specify either httpRouteFilterRequestRedirect or httpRouteFilterRequestRewrite, but not both"))
147144
}
148145

146+
// repeatableHTTPRouteFilters filters can be used more than once
147+
for _, key := range repeatableHTTPRouteFilters {
148+
delete(counts, key)
149+
}
150+
149151
for filterType, count := range counts {
150152
if count > 1 {
151153
errs = append(errs, field.Invalid(path.Child("filters"), filterType, "cannot be used multiple times in the same rule"))

apis/v1beta1/validation/httproute_test.go

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828

2929
func TestValidateHTTPRoute(t *testing.T) {
3030
testService := gatewayv1b1.ObjectName("test-service")
31-
specialService := gatewayv1b1.ObjectName("special-service")
3231
pathPrefixMatchType := gatewayv1b1.PathMatchPathPrefix
3332

3433
tests := []struct {
@@ -102,20 +101,20 @@ func TestValidateHTTPRoute(t *testing.T) {
102101
},
103102
Filters: []gatewayv1b1.HTTPRouteFilter{
104103
{
105-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
106-
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
107-
BackendRef: gatewayv1b1.BackendObjectReference{
108-
Name: testService,
109-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
104+
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
105+
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
106+
Path: &gatewayv1b1.HTTPPathModifier{
107+
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
108+
ReplacePrefixMatch: ptrTo("foo"),
110109
},
111110
},
112111
},
113112
{
114-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
115-
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
116-
BackendRef: gatewayv1b1.BackendObjectReference{
117-
Name: specialService,
118-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
113+
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
114+
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
115+
Path: &gatewayv1b1.HTTPPathModifier{
116+
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
117+
ReplacePrefixMatch: ptrTo("bar"),
119118
},
120119
},
121120
},
@@ -172,7 +171,7 @@ func TestValidateHTTPRoute(t *testing.T) {
172171
},
173172
}, {
174173
name: "invalid httpRoute with multiple duplicate filters",
175-
errCount: 3,
174+
errCount: 2,
176175
rules: []gatewayv1b1.HTTPRouteRule{
177176
{
178177
Matches: []gatewayv1b1.HTTPRouteMatch{
@@ -184,15 +183,6 @@ func TestValidateHTTPRoute(t *testing.T) {
184183
},
185184
},
186185
Filters: []gatewayv1b1.HTTPRouteFilter{
187-
{
188-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
189-
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
190-
BackendRef: gatewayv1b1.BackendObjectReference{
191-
Name: testService,
192-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
193-
},
194-
},
195-
},
196186
{
197187
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
198188
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
@@ -204,15 +194,6 @@ func TestValidateHTTPRoute(t *testing.T) {
204194
},
205195
},
206196
},
207-
{
208-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
209-
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
210-
BackendRef: gatewayv1b1.BackendObjectReference{
211-
Name: testService,
212-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
213-
},
214-
},
215-
},
216197
{
217198
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
218199
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
@@ -235,15 +216,6 @@ func TestValidateHTTPRoute(t *testing.T) {
235216
},
236217
},
237218
},
238-
{
239-
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
240-
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
241-
BackendRef: gatewayv1b1.BackendObjectReference{
242-
Name: specialService,
243-
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
244-
},
245-
},
246-
},
247219
{
248220
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
249221
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
@@ -638,8 +610,8 @@ func TestValidateHTTPBackendUniqueFilters(t *testing.T) {
638610
},
639611
}},
640612
}, {
641-
name: "invalid httpRoute Rules duplicate mirror filter",
642-
errCount: 1,
613+
name: "valid httpRoute Rules duplicate mirror filter",
614+
errCount: 0,
643615
rules: []gatewayv1b1.HTTPRouteRule{{
644616
BackendRefs: []gatewayv1b1.HTTPBackendRef{
645617
{

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

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

0 commit comments

Comments
 (0)