From 7a378839bfc9d44c7f831df492491b411971a5f0 Mon Sep 17 00:00:00 2001 From: Dingkang Li Date: Wed, 8 May 2024 16:56:19 +0800 Subject: [PATCH 1/3] Add consistent hash table size api Signed-off-by: Dingkang Li --- api/v1alpha1/loadbalancer_types.go | 8 ++++++++ api/v1alpha1/zz_generated.deepcopy.go | 7 ++++++- .../gateway.envoyproxy.io_backendtrafficpolicies.yaml | 8 ++++++++ site/content/en/latest/api/extension_types.md | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/loadbalancer_types.go b/api/v1alpha1/loadbalancer_types.go index 3bd4d9c4e54..2b3ab91b828 100644 --- a/api/v1alpha1/loadbalancer_types.go +++ b/api/v1alpha1/loadbalancer_types.go @@ -55,6 +55,14 @@ const ( // load balancer policy type ConsistentHash struct { Type ConsistentHashType `json:"type"` + + // The table size for consistent hashing, must be prime number limited to 5000011. + // + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=5000011 + // +kubebuilder:default=65537 + // +optional + TableSize *uint64 `json:"tableSize,omitempty"` } // ConsistentHashType defines the type of input to hash on. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 8ebd4453c5c..7c59e4f3123 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -751,6 +751,11 @@ func (in *ConnectionLimit) DeepCopy() *ConnectionLimit { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ConsistentHash) DeepCopyInto(out *ConsistentHash) { *out = *in + if in.TableSize != nil { + in, out := &in.TableSize, &out.TableSize + *out = new(uint64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConsistentHash. @@ -2865,7 +2870,7 @@ func (in *LoadBalancer) DeepCopyInto(out *LoadBalancer) { if in.ConsistentHash != nil { in, out := &in.ConsistentHash, &out.ConsistentHash *out = new(ConsistentHash) - **out = **in + (*in).DeepCopyInto(*out) } if in.SlowStart != nil { in, out := &in.SlowStart, &out.SlowStart diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml index eb8457a116b..b51c0ae8cdc 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml @@ -412,6 +412,14 @@ spec: ConsistentHash defines the configuration when the load balancer type is set to ConsistentHash properties: + tableSize: + default: 65537 + description: The table size for consistent hashing, must be + prime number limited to 5000011. + format: int64 + maximum: 5000011 + minimum: 1 + type: integer type: description: ConsistentHashType defines the type of input to hash on. diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md index c00e9d8a915..3540a04b8ab 100644 --- a/site/content/en/latest/api/extension_types.md +++ b/site/content/en/latest/api/extension_types.md @@ -563,6 +563,7 @@ _Appears in:_ | Field | Type | Required | Description | | --- | --- | --- | --- | | `type` | _[ConsistentHashType](#consistenthashtype)_ | true | | +| `tableSize` | _integer_ | false | The table size for consistent hashing, must be prime number limited to 5000011. | #### ConsistentHashType From 78f31d0522d0903913e2d2609febc23d635c05a1 Mon Sep 17 00:00:00 2001 From: Dingkang Li Date: Wed, 8 May 2024 17:32:05 +0800 Subject: [PATCH 2/3] Set consistent hash table size's minimum as the smallest prime number: 2 Signed-off-by: Dingkang Li --- api/v1alpha1/loadbalancer_types.go | 2 +- .../generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/loadbalancer_types.go b/api/v1alpha1/loadbalancer_types.go index 2b3ab91b828..9e9026af3e7 100644 --- a/api/v1alpha1/loadbalancer_types.go +++ b/api/v1alpha1/loadbalancer_types.go @@ -58,7 +58,7 @@ type ConsistentHash struct { // The table size for consistent hashing, must be prime number limited to 5000011. // - // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Minimum=2 // +kubebuilder:validation:Maximum=5000011 // +kubebuilder:default=65537 // +optional diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml index b51c0ae8cdc..afb60bee9b2 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml @@ -418,7 +418,7 @@ spec: prime number limited to 5000011. format: int64 maximum: 5000011 - minimum: 1 + minimum: 2 type: integer type: description: ConsistentHashType defines the type of input From 4202e186dc60b32c9f0a7ea4015072de2571b9cf Mon Sep 17 00:00:00 2001 From: Dingkang Li Date: Tue, 14 May 2024 16:27:05 +0800 Subject: [PATCH 3/3] Comment tableSize api as notImplementedHide Signed-off-by: Dingkang Li --- api/v1alpha1/loadbalancer_types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/v1alpha1/loadbalancer_types.go b/api/v1alpha1/loadbalancer_types.go index 1ffe76677f1..e3aeffb0d80 100644 --- a/api/v1alpha1/loadbalancer_types.go +++ b/api/v1alpha1/loadbalancer_types.go @@ -74,6 +74,7 @@ type ConsistentHash struct { // +kubebuilder:validation:Maximum=5000011 // +kubebuilder:default=65537 // +optional + // +notImplementedHide TableSize *uint64 `json:"tableSize,omitempty"` }