-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Direct Response #3977
feat: Direct Response #3977
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package v1alpha1 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
const ( | ||
// KindVirtualBackend is the name of the VirtualBackend kind. | ||
KindVirtualBackend = "VirtualBackend" | ||
) | ||
|
||
// +kubebuilder:validation:Minimum=100 | ||
// +kubebuilder:validation:Maximum=599 | ||
type StatusCode uint32 | ||
|
||
// +kubebuilder:validation:Pattern=`^([\w-]+)$` | ||
type ResponseHeader string | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:categories=envoy-gateway,shortName=vb | ||
// | ||
// VirtualBackend defines the configuration for direct response. | ||
type VirtualBackend struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// Spec defines desired state of VirtualBackend. | ||
Spec VirtualBackendSpec `json:"spec"` | ||
} | ||
|
||
// +kubebuilder:validation:XValidation:rule="has(self.statusCode)" | ||
// | ||
// VirtualBackendSpec defines direct response configuration. | ||
type VirtualBackendSpec struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some CEL validations here, and also document what the defaults are if nothing is provided. For consistency with other EG APIs, if the value is optional:
This is especially important for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liorokman done. |
||
// +optional | ||
// | ||
// Body contains data which gateway returns in direct response. | ||
Body *[]byte `json:"body,omitempty" yaml:"body,omitempty"` | ||
|
||
// +kubebuilder:default=200 | ||
// | ||
// StatusCode defines HTTP response status code of direct response. Default value is 200. | ||
StatusCode StatusCode `json:"statusCode" yaml:"statusCode"` | ||
|
||
// +optional | ||
// | ||
// ResponseHeaders defines Header:Value map of additional headers to response. | ||
ResponseHeaders map[ResponseHeader]string `json:"responseHeaders,omitempty" yaml:"responseHeaders,omitempty"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.15.0 | ||
name: virtualbackends.gateway.envoyproxy.io | ||
spec: | ||
group: gateway.envoyproxy.io | ||
names: | ||
categories: | ||
- envoy-gateway | ||
kind: VirtualBackend | ||
listKind: VirtualBackendList | ||
plural: virtualbackends | ||
shortNames: | ||
- vb | ||
singular: virtualbackend | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: VirtualBackend defines the configuration for direct response. | ||
properties: | ||
apiVersion: | ||
description: |- | ||
APIVersion defines the versioned schema of this representation of an object. | ||
Servers should convert recognized schemas to the latest internal value, and | ||
may reject unrecognized values. | ||
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources | ||
type: string | ||
kind: | ||
description: |- | ||
Kind is a string value representing the REST resource this object represents. | ||
Servers may infer this from the endpoint the client submits requests to. | ||
Cannot be updated. | ||
In CamelCase. | ||
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
description: Spec defines desired state of VirtualBackend. | ||
properties: | ||
body: | ||
description: Body contains data which gateway returns in direct response. | ||
format: byte | ||
type: string | ||
responseHeaders: | ||
additionalProperties: | ||
type: string | ||
description: ResponseHeaders defines Header:Value map of additional | ||
headers to response. | ||
type: object | ||
statusCode: | ||
default: 200 | ||
description: StatusCode defines HTTP response status code of direct | ||
response. Default value is 200. | ||
format: int32 | ||
maximum: 599 | ||
minimum: 100 | ||
type: integer | ||
required: | ||
- statusCode | ||
type: object | ||
x-kubernetes-validations: | ||
- rule: has(self.statusCode) | ||
required: | ||
- spec | ||
type: object | ||
served: true | ||
storage: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
gateways: | ||
- apiVersion: gateway.networking.k8s.io/v1 | ||
kind: Gateway | ||
metadata: | ||
namespace: envoy-gateway | ||
name: gateway-1 | ||
spec: | ||
gatewayClassName: envoy-gateway-class | ||
listeners: | ||
- name: http | ||
protocol: HTTP | ||
port: 80 | ||
hostname: "*.envoyproxy.io" | ||
allowedRoutes: | ||
namespaces: | ||
from: All | ||
httpRoutes: | ||
- apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
namespace: default | ||
name: httproute-1 | ||
spec: | ||
hostnames: | ||
- gateway.envoyproxy.io | ||
parentRefs: | ||
- namespace: envoy-gateway | ||
name: gateway-1 | ||
sectionName: http | ||
rules: | ||
- matches: | ||
- path: | ||
value: "/" | ||
backendRefs: | ||
- kind: VirtualBackend | ||
name: virtual-backend-1 | ||
virtualBackends: | ||
- apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
kind: VirtualBackend | ||
metadata: | ||
namespace: default | ||
name: virtual-backend-1 | ||
spec: | ||
body: eyJlcnIiOiAiU29tZSBlcnJvciJ9 | ||
statusCode: 501 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guydc do you think it's a good idea to support this in
Backend
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the very late response. IMHO, the best direction here is to support this through a custom filter, as outlined here: #4120