Skip to content

Commit

Permalink
api: cookie based consistent hashing
Browse files Browse the repository at this point in the history
Relates to envoyproxy#2624

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed May 21, 2024
1 parent b99888a commit d5ca7c8
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
31 changes: 30 additions & 1 deletion api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
// +union
//
// +kubebuilder:validation:XValidation:rule="self.type == 'Header' ? has(self.header) : !has(self.header)",message="If consistent hash type is header, the header field must be set."
// +kubebuilder:validation:XValidation:rule="self.type == 'Cookie' ? has(self.cookie) : !has(self.cookie)",message="If consistent hash type is cookie, the cookie field must be set."
type ConsistentHash struct {
// ConsistentHashType defines the type of input to hash on. Valid Type values are "SourceIP" or "Header".
//
Expand All @@ -67,6 +68,12 @@ type ConsistentHash struct {
// +optional
Header *Header `json:"header,omitempty"`

// Cookie configures the cookie hash policy when the consistent hash type is set to Cookie.
//
// +optional
// +notImplementedHide
Cookie *Cookie `json:"cookie,omitempty"`

// The table size for consistent hashing, must be prime number limited to 5000011.
//
// +kubebuilder:validation:Minimum=2
Expand All @@ -84,14 +91,36 @@ type Header struct {
Name string `json:"name"`
}

// Cookie defines the cookie hashing configuration for consistent hash based
// load balancing.
type Cookie struct {
// Name of the cookie to hash.
// If this cookie doesnt exist in the request, Envoy will generate a cookie and set
// the TTL on the response back to the client based on Layer 4
// attributes of the backend endpoint, to ensure that these future requests
// go to the same backend endpoint. Make sure to set the TTL field for this case.
Name string `json:"name"`
// TTL of the generated cookie if the cookie is not present. This value sets the
// Max-Age attribute value.
//
// +optional
// +notImplementedHide
TTL *metav1.Duration `json:"ttl,omitempty"`
// Additional Attributes to set for the generated cookie.
//
// +optional
// +notImplementedHide
Attributes map[string]string `json:"attributes,omitempty"`
}

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

const (
// SourceIPConsistentHashType hashes based on the source IP address.
SourceIPConsistentHashType ConsistentHashType = "SourceIP"
// HeaderConsistentHashType hashes based on a request header.
// HeaderConsistentHas`hType hashes based on a request header.
HeaderConsistentHashType ConsistentHashType = "Header"
)

Expand Down
32 changes: 32 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 @@ -412,6 +412,32 @@ spec:
ConsistentHash defines the configuration when the load balancer type is
set to ConsistentHash
properties:
cookie:
description: Cookie configures the cookie hash policy when
the consistent hash type is set to Cookie.
properties:
attributes:
additionalProperties:
type: string
description: Additional Attributes to set for the generated
cookie.
type: object
name:
description: |-
Name of the cookie to hash.
If this cookie doesnt exist in the request, Envoy will generate a cookie and set
the TTL on the response back to the client based on Layer 4
attributes of the backend endpoint, to ensure that these future requests
go to the same backend endpoint. Make sure to set the TTL field for this case.
type: string
ttl:
description: |-
TTL of the generated cookie if the cookie is not present. This value sets the
Max-Age attribute value.
type: string
required:
- name
type: object
header:
description: Header configures the header hash policy when
the consistent hash type is set to Header.
Expand Down Expand Up @@ -444,6 +470,9 @@ spec:
- message: If consistent hash type is header, the header field
must be set.
rule: 'self.type == ''Header'' ? has(self.header) : !has(self.header)'
- message: If consistent hash type is cookie, the cookie field
must be set.
rule: 'self.type == ''Cookie'' ? has(self.cookie) : !has(self.cookie)'
slowStart:
description: |-
SlowStart defines the configuration related to the slow start load balancer policy.
Expand Down
17 changes: 16 additions & 1 deletion site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,22 @@ _Appears in:_
| Value | Description |
| ----- | ----------- |
| `SourceIP` | SourceIPConsistentHashType hashes based on the source IP address.<br /> |
| `Header` | HeaderConsistentHashType hashes based on a request header.<br /> |
| `Header` | HeaderConsistentHas`hType hashes based on a request header.<br /> |


#### Cookie



Cookie defines the cookie hashing configuration for consistent hash based
load balancing.

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | _string_ | true | Name of the cookie to hash.<br />If this cookie doesnt exist in the request, Envoy will generate a cookie and set<br />the TTL on the response back to the client based on Layer 4<br />attributes of the backend endpoint, to ensure that these future requests<br />go to the same backend endpoint. Make sure to set the TTL field for this case. |


#### CustomHeaderExtensionSettings
Expand Down

0 comments on commit d5ca7c8

Please sign in to comment.