Skip to content

Commit 06f961e

Browse files
authored
feat: support chash on multiple headers (#7198)
* feat: support chash based on multiple headers Signed-off-by: Shreemaan Abhishek <[email protected]>
1 parent bd2380d commit 06f961e

29 files changed

+1396
-162
lines changed

api/v1alpha1/loadbalancer_types.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,29 @@ const (
7070
// +union
7171
//
7272
// +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."
73+
// +kubebuilder:validation:XValidation:rule="self.type == 'Headers' ? has(self.headers) : !has(self.headers)",message="If consistent hash type is headers, the headers field must be set."
7374
// +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."
7475
type ConsistentHash struct {
7576
// ConsistentHashType defines the type of input to hash on. Valid Type values are
7677
// "SourceIP",
7778
// "Header",
79+
// "Headers",
7880
// "Cookie".
7981
//
8082
// +unionDiscriminator
8183
Type ConsistentHashType `json:"type"`
8284

8385
// Header configures the header hash policy when the consistent hash type is set to Header.
8486
//
87+
// Deprecated: use Headers instead
8588
// +optional
8689
Header *Header `json:"header,omitempty"`
8790

91+
// Headers configures the header hash policy for each header, when the consistent hash type is set to Headers.
92+
//
93+
// +optional
94+
Headers []*Header `json:"headers,omitempty"`
95+
8896
// Cookie configures the cookie hash policy when the consistent hash type is set to Cookie.
8997
//
9098
// +optional
@@ -127,14 +135,18 @@ type Cookie struct {
127135
}
128136

129137
// ConsistentHashType defines the type of input to hash on.
130-
// +kubebuilder:validation:Enum=SourceIP;Header;Cookie
138+
// +kubebuilder:validation:Enum=SourceIP;Header;Headers;Cookie
131139
type ConsistentHashType string
132140

133141
const (
134142
// SourceIPConsistentHashType hashes based on the source IP address.
135143
SourceIPConsistentHashType ConsistentHashType = "SourceIP"
136144
// HeaderConsistentHashType hashes based on a request header.
145+
//
146+
// Deprecated: use HeadersConsistentHashType instead
137147
HeaderConsistentHashType ConsistentHashType = "Header"
148+
// HeadersConsistentHashType hashes based on multiple request headers.
149+
HeadersConsistentHashType ConsistentHashType = "Headers"
138150
// CookieConsistentHashType hashes based on a cookie.
139151
CookieConsistentHashType ConsistentHashType = "Cookie"
140152
)

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 11 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: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,32 @@ spec:
675675
- name
676676
type: object
677677
header:
678-
description: Header configures the header hash policy when
679-
the consistent hash type is set to Header.
678+
description: |-
679+
Header configures the header hash policy when the consistent hash type is set to Header.
680+
681+
Deprecated: use Headers instead
680682
properties:
681683
name:
682684
description: Name of the header to hash.
683685
type: string
684686
required:
685687
- name
686688
type: object
689+
headers:
690+
description: Headers configures the header hash policy for
691+
each header, when the consistent hash type is set to Headers.
692+
items:
693+
description: |-
694+
Header defines the header hashing configuration for consistent hash based
695+
load balancing.
696+
properties:
697+
name:
698+
description: Name of the header to hash.
699+
type: string
700+
required:
701+
- name
702+
type: object
703+
type: array
687704
tableSize:
688705
default: 65537
689706
description: The table size for consistent hashing, must be
@@ -697,10 +714,12 @@ spec:
697714
ConsistentHashType defines the type of input to hash on. Valid Type values are
698715
"SourceIP",
699716
"Header",
717+
"Headers",
700718
"Cookie".
701719
enum:
702720
- SourceIP
703721
- Header
722+
- Headers
704723
- Cookie
705724
type: string
706725
required:
@@ -710,6 +729,9 @@ spec:
710729
- message: If consistent hash type is header, the header field
711730
must be set.
712731
rule: 'self.type == ''Header'' ? has(self.header) : !has(self.header)'
732+
- message: If consistent hash type is headers, the headers field
733+
must be set.
734+
rule: 'self.type == ''Headers'' ? has(self.headers) : !has(self.headers)'
713735
- message: If consistent hash type is cookie, the cookie field
714736
must be set.
715737
rule: 'self.type == ''Cookie'' ? has(self.cookie) : !has(self.cookie)'

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,15 +714,33 @@ spec:
714714
- name
715715
type: object
716716
header:
717-
description: Header configures the header hash policy
718-
when the consistent hash type is set to Header.
717+
description: |-
718+
Header configures the header hash policy when the consistent hash type is set to Header.
719+
720+
Deprecated: use Headers instead
719721
properties:
720722
name:
721723
description: Name of the header to hash.
722724
type: string
723725
required:
724726
- name
725727
type: object
728+
headers:
729+
description: Headers configures the header hash
730+
policy for each header, when the consistent hash
731+
type is set to Headers.
732+
items:
733+
description: |-
734+
Header defines the header hashing configuration for consistent hash based
735+
load balancing.
736+
properties:
737+
name:
738+
description: Name of the header to hash.
739+
type: string
740+
required:
741+
- name
742+
type: object
743+
type: array
726744
tableSize:
727745
default: 65537
728746
description: The table size for consistent hashing,
@@ -736,10 +754,12 @@ spec:
736754
ConsistentHashType defines the type of input to hash on. Valid Type values are
737755
"SourceIP",
738756
"Header",
757+
"Headers",
739758
"Cookie".
740759
enum:
741760
- SourceIP
742761
- Header
762+
- Headers
743763
- Cookie
744764
type: string
745765
required:
@@ -750,6 +770,10 @@ spec:
750770
field must be set.
751771
rule: 'self.type == ''Header'' ? has(self.header)
752772
: !has(self.header)'
773+
- message: If consistent hash type is headers, the headers
774+
field must be set.
775+
rule: 'self.type == ''Headers'' ? has(self.headers)
776+
: !has(self.headers)'
753777
- message: If consistent hash type is cookie, the cookie
754778
field must be set.
755779
rule: 'self.type == ''Cookie'' ? has(self.cookie)

0 commit comments

Comments
 (0)