Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 26 additions & 32 deletions apis/v1alpha2/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

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

tests := []struct {
Expand Down Expand Up @@ -103,20 +102,20 @@ func TestValidateHTTPRoute(t *testing.T) {
},
Filters: []gatewayv1a2.HTTPRouteFilter{
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
BackendRef: gatewayv1a2.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
Path: &gatewayv1b1.HTTPPathModifier{
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
ReplacePrefixMatch: ptrTo("foo"),
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
BackendRef: gatewayv1a2.BackendObjectReference{
Name: specialService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
Path: &gatewayv1b1.HTTPPathModifier{
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
ReplacePrefixMatch: ptrTo("bar"),
},
},
},
Expand Down Expand Up @@ -186,11 +185,13 @@ func TestValidateHTTPRoute(t *testing.T) {
},
Filters: []gatewayv1a2.HTTPRouteFilter{
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
BackendRef: gatewayv1a2.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Add: []gatewayv1b1.HTTPHeader{
{
Name: "extra-header",
Value: "foo",
},
},
},
},
Expand All @@ -206,11 +207,13 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
BackendRef: gatewayv1a2.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Set: []gatewayv1b1.HTTPHeader{
{
Name: "other-header",
Value: "bat",
},
},
},
},
Expand All @@ -225,15 +228,6 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1a2.HTTPRequestMirrorFilter{
BackendRef: gatewayv1a2.BackendObjectReference{
Name: specialService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
},
},
},
},
},
},
Expand Down Expand Up @@ -471,8 +465,8 @@ func TestValidateHTTPBackendUniqueFilters(t *testing.T) {
},
}},
}, {
name: "invalid httpRoute Rules duplicate mirror filter",
errCount: 1,
name: "valid httpRoute Rules duplicate mirror filter",
errCount: 0,
rules: []gatewayv1a2.HTTPRouteRule{{
BackendRefs: []gatewayv1a2.HTTPBackendRef{
{
Expand Down
10 changes: 8 additions & 2 deletions apis/v1beta1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ type HTTPRouteRule struct {
// - Implementation-specific custom filters have no API guarantees across
// implementations.
//
// Specifying a core filter multiple times has unspecified or
// implementation-specific conformance.
// Specifying the same filter multiple times is not supported unless explicitly
// indicated in the filter.
//
// All filters are expected to be compatible with each other except for the
// URLRewrite and RequestRedirect filters, which may not be combined. If an
Expand Down Expand Up @@ -618,6 +618,10 @@ type HTTPRouteFilter struct {
// Requests are sent to the specified destination, but responses from
// that destination are ignored.
//
// This filter can be used multiple times within the same rule. Note that
// not all implementations will be able to support mirroring to multiple
// backends.
//
// Support: Extended
//
// +optional
Expand All @@ -643,6 +647,8 @@ type HTTPRouteFilter struct {
// "networking.example.net"). ExtensionRef MUST NOT be used for core and
// extended filters.
//
// This filter can be used multiple times within the same rule.
//
// Support: Implementation-specific
//
// +optional
Expand Down
10 changes: 6 additions & 4 deletions apis/v1beta1/validation/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
// repeated multiple times in a rule.
repeatableHTTPRouteFilters = []gatewayv1b1.HTTPRouteFilterType{
gatewayv1b1.HTTPRouteFilterExtensionRef,
gatewayv1b1.HTTPRouteFilterRequestMirror,
}

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

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

// repeatableHTTPRouteFilters filters can be used more than once
for _, key := range repeatableHTTPRouteFilters {
delete(counts, key)
}

for filterType, count := range counts {
if count > 1 {
errs = append(errs, field.Invalid(path.Child("filters"), filterType, "cannot be used multiple times in the same rule"))
Expand Down
54 changes: 13 additions & 41 deletions apis/v1beta1/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

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

tests := []struct {
Expand Down Expand Up @@ -102,20 +101,20 @@ func TestValidateHTTPRoute(t *testing.T) {
},
Filters: []gatewayv1b1.HTTPRouteFilter{
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1b1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
Path: &gatewayv1b1.HTTPPathModifier{
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
ReplacePrefixMatch: ptrTo("foo"),
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1b1.BackendObjectReference{
Name: specialService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
Type: gatewayv1b1.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayv1b1.HTTPURLRewriteFilter{
Path: &gatewayv1b1.HTTPPathModifier{
Type: gatewayv1b1.PrefixMatchHTTPPathModifier,
ReplacePrefixMatch: ptrTo("bar"),
},
},
},
Expand Down Expand Up @@ -172,7 +171,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
}, {
name: "invalid httpRoute with multiple duplicate filters",
errCount: 3,
errCount: 2,
rules: []gatewayv1b1.HTTPRouteRule{
{
Matches: []gatewayv1b1.HTTPRouteMatch{
Expand All @@ -184,15 +183,6 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
Filters: []gatewayv1b1.HTTPRouteFilter{
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1b1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Expand All @@ -204,15 +194,6 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1b1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Expand All @@ -235,15 +216,6 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1b1.BackendObjectReference{
Name: specialService,
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Expand Down Expand Up @@ -638,8 +610,8 @@ func TestValidateHTTPBackendUniqueFilters(t *testing.T) {
},
}},
}, {
name: "invalid httpRoute Rules duplicate mirror filter",
errCount: 1,
name: "valid httpRoute Rules duplicate mirror filter",
errCount: 0,
rules: []gatewayv1b1.HTTPRouteRule{{
BackendRefs: []gatewayv1b1.HTTPBackendRef{
{
Expand Down
44 changes: 30 additions & 14 deletions config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading