-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(translator): Implement header hash policy for consistent hash lo…
…ad balancers (#3357) * Map consistent hash configuration Signed-off-by: Harry Turton <harryt@canva.com> * Implement mapping and add tests Signed-off-by: Harry Turton <harryt@canva.com> * Small refactors, add yaml keys Signed-off-by: Harry Turton <harryt@canva.com> * Add documentation and lints Signed-off-by: Harry Turton <harryt@canva.com> * Add additional tests Signed-off-by: Harry Turton <harryt@canva.com> --------- Signed-off-by: Harry Turton <harryt@canva.com>
- Loading branch information
1 parent
bb348dc
commit 7863f81
Showing
14 changed files
with
199 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 translator | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" | ||
"k8s.io/utils/ptr" | ||
|
||
"github.com/envoyproxy/gateway/internal/ir" | ||
) | ||
|
||
func Test_buildHashPolicy(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
httpRoute *ir.HTTPRoute | ||
want []*routev3.RouteAction_HashPolicy | ||
}{ | ||
{ | ||
name: "Nil HttpRoute", | ||
httpRoute: nil, | ||
want: nil, | ||
}, | ||
{ | ||
name: "Nil LoadBalancer in HttpRoute", | ||
httpRoute: &ir.HTTPRoute{}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "Nil ConsistentHash in LoadBalancer", | ||
httpRoute: &ir.HTTPRoute{LoadBalancer: &ir.LoadBalancer{}}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "ConsistentHash with nil SourceIP and Header", | ||
httpRoute: &ir.HTTPRoute{LoadBalancer: &ir.LoadBalancer{ConsistentHash: &ir.ConsistentHash{}}}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "ConsistentHash with SourceIP set to false", | ||
httpRoute: &ir.HTTPRoute{LoadBalancer: &ir.LoadBalancer{ConsistentHash: &ir.ConsistentHash{SourceIP: ptr.To(false)}}}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "ConsistentHash with SourceIP set to true", | ||
httpRoute: &ir.HTTPRoute{LoadBalancer: &ir.LoadBalancer{ConsistentHash: &ir.ConsistentHash{SourceIP: ptr.To(true)}}}, | ||
want: []*routev3.RouteAction_HashPolicy{ | ||
{ | ||
PolicySpecifier: &routev3.RouteAction_HashPolicy_ConnectionProperties_{ | ||
ConnectionProperties: &routev3.RouteAction_HashPolicy_ConnectionProperties{ | ||
SourceIp: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "ConsistentHash with Header", | ||
httpRoute: &ir.HTTPRoute{LoadBalancer: &ir.LoadBalancer{ConsistentHash: &ir.ConsistentHash{Header: &ir.Header{Name: "name"}}}}, | ||
want: []*routev3.RouteAction_HashPolicy{ | ||
{ | ||
PolicySpecifier: &routev3.RouteAction_HashPolicy_Header_{ | ||
Header: &routev3.RouteAction_HashPolicy_Header{ | ||
HeaderName: "name", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := buildHashPolicy(tt.httpRoute) | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("buildHashPolicy() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters