Skip to content

Commit

Permalink
Merge pull request #683 from hbagdi/feat/configurable-redirects
Browse files Browse the repository at this point in the history
httproute: introduce RequestRedirect filter
  • Loading branch information
k8s-ci-robot committed Jul 2, 2021
2 parents 1f09903 + 84f15d0 commit e4536a0
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 1 deletion.
47 changes: 46 additions & 1 deletion apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ type HTTPRouteFilter struct {
// +optional
RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"`

// RequestRedirect defines a schema for a filter that redirects request.
//
// Support: Core
//
// +optional
RequestRedirect *HTTPRequestRedirect `json:"requestRedirect,omitempty"`

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

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

const (
Expand All @@ -533,6 +540,15 @@ const (
// Support in HTTPRouteForwardTo: Extended
HTTPRouteFilterRequestHeaderModifier HTTPRouteFilterType = "RequestHeaderModifier"

// HTTPRouteFilterRequestRedirect can be used to redirect a request to
// another location. This filter can also be used for HTTP to HTTPS
// redirects.
//
// Support in HTTPRouteRule: Core
//
// Support in HTTPRouteForwardTo: Extended
HTTPRouteFilterRequestRedirect HTTPRouteFilterType = "RequestRedirect"

// 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 @@ -641,6 +657,35 @@ type HTTPRequestHeaderFilter struct {
Remove []string `json:"remove,omitempty"`
}

// HTTPRequestRedirect defines configuration for the RequestRedirect filter.
type HTTPRequestRedirect struct {
// Protocol is the protocol to be used in the value of the `Location`
// header in the response.
// When empty, the protocol of the request is used.
//
// +optional
// +kubebuilder:validation:Enum=HTTP;HTTPS
Protocol *string `json:"protocol,omitempty"`
// Hostname is the hostname to be used in the value of the `Location`
// header in the response.
// When empty, the hostname of the request is used.
//
// +optional
Hostname *string `json:"hostname,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.
//
// +optional
Port *int `json:"port,omitempty"`
// StatusCode is the HTTP status code to be used in response.
//
// +optional
// +kubebuilder:default=302
// +kubebuilder:validation=301;302
StatusCode *int `json:"redirect_status_code,omitempty"`
}

// HTTPRequestMirrorFilter defines configuration for the RequestMirror filter.
type HTTPRequestMirrorFilter struct {
// ServiceName refers to the name of the Service to mirror matched requests
Expand Down
40 changes: 40 additions & 0 deletions apis/v1alpha2/zz_generated.deepcopy.go

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

61 changes: 61 additions & 0 deletions config/crd/bases/networking.x-k8s.io_httproutes.yaml

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

81 changes: 81 additions & 0 deletions examples/v1alpha2/http-redirect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
kind: GatewayClass
apiVersion: networking.x-k8s.io/v1alpha2
metadata:
name: filter-lb
spec:
controller: acme.io/gateway-controller
parametersRef:
name: acme-lb
group: acme.io
kind: Parameters
---
kind: Namespace
apiVersion: v1
metadata:
name: gateway-api-example-ns1
---
kind: Gateway
apiVersion: networking.x-k8s.io/v1alpha2
metadata:
name: my-filter-gateway
namespace: gateway-api-example-ns1
spec:
gatewayClassName: filter-lb
listeners:
- protocol: HTTP
port: 80
routes:
kind: HTTPRoute
selector:
matchLabels:
protocol: http
namespaces:
from: "Same"
- protocol: HTTPS
port: 443
routes:
kind: HTTPRoute
selector:
matchLabels:
app: filter
namespaces:
from: "All"
---
kind: HTTPRoute
apiVersion: networking.x-k8s.io/v1alpha2
metadata:
name: http-filter-1
namespace: gateway-api-example-ns1
labels:
protocol: http
spec:
hostnames:
- my-filter.example.com
rules:
- matches:
- path:
type: Prefix
value: /
filters:
- type: RequestRedirect
requestRedirect:
protocol: HTTPS
---
kind: HTTPRoute
apiVersion: networking.x-k8s.io/v1alpha2
metadata:
name: http-filter-1
labels:
app: filter
spec:
hostnames:
- my-filter.example.com
rules:
- matches:
- path:
type: Prefix
value: /
forwardTo:
- serviceName: my-filter-svc1
weight: 1
port: 80

0 comments on commit e4536a0

Please sign in to comment.