Skip to content

Commit

Permalink
LoadBalancer in BackendTrafficPolicy
Browse files Browse the repository at this point in the history
Fixes: envoyproxy#1105

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg committed Oct 25, 2023
1 parent 7fa96a7 commit ceaf2f9
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ type BackendTrafficPolicySpec struct {

// RateLimit allows the user to limit the number of incoming requests
// to a predefined value based on attributes within the traffic flow.
// +optional
RateLimit *RateLimitFilterSpec `json:"rateLimit,omitempty"`

// LoadBalancer policy to apply when routing traffic from the gateway to
// the backend endpoints
// +optional
LoadBalancer *LoadBalancer `json:"loadBalancer,omitempty"`
}

// BackendTrafficPolicyStatus defines the state of BackendTrafficPolicy
Expand Down
55 changes: 55 additions & 0 deletions api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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

// LoadBalancer defines the load balancer policy to be applied.
// +union
type LoadBalancer struct {
// Type decides the type of Load Balancer policy.
// Valid RateLimitType values are
// "ConsistentHash",
// "LeastRequest",
// "Random",
// "RoundRobin",
//
// +unionDiscriminator
Type LoadBalancerType `json:"type"`
// ConsistentHash defines the configuration when the load balancer type is
// set to ConsistentHash
//
// +optional
ConsistentHash *ConsistentHash `json:"consistentHash,omitempty"`
}

// LoadBalancerType specifies the types of LoadBalancer.
// +kubebuilder:validation:Enum=ConsistentHash;LeastRequest;Random;RoundRobin
type LoadBalancerType string

const (
// ConsistentHashLoadBalancerType load balancer policy.
ConsistentHashLoadBalancerType LoadBalancerType = "ConsistentHash"
// LeastRequestLoadBalancerType load balancer policy.
LeastRequestLoadBalancerType LoadBalancerType = "LeastRequest"
// RandomLoadBalancerType load balancer policy.
RandomLoadBalancerType LoadBalancerType = "Random"
// RoundRobinLoadBalancerType load balancer policy.
RoundRobinLoadBalancerType LoadBalancerType = "RoundRobin"
)

// ConsistentHash defines the configuration related to the consistent hash
// load balancer policy
type ConsistentHash struct {
Type ConsistentHashType `json:"type"`
}

// ConsistentHashType defines the type of input to hash on.
// +kubebuilder:validation:Enum=SourceIP
type ConsistentHashType string

const (
// SourceIPConsistentHashType hashes based on the source IP address.
SourceIPConsistentHashType ConsistentHashType = "SourceIP"
)
40 changes: 40 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 @@ -44,6 +44,36 @@ spec:
spec:
description: spec defines the desired state of BackendTrafficPolicy.
properties:
loadBalancer:
description: LoadBalancer policy to apply when routing traffic from
the gateway to the backend endpoints
properties:
consistentHash:
description: ConsistentHash defines the configuration when the
load balancer type is set to ConsistentHash
properties:
type:
description: ConsistentHashType defines the type of input
to hash on.
enum:
- SourceIP
type: string
required:
- type
type: object
type:
description: Type decides the type of Load Balancer policy. Valid
RateLimitType values are "ConsistentHash", "LeastRequest", "Random",
"RoundRobin",
enum:
- ConsistentHash
- LeastRequest
- Random
- RoundRobin
type: string
required:
- type
type: object
rateLimit:
description: RateLimit allows the user to limit the number of incoming
requests to a predefined value based on attributes within the traffic
Expand Down
52 changes: 52 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ _Appears in:_
| --- | --- |
| `targetRef` _[PolicyTargetReferenceWithSectionName](#policytargetreferencewithsectionname)_ | targetRef is the name of the resource this policy is being attached to. This Policy and the TargetRef MUST be in the same namespace for this Policy to have effect and be applied to the Gateway. |
| `rateLimit` _[RateLimitFilterSpec](#ratelimitfilterspec)_ | RateLimit allows the user to limit the number of incoming requests to a predefined value based on attributes within the traffic flow. |
| `loadBalancer` _[LoadBalancer](#loadbalancer)_ | LoadBalancer policy to apply when routing traffic from the gateway to the backend endpoints |



Expand Down Expand Up @@ -197,6 +198,31 @@ _Appears in:_



#### ConsistentHash



ConsistentHash defines the configuration related to the consistent hash load balancer policy

_Appears in:_
- [LoadBalancer](#loadbalancer)

| Field | Description |
| --- | --- |
| `type` _[ConsistentHashType](#consistenthashtype)_ | |


#### ConsistentHashType

_Underlying type:_ `string`

ConsistentHashType defines the type of input to hash on.

_Appears in:_
- [ConsistentHash](#consistenthash)



#### CustomTag


Expand Down Expand Up @@ -1006,6 +1032,32 @@ _Appears in:_
| `value` _string_ | Value defines the hard-coded value to add to each span. |


#### LoadBalancer



LoadBalancer defines the load balancer policy to be applied.

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

| Field | Description |
| --- | --- |
| `type` _[LoadBalancerType](#loadbalancertype)_ | Type decides the type of Load Balancer policy. Valid RateLimitType values are "ConsistentHash", "LeastRequest", "Random", "RoundRobin", |
| `consistentHash` _[ConsistentHash](#consistenthash)_ | ConsistentHash defines the configuration when the load balancer type is set to ConsistentHash |


#### LoadBalancerType

_Underlying type:_ `string`

LoadBalancerType specifies the types of LoadBalancer.

_Appears in:_
- [LoadBalancer](#loadbalancer)



#### LogLevel

_Underlying type:_ `string`
Expand Down

0 comments on commit ceaf2f9

Please sign in to comment.