Skip to content

Commit

Permalink
Merge pull request #945 from robscott/gep-726-implementation
Browse files Browse the repository at this point in the history
Implementing GEPs 726 and 922: Rewrites + Experimental CRDs
  • Loading branch information
k8s-ci-robot authored Dec 2, 2021
2 parents fdeadc9 + 0d40986 commit 06754c5
Show file tree
Hide file tree
Showing 21 changed files with 4,249 additions and 96 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
apis/generated/** linguist-generated=true
apis/**/generated.pb.go linguist-generated=true
apis/**/generated.proto linguist-generated=true
config/crd/v1alpha2/** linguist-generated=true
config/crd/experimental/** linguist-generated=true
config/crd/stable/** linguist-generated=true
pkg/client/** linguist-generated=true

99 changes: 96 additions & 3 deletions apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ type HTTPRouteFilter struct {
// that filter MUST receive a HTTP error response.
//
// +unionDiscriminator
// +kubebuilder:validation:Enum=RequestHeaderModifier;RequestMirror;RequestRedirect;ExtensionRef
// <gateway:experimental:validation:Enum=RequestHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef>
Type HTTPRouteFilterType `json:"type"`

// RequestHeaderModifier defines a schema for a filter that modifies request
Expand Down Expand Up @@ -521,6 +523,15 @@ type HTTPRouteFilter struct {
// +optional
RequestRedirect *HTTPRequestRedirectFilter `json:"requestRedirect,omitempty"`

// URLRewrite defines a schema for a filter that responds to the
// request with an HTTP redirection.
//
// Support: Extended
//
// <gateway:experimental>
// +optional
URLRewrite *HTTPURLRewriteFilter `json:"urlRewrite,omitempty"`

// ExtensionRef is an optional, implementation-specific extension to the
// "filter" behavior. For example, resource "myroutefilter" in group
// "networking.example.net"). ExtensionRef MUST NOT be used for core and
Expand All @@ -533,7 +544,6 @@ type HTTPRouteFilter struct {
}

// HTTPRouteFilterType identifies a type of HTTPRoute filter.
// +kubebuilder:validation:Enum=RequestHeaderModifier;RequestMirror;RequestRedirect;ExtensionRef
type HTTPRouteFilterType string

const (
Expand All @@ -547,13 +557,26 @@ const (

// HTTPRouteFilterRequestRedirect can be used to redirect a request to
// another location. This filter can also be used for HTTP to HTTPS
// redirects.
// redirects. This may not be used on the same Route rule or BackendRef as a
// URLRewrite filter.
//
// Support in HTTPRouteRule: Core
//
// Support in HTTPBackendRef: Extended
HTTPRouteFilterRequestRedirect HTTPRouteFilterType = "RequestRedirect"

// HTTPRouteFilterURLRewrite can be used to modify a request during
// forwarding. At most one of these filters may be used on a Route rule.
// This may not be used on the same Route rule or BackendRef as a
// RequestRedirect filter.
//
// Support in HTTPRouteRule: Extended
//
// Support in HTTPBackendRef: Extended
//
// <gateway:experimental>
HTTPRouteFilterURLRewrite HTTPRouteFilterType = "URLRewrite"

// HTTPRouteFilterRequestMirror can be used to mirror HTTP requests to a
// different backend. The responses from this backend MUST be ignored by
// the Gateway.
Expand Down Expand Up @@ -663,7 +686,42 @@ type HTTPRequestHeaderFilter struct {
Remove []string `json:"remove,omitempty"`
}

// HTTPRequestRedirectFilter defines configuration for the RequestRedirect filter.
// HTTPPathModifierType defines the type of path redirect.
type HTTPPathModifierType string

const (
// This type of modifier indicates that the complete path will be replaced
// by the path redirect value.
AbsoluteHTTPPathModifier HTTPPathModifierType = "Absolute"

// This type of modifier indicates that any prefix path matches will be
// replaced by the substitution value. For example, a path with a prefix
// match of "/foo" and a ReplacePrefixMatch substitution of "/bar" will have
// the "/foo" prefix replaced with "/bar" in matching requests.
PrefixMatchHTTPPathModifier HTTPPathModifierType = "ReplacePrefixMatch"
)

// HTTPPathModifier defines configuration for path modifiers.
// <gateway:experimental>
type HTTPPathModifier struct {
// Type defines the type of path modifier.
//
// <gateway:experimental>
// +kubebuilder:validation:Enum=Absolute;ReplacePrefixMatch
Type HTTPPathModifierType `json:"type"`

// Substitution defines the HTTP path value to substitute. An empty value
// ("") indicates that the portion of the path to be changed should be
// removed from the resulting path. For example, a request to "/foo/bar"
// with a prefix match of "/foo" would be modified to "/bar".
//
// <gateway:experimental>
// +kubebuilder:validation:MaxLength=1024
Substitution string `json:"substitution"`
}

// HTTPRequestRedirect defines a filter that redirects a request. This filter
// MUST not be used on the same Route rule as a HTTPURLRewrite filter.
type HTTPRequestRedirectFilter struct {
// Scheme is the scheme to be used in the value of the `Location`
// header in the response.
Expand All @@ -684,6 +742,16 @@ type HTTPRequestRedirectFilter struct {
// +optional
Hostname *Hostname `json:"hostname,omitempty"`

// Path defines parameters used to modify the path of the incoming request.
// The modified path is then used to construct the `Location` header. When
// empty, the request path is used as-is.
//
// Support: Extended
//
// <gateway:experimental>
// +optional
Path *HTTPPathModifier `json:"path,omitempty"`

// Port is the port to be used in the value of the `Location`
// header in the response.
// When empty, port (if specified) of the request is used.
Expand All @@ -703,6 +771,31 @@ type HTTPRequestRedirectFilter struct {
StatusCode *int `json:"statusCode,omitempty"`
}

// HTTPURLRewriteFilter defines a filter that modifies a request during
// forwarding. At most one of these filters may be used on a Route rule. This
// may not be used on the same Route rule as a HTTPRequestRedirect filter.
//
// <gateway:experimental>
// Support: Extended
type HTTPURLRewriteFilter struct {
// Hostname is the value to be used to replace the Host header value during
// forwarding.
//
// Support: Extended
//
// <gateway:experimental>
// +optional
Hostname *Hostname `json:"hostname,omitempty"`

// Path defines a path rewrite.
//
// Support: Extended
//
// <gateway:experimental>
// +optional
Path *HTTPPathModifier `json:"path,omitempty"`
}

// HTTPRequestMirrorFilter defines configuration for the RequestMirror filter.
type HTTPRequestMirrorFilter struct {
// BackendRef references a resource where mirrored requests are sent.
Expand Down
226 changes: 226 additions & 0 deletions config/crd/experimental/gateway.networking.k8s.io_gatewayclasses.yaml

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

Loading

0 comments on commit 06754c5

Please sign in to comment.