Skip to content

Commit 3944377

Browse files
committed
feat: support endpoint override policy based routing
Signed-off-by: bitliu <[email protected]>
1 parent e8fefff commit 3944377

File tree

35 files changed

+6244
-139
lines changed

35 files changed

+6244
-139
lines changed

api/v1alpha1/loadbalancer_types.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
//
1313
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' ? has(self.consistentHash) : !has(self.consistentHash)",message="If LoadBalancer type is consistentHash, consistentHash field needs to be set."
1414
// +kubebuilder:validation:XValidation:rule="self.type in ['Random', 'ConsistentHash'] ? !has(self.slowStart) : true ",message="Currently SlowStart is only supported for RoundRobin and LeastRequest load balancers."
15-
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' ? !has(self.zoneAware) : true ",message="Currently ZoneAware is only supported for LeastRequest, Random, and RoundRobin load balancers."
15+
// +kubebuilder:validation:XValidation:rule="self.type in ['ConsistentHash'] ? !has(self.zoneAware) : true ",message="Currently ZoneAware is only supported for LeastRequest, Random, and RoundRobin load balancers."
1616
type LoadBalancer struct {
1717
// Type decides the type of Load Balancer policy.
1818
// Valid LoadBalancerType values are
@@ -29,6 +29,14 @@ type LoadBalancer struct {
2929
// +optional
3030
ConsistentHash *ConsistentHash `json:"consistentHash,omitempty"`
3131

32+
// EndpointOverride defines the configuration for endpoint override.
33+
// When specified, the load balancer will attempt to route requests to endpoints
34+
// based on the override information extracted from request headers or metadata.
35+
// If no valid override endpoint is found, the configured load balancer policy will be used as fallback.
36+
//
37+
// +optional
38+
EndpointOverride *EndpointOverride `json:"endpointOverride,omitempty"`
39+
3240
// SlowStart defines the configuration related to the slow start load balancer policy.
3341
// If set, during slow start window, traffic sent to the newly added hosts will gradually increase.
3442
// Currently this is only supported for RoundRobin and LeastRequest load balancers
@@ -178,3 +186,57 @@ type ForceLocalZone struct {
178186
// +notImplementedHide
179187
MinEndpointsInZoneThreshold *uint32 `json:"minEndpointsInZoneThreshold,omitempty"`
180188
}
189+
190+
// EndpointOverride defines the configuration for endpoint override.
191+
// This allows endpoint picking to be implemented based on request headers or metadata.
192+
// It extracts selected override endpoints from the specified sources (request headers, metadata, etc.).
193+
// If no valid endpoint in the override list, then the configured load balancing policy is used as fallback.
194+
type EndpointOverride struct {
195+
// ExtractFrom defines the sources to extract endpoint override information from.
196+
//
197+
// +kubebuilder:validation:MinItems=1
198+
// +kubebuilder:validation:MaxItems=10
199+
ExtractFrom []EndpointOverrideExtractFrom `json:"extractFrom"`
200+
}
201+
202+
// EndpointOverrideExtractFrom defines a source to extract endpoint override information from.
203+
// +union
204+
//
205+
// +kubebuilder:validation:XValidation:rule="(has(self.header) && !has(self.metadata)) || (!has(self.header) && has(self.metadata))",message="Exactly one of header or metadata must be set."
206+
type EndpointOverrideExtractFrom struct {
207+
// Header defines the header to get the override endpoint addresses.
208+
// The header value must specify at least one endpoint in `IP:Port` format or multiple endpoints in `IP:Port,IP:Port,...` format.
209+
// For example `10.0.0.5:8080` or `[2600:4040:5204::1574:24ae]:80`.
210+
// The IPv6 address is enclosed in square brackets.
211+
//
212+
// +optional
213+
Header *string `json:"header,omitempty"`
214+
215+
// Metadata defines the metadata key to get the override endpoint addresses from the request dynamic metadata.
216+
// If set this field then it will take precedence over the header field.
217+
//
218+
// +optional
219+
Metadata *EndpointOverrideMetadataKey `json:"metadata,omitempty"`
220+
}
221+
222+
// EndpointOverrideMetadataKey defines the metadata key configuration for endpoint override.
223+
type EndpointOverrideMetadataKey struct {
224+
// Key defines the metadata key.
225+
//
226+
// +kubebuilder:validation:MinLength=1
227+
Key string `json:"key"`
228+
229+
// Path defines the path within the metadata to extract the endpoint addresses.
230+
// Each path element represents a key in nested metadata structure.
231+
//
232+
// +optional
233+
Path []EndpointOverrideMetadataKeyPath `json:"path,omitempty"`
234+
}
235+
236+
// EndpointOverrideMetadataKeyPath defines a path element in the metadata structure.
237+
type EndpointOverrideMetadataKeyPath struct {
238+
// Key defines the key name in the metadata structure.
239+
//
240+
// +kubebuilder:validation:MinLength=1
241+
Key string `json:"key"`
242+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,67 @@ spec:
661661
- message: If consistent hash type is cookie, the cookie field
662662
must be set.
663663
rule: 'self.type == ''Cookie'' ? has(self.cookie) : !has(self.cookie)'
664+
endpointOverride:
665+
description: |-
666+
EndpointOverride defines the configuration for endpoint override.
667+
When specified, the load balancer will attempt to route requests to endpoints
668+
based on the override information extracted from request headers or metadata.
669+
If no valid override endpoint is found, the configured load balancer policy will be used as fallback.
670+
properties:
671+
extractFrom:
672+
description: ExtractFrom defines the sources to extract endpoint
673+
override information from.
674+
items:
675+
description: EndpointOverrideExtractFrom defines a source
676+
to extract endpoint override information from.
677+
properties:
678+
header:
679+
description: |-
680+
Header defines the header to get the override endpoint addresses.
681+
The header value must specify at least one endpoint in `IP:Port` format or multiple endpoints in `IP:Port,IP:Port,...` format.
682+
For example `10.0.0.5:8080` or `[2600:4040:5204::1574:24ae]:80`.
683+
The IPv6 address is enclosed in square brackets.
684+
type: string
685+
metadata:
686+
description: |-
687+
Metadata defines the metadata key to get the override endpoint addresses from the request dynamic metadata.
688+
If set this field then it will take precedence over the header field.
689+
properties:
690+
key:
691+
description: Key defines the metadata key.
692+
minLength: 1
693+
type: string
694+
path:
695+
description: |-
696+
Path defines the path within the metadata to extract the endpoint addresses.
697+
Each path element represents a key in nested metadata structure.
698+
items:
699+
description: EndpointOverrideMetadataKeyPath defines
700+
a path element in the metadata structure.
701+
properties:
702+
key:
703+
description: Key defines the key name in the
704+
metadata structure.
705+
minLength: 1
706+
type: string
707+
required:
708+
- key
709+
type: object
710+
type: array
711+
required:
712+
- key
713+
type: object
714+
type: object
715+
x-kubernetes-validations:
716+
- message: Exactly one of header or metadata must be set.
717+
rule: (has(self.header) && !has(self.metadata)) || (!has(self.header)
718+
&& has(self.metadata))
719+
maxItems: 10
720+
minItems: 1
721+
type: array
722+
required:
723+
- extractFrom
724+
type: object
664725
slowStart:
665726
description: |-
666727
SlowStart defines the configuration related to the slow start load balancer policy.
@@ -733,8 +794,8 @@ spec:
733794
: true '
734795
- message: Currently ZoneAware is only supported for LeastRequest,
735796
Random, and RoundRobin load balancers.
736-
rule: 'self.type == ''ConsistentHash'' ? !has(self.zoneAware) :
737-
true '
797+
rule: 'self.type in [''ConsistentHash''] ? !has(self.zoneAware)
798+
: true '
738799
mergeType:
739800
description: |-
740801
MergeType determines how this configuration is merged with existing BackendTrafficPolicy

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyextensionpolicies.yaml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,71 @@ spec:
739739
field must be set.
740740
rule: 'self.type == ''Cookie'' ? has(self.cookie)
741741
: !has(self.cookie)'
742+
endpointOverride:
743+
description: |-
744+
EndpointOverride defines the configuration for endpoint override.
745+
When specified, the load balancer will attempt to route requests to endpoints
746+
based on the override information extracted from request headers or metadata.
747+
If no valid override endpoint is found, the configured load balancer policy will be used as fallback.
748+
properties:
749+
extractFrom:
750+
description: ExtractFrom defines the sources to
751+
extract endpoint override information from.
752+
items:
753+
description: EndpointOverrideExtractFrom defines
754+
a source to extract endpoint override information
755+
from.
756+
properties:
757+
header:
758+
description: |-
759+
Header defines the header to get the override endpoint addresses.
760+
The header value must specify at least one endpoint in `IP:Port` format or multiple endpoints in `IP:Port,IP:Port,...` format.
761+
For example `10.0.0.5:8080` or `[2600:4040:5204::1574:24ae]:80`.
762+
The IPv6 address is enclosed in square brackets.
763+
type: string
764+
metadata:
765+
description: |-
766+
Metadata defines the metadata key to get the override endpoint addresses from the request dynamic metadata.
767+
If set this field then it will take precedence over the header field.
768+
properties:
769+
key:
770+
description: Key defines the metadata
771+
key.
772+
minLength: 1
773+
type: string
774+
path:
775+
description: |-
776+
Path defines the path within the metadata to extract the endpoint addresses.
777+
Each path element represents a key in nested metadata structure.
778+
items:
779+
description: EndpointOverrideMetadataKeyPath
780+
defines a path element in the metadata
781+
structure.
782+
properties:
783+
key:
784+
description: Key defines the key
785+
name in the metadata structure.
786+
minLength: 1
787+
type: string
788+
required:
789+
- key
790+
type: object
791+
type: array
792+
required:
793+
- key
794+
type: object
795+
type: object
796+
x-kubernetes-validations:
797+
- message: Exactly one of header or metadata must
798+
be set.
799+
rule: (has(self.header) && !has(self.metadata))
800+
|| (!has(self.header) && has(self.metadata))
801+
maxItems: 10
802+
minItems: 1
803+
type: array
804+
required:
805+
- extractFrom
806+
type: object
742807
slowStart:
743808
description: |-
744809
SlowStart defines the configuration related to the slow start load balancer policy.
@@ -812,7 +877,7 @@ spec:
812877
!has(self.slowStart) : true '
813878
- message: Currently ZoneAware is only supported for LeastRequest,
814879
Random, and RoundRobin load balancers.
815-
rule: 'self.type == ''ConsistentHash'' ? !has(self.zoneAware)
880+
rule: 'self.type in [''ConsistentHash''] ? !has(self.zoneAware)
816881
: true '
817882
proxyProtocol:
818883
description: ProxyProtocol enables the Proxy Protocol when

0 commit comments

Comments
 (0)