Skip to content

Commit

Permalink
api: support customized UpgradeConfigs (#5300)
Browse files Browse the repository at this point in the history
* api: support customized UpgradeConfigs

Signed-off-by: zirain <[email protected]>

* update

Signed-off-by: zirain <[email protected]>

* hide

Signed-off-by: zirain <[email protected]>

* update

Signed-off-by: zirain <[email protected]>

* rename to Type

Signed-off-by: zirain <[email protected]>

---------

Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain authored Feb 28, 2025
1 parent 6d2b4b0 commit 12c4390
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
30 changes: 23 additions & 7 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const (
KindBackendTrafficPolicy = "BackendTrafficPolicy"
)

// BackendTrafficPolicy allows the user to configure the behavior of the connection
// between the Envoy Proxy listener and the backend service.
//
// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=envoy-gateway,shortName=btp
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// BackendTrafficPolicy allows the user to configure the behavior of the connection
// between the Envoy Proxy listener and the backend service.
type BackendTrafficPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -33,16 +33,15 @@ type BackendTrafficPolicy struct {
Status gwapiv1a2.PolicyStatus `json:"status,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="(has(self.targetRef) && !has(self.targetRefs)) || (!has(self.targetRef) && has(self.targetRefs)) || (has(self.targetSelectors) && self.targetSelectors.size() > 0) ", message="either targetRef or targetRefs must be used"
// BackendTrafficPolicySpec defines the desired state of BackendTrafficPolicy.
//
// +kubebuilder:validation:XValidation:rule="(has(self.targetRef) && !has(self.targetRefs)) || (!has(self.targetRef) && has(self.targetRefs)) || (has(self.targetSelectors) && self.targetSelectors.size() > 0) ", message="either targetRef or targetRefs must be used"
// +kubebuilder:validation:XValidation:rule="has(self.targetRef) ? self.targetRef.group == 'gateway.networking.k8s.io' : true ", message="this policy can only have a targetRef.group of gateway.networking.k8s.io"
// +kubebuilder:validation:XValidation:rule="has(self.targetRef) ? self.targetRef.kind in ['Gateway', 'HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute'] : true", message="this policy can only have a targetRef.kind of Gateway/HTTPRoute/GRPCRoute/TCPRoute/UDPRoute/TLSRoute"
// +kubebuilder:validation:XValidation:rule="has(self.targetRef) ? !has(self.targetRef.sectionName) : true",message="this policy does not yet support the sectionName field"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.group == 'gateway.networking.k8s.io') : true ", message="this policy can only have a targetRefs[*].group of gateway.networking.k8s.io"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.kind in ['Gateway', 'HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute']) : true ", message="this policy can only have a targetRefs[*].kind of Gateway/HTTPRoute/GRPCRoute/TCPRoute/UDPRoute/TLSRoute"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, !has(ref.sectionName)) : true",message="this policy does not yet support the sectionName field"
//
// BackendTrafficPolicySpec defines the desired state of BackendTrafficPolicy.
type BackendTrafficPolicySpec struct {
PolicyTargetReferences `json:",inline"`
ClusterSettings `json:",inline"`
Expand Down Expand Up @@ -74,11 +73,28 @@ type BackendTrafficPolicySpec struct {
//
// +optional
ResponseOverride []*ResponseOverride `json:"responseOverride,omitempty"`
// HTTPUpgrade defines the configuration for HTTP protocol upgrades.
// If not specified, the default upgrade configuration(websocket) will be used.
//
// +optional
// +notImplementedHide
HTTPUpgrade []*ProtocolUpgradeConfig `json:"httpUpgrade,omitempty"`
}

// +kubebuilder:object:root=true
type ProtocolUpgradeConfig struct {
// Type is the case-insensitive type of protocol upgrade.
// e.g. `websocket`, `CONNECT`, `spdy/3.1` etc.
//
// +kubebuilder:validation:Required
Type string `json:"type"`
// Disabled indicates whether the upgrade is disabled.
// +optional
Disabled *bool `json:"disabled"`
}

// BackendTrafficPolicyList contains a list of BackendTrafficPolicy resources.
//
// +kubebuilder:object:root=true
type BackendTrafficPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
31 changes: 31 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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
Expand Up @@ -532,6 +532,24 @@ spec:
Default: TerminateConnection
type: string
type: object
httpUpgrade:
description: |-
HTTPUpgrade defines the configuration for HTTP protocol upgrades.
If not specified, the default upgrade configuration(websocket) will be used.
items:
properties:
disabled:
description: Disabled indicates whether the upgrade is disabled.
type: boolean
type:
description: |-
Type is the case-insensitive type of protocol upgrade.
e.g. `websocket`, `CONNECT`, `spdy/3.1` etc.
type: string
required:
- type
type: object
type: array
loadBalancer:
description: |-
LoadBalancer policy to apply when routing traffic from the gateway to
Expand Down
15 changes: 15 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,21 @@ _Appears in:_
| `attributes` | _string array_ | false | | Defines which attributes are sent to the external processor. Envoy Gateway currently<br />supports only the following attribute prefixes: connection, source, destination,<br />request, response, upstream and xds.route.<br />https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes |


#### ProtocolUpgradeConfig





_Appears in:_
- [BackendTrafficPolicySpec](#backendtrafficpolicyspec)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | _string_ | true | | Type is the case-insensitive type of protocol upgrade.<br />e.g. `websocket`, `CONNECT`, `spdy/3.1` etc. |
| `disabled` | _boolean_ | false | | Disabled indicates whether the upgrade is disabled. |


#### ProviderType

_Underlying type:_ _string_
Expand Down

0 comments on commit 12c4390

Please sign in to comment.