From 736743bef1e6ac639c606938c6949b94e34bb0e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:18:54 +0800 Subject: [PATCH] chore(deps): bump github.com/kong/go-kong from 0.47.0 to 0.48.0 (#5012) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): bump github.com/kong/go-kong from 0.47.0 to 0.48.0 Bumps [github.com/kong/go-kong](https://github.com/kong/go-kong) from 0.47.0 to 0.48.0. - [Release notes](https://github.com/kong/go-kong/releases) - [Changelog](https://github.com/Kong/go-kong/blob/main/CHANGELOG.md) - [Commits](https://github.com/kong/go-kong/compare/v0.47.0...v0.48.0) --- updated-dependencies: - dependency-name: github.com/kong/go-kong dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: adjust route priority calculation code after changing route priority to uint64 --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Patryk Małek (cherry picked from commit 0422f3b74766773bf8e894cc3202e90f5d778aaa) --- .golangci.yaml | 5 ++++ go.mod | 10 +++---- go.sum | 18 ++++++----- internal/dataplane/parser/atc/route.go | 4 +-- .../parser/translate_httproute_test.go | 10 +++---- .../dataplane/parser/translators/atc_utils.go | 5 ++++ .../parser/translators/grpcroute_atc.go | 20 ++++++------- .../parser/translators/grpcroute_atc_test.go | 30 +++++++++---------- .../parser/translators/httproute_atc.go | 24 +++++++-------- .../parser/translators/httproute_atc_test.go | 26 ++++++++-------- .../parser/translators/ingress_atc.go | 18 +++++------ .../parser/translators/ingress_atc_test.go | 8 ++--- 12 files changed, 95 insertions(+), 83 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index a59111836d..831c64be93 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -129,3 +129,8 @@ issues: - gosec text: "Potential HTTP request made with variable url" path: test\.go + + - linters: + - revive + text: "var-declaration: should drop = 0 from declaration of var .*; it is the zero value" + path: \.go diff --git a/go.mod b/go.mod index 360cb0d2a4..5601e12664 100644 --- a/go.mod +++ b/go.mod @@ -26,11 +26,11 @@ require ( github.com/bombsimon/logrusr/v4 v4.0.0 github.com/go-logr/logr v1.2.4 github.com/goccy/go-json v0.10.2 - github.com/google/go-cmp v0.5.9 - github.com/google/uuid v1.3.1 + github.com/google/go-cmp v0.6.0 + github.com/google/uuid v1.4.0 github.com/jpillora/backoff v1.0.0 github.com/kong/deck v1.26.1 - github.com/kong/go-kong v0.47.0 + github.com/kong/go-kong v0.48.0 github.com/kong/kubernetes-telemetry v0.1.1 github.com/kong/kubernetes-testing-framework v0.39.1 github.com/lithammer/dedent v1.1.0 @@ -60,7 +60,7 @@ require ( sigs.k8s.io/gateway-api v0.8.1 sigs.k8s.io/kustomize/api v0.14.0 sigs.k8s.io/kustomize/kyaml v0.14.3 - sigs.k8s.io/yaml v1.3.0 + sigs.k8s.io/yaml v1.4.0 ) require ( @@ -169,7 +169,7 @@ require ( github.com/sourcegraph/conc v0.3.0 github.com/spf13/cast v1.5.1 // indirect github.com/ssgelm/cookiejarparser v1.0.1 // indirect - github.com/tidwall/gjson v1.16.0 // indirect + github.com/tidwall/gjson v1.17.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tklauser/go-sysconf v0.3.11 // indirect diff --git a/go.sum b/go.sum index 8f0d71bebc..2721d4ad3c 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,9 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.13.0 h1:y1C7Z3e149OJbOPDBxLYR8ITPz8dTKqQwjErKVHJC8k= github.com/google/go-containerregistry v0.13.0/go.mod h1:J9FQ+eSS4a1aC2GNZxvNpbWhgp0487v+cgiilB4FqDo= github.com/google/go-github/v48 v48.2.0 h1:68puzySE6WqUY9KWmpOsDEQfDZsso98rT6pZcz9HqcE= @@ -195,8 +196,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.2.5 h1:UR4rDjcgpgEnqpIEvkiqTYKBCKLNmlge2eVjoZfySzM= github.com/googleapis/enterprise-certificate-proxy v0.2.5/go.mod h1:RxW0N9901Cko1VOCW3SXCpWP+mlIEkk2tP7jnHy9a3w= github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas= @@ -248,8 +249,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kong/deck v1.26.1 h1:NwG/Zty5B0TlyDvHB9IlF9c7zRHDVEaYHFRjqxEM2yg= github.com/kong/deck v1.26.1/go.mod h1:B6f2nPWzTld/aTvtxAC6lWFIcAr4FsG25fgycdzeZQY= -github.com/kong/go-kong v0.47.0 h1:fuZjRnUChITogljM4mY4HGGTKTaZM50970Wwg6EvQgs= -github.com/kong/go-kong v0.47.0/go.mod h1:QaLx1EsT+roe5V6h7aKghwLn0bXg7l/Bg8wzlcCmygc= +github.com/kong/go-kong v0.48.0 h1:vK1OpoxO50qlKdwPfmx9ChvkTKRsoCCB3b3iHo1umLc= +github.com/kong/go-kong v0.48.0/go.mod h1:qH4CEFqT83ywmu1TlMZX09clQH4B8/dX88CtT/jdv/E= github.com/kong/kubernetes-telemetry v0.1.1 h1:q8iABCuonO16p5q6QVygr7J39G5o5jK5Y3w3ZlE8JC4= github.com/kong/kubernetes-telemetry v0.1.1/go.mod h1:0yzRZVPwKeOQUFMWbROEJzUE1z8WWngWiujoYtdEEPA= github.com/kong/kubernetes-testing-framework v0.39.1 h1:30dTVe0Muda3r6NAMQHvdGLuB+nkhZRXnJA8AJjuvO4= @@ -409,8 +410,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg= -github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM= +github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= @@ -662,5 +663,6 @@ sigs.k8s.io/kustomize/kyaml v0.14.3 h1:WpabVAKZe2YEp/irTSHwD6bfjwZnTtSDewd2BVJGM sigs.k8s.io/kustomize/kyaml v0.14.3/go.mod h1:npvh9epWysfQ689Rtt/U+dpOJDTBn8kUnF1O6VzvmZA= sigs.k8s.io/structured-merge-diff/v4 v4.3.0 h1:UZbZAZfX0wV2zr7YZorDz6GXROfDFj6LvqCRm4VUVKk= sigs.k8s.io/structured-merge-diff/v4 v4.3.0/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/internal/dataplane/parser/atc/route.go b/internal/dataplane/parser/atc/route.go index 1da66655eb..b045f998bf 100644 --- a/internal/dataplane/parser/atc/route.go +++ b/internal/dataplane/parser/atc/route.go @@ -5,7 +5,7 @@ import ( ) // ApplyExpression sets a Matcher as a Kong route's expression and assigns the route the given priority. -func ApplyExpression(r *kong.Route, m Matcher, priority int) { +func ApplyExpression(r *kong.Route, m Matcher, priority uint64) { r.Expression = kong.String(m.Expression()) - r.Priority = kong.Int(priority) + r.Priority = kong.Uint64(priority) } diff --git a/internal/dataplane/parser/translate_httproute_test.go b/internal/dataplane/parser/translate_httproute_test.go index 75ea504ac7..bb36866bd5 100644 --- a/internal/dataplane/parser/translate_httproute_test.go +++ b/internal/dataplane/parser/translate_httproute_test.go @@ -1949,7 +1949,7 @@ func TestIngressRulesFromSplitHTTPRouteMatchWithPriority(t *testing.T) { Expression: kong.String(`http.path == "/v1/foo"`), PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, @@ -2012,7 +2012,7 @@ func TestIngressRulesFromSplitHTTPRouteMatchWithPriority(t *testing.T) { Expression: kong.String(`(http.host == "foo.com") && (http.path == "/v1/foo")`), PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, Plugins: []kong.Plugin{ { @@ -2090,7 +2090,7 @@ func TestIngressRulesFromSplitHTTPRouteMatchWithPriority(t *testing.T) { Expression: kong.String(`(http.host =^ ".foo.com") && (http.path == "/v1/foo")`), PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, @@ -2143,7 +2143,7 @@ func TestIngressRulesFromSplitHTTPRouteMatchWithPriority(t *testing.T) { Expression: kong.String(`http.host == "a.foo.com"`), PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, @@ -2193,7 +2193,7 @@ func TestIngressRulesFromSplitHTTPRouteMatchWithPriority(t *testing.T) { Expression: kong.String(translators.CatchAllHTTPExpression), PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, diff --git a/internal/dataplane/parser/translators/atc_utils.go b/internal/dataplane/parser/translators/atc_utils.go index 16608d0bc5..1865d84ff9 100644 --- a/internal/dataplane/parser/translators/atc_utils.go +++ b/internal/dataplane/parser/translators/atc_utils.go @@ -21,6 +21,11 @@ const ( ResourceKindBitsGRPCRoute = 1 ) +type ( + // RoutePriorityType is the type of priority field of Kong routes. + RoutePriorityType = uint64 +) + const ( // CatchAllHTTPExpression is the expression to match all HTTP/HTTPS requests. // For rules with no matches and no hostnames in its parent HTTPRoute or GRPCRoute, diff --git a/internal/dataplane/parser/translators/grpcroute_atc.go b/internal/dataplane/parser/translators/grpcroute_atc.go index b337538acb..52b2a87537 100644 --- a/internal/dataplane/parser/translators/grpcroute_atc.go +++ b/internal/dataplane/parser/translators/grpcroute_atc.go @@ -302,7 +302,7 @@ func CalculateGRCPRouteMatchPriorityTraits(match SplitGRPCRouteMatch) GRPCRouteP // // REVIEW: althogh not specified in official docs, do we need to assign a bit for GRPC method match type // to assign higher priority for method match with `Exact` match? -func (t GRPCRoutePriorityTraits) EncodeToPriority() int { +func (t GRPCRoutePriorityTraits) EncodeToPriority() RoutePriorityType { const ( // PreciseHostnameShiftBits assigns bit 49 for marking if the hostname is non-wildcard. PreciseHostnameShiftBits = 49 @@ -319,15 +319,15 @@ func (t GRPCRoutePriorityTraits) EncodeToPriority() int { // and start from all 1s, then decrease by one for each GRPCRoute. ) - var priority int + var priority RoutePriorityType priority += ResourceKindBitsGRPCRoute << FromResourceKindPriorityShiftBits if t.PreciseHostname { priority += (1 << PreciseHostnameShiftBits) } - priority += t.HostnameLength << HostnameLengthShiftBits - priority += t.ServiceLength << ServiceLengthShiftBits - priority += t.MethodLength << MethodLengthShiftBits - priority += t.HeaderCount << HeaderCountShiftBits + priority += RoutePriorityType(t.HostnameLength) << HostnameLengthShiftBits + priority += RoutePriorityType(t.ServiceLength) << ServiceLengthShiftBits + priority += RoutePriorityType(t.MethodLength) << MethodLengthShiftBits + priority += RoutePriorityType(t.HeaderCount) << HeaderCountShiftBits return priority } @@ -344,7 +344,7 @@ type SplitGRPCRouteMatch struct { type SplitGRPCRouteMatchToPriority struct { Match SplitGRPCRouteMatch - Priority int + Priority uint64 } // AssignRoutePriorityToSplitGRPCRouteMatches assigns priority to ALL split GRPCRoute matches @@ -358,7 +358,7 @@ func AssignRoutePriorityToSplitGRPCRouteMatches( logger logr.Logger, splitGRPCouteMatches []SplitGRPCRouteMatch, ) []SplitGRPCRouteMatchToPriority { - priorityToSplitGRPCRouteMatches := map[int][]SplitGRPCRouteMatch{} + priorityToSplitGRPCRouteMatches := map[RoutePriorityType][]SplitGRPCRouteMatch{} for _, match := range splitGRPCouteMatches { priority := CalculateGRCPRouteMatchPriorityTraits(match).EncodeToPriority() priorityToSplitGRPCRouteMatches[priority] = append(priorityToSplitGRPCRouteMatches[priority], match) @@ -371,7 +371,7 @@ func AssignRoutePriorityToSplitGRPCRouteMatches( // sort them then starts with 2^14 -1 and decrease by one for each GRPCRoute; // If only one GRPCRoute occupies the priority, fill the relative order bits with all 1s. const relativeOrderAssignedBits = 14 - const defaultRelativeOrderPriorityBits = (1 << relativeOrderAssignedBits) - 1 + const defaultRelativeOrderPriorityBits RoutePriorityType = (1 << relativeOrderAssignedBits) - 1 for priority, matches := range priorityToSplitGRPCRouteMatches { if len(matches) == 1 { @@ -388,7 +388,7 @@ func AssignRoutePriorityToSplitGRPCRouteMatches( }) for i, match := range matches { - relativeOrderBits := defaultRelativeOrderPriorityBits - i + relativeOrderBits := defaultRelativeOrderPriorityBits - RoutePriorityType(i) // Although it is very unlikely that there are 2^14 = 16384 GRPCRoutes // should be given priority by their relative order, here we limit the // relativeOrderBits to be at least 0. diff --git a/internal/dataplane/parser/translators/grpcroute_atc_test.go b/internal/dataplane/parser/translators/grpcroute_atc_test.go index 1af73c067f..332919a6cf 100644 --- a/internal/dataplane/parser/translators/grpcroute_atc_test.go +++ b/internal/dataplane/parser/translators/grpcroute_atc_test.go @@ -59,7 +59,7 @@ func TestGenerateKongExpressionRoutesFromGRPCRouteRule(t *testing.T) { Route: kong.Route{ Name: kong.String("grpcroute.default.single-match.0.0"), Expression: kong.String(`(http.path ^= "/service0/") && (http.headers.x_foo == "Bar")`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, }, }, @@ -91,7 +91,7 @@ func TestGenerateKongExpressionRoutesFromGRPCRouteRule(t *testing.T) { Route: kong.Route{ Name: kong.String("grpcroute.default.single-match-with-hostname.0.0"), Expression: kong.String(`(http.path == "/service0/method0") && ((http.host == "foo.com") || (http.host =^ ".foo.com"))`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, }, }, @@ -136,7 +136,7 @@ func TestGenerateKongExpressionRoutesFromGRPCRouteRule(t *testing.T) { Route: kong.Route{ Name: kong.String("grpcroute.default.multiple-matches.0.0"), Expression: kong.String(`(http.path =^ "/method0") && ((http.headers.client == "kong-test") && (http.headers.version == "2"))`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, }, { @@ -149,7 +149,7 @@ func TestGenerateKongExpressionRoutesFromGRPCRouteRule(t *testing.T) { Route: kong.Route{ Name: kong.String("grpcroute.default.multiple-matches.0.1"), Expression: kong.String(`http.path ~ "^/v[012]/.+"`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, }, }, @@ -188,7 +188,7 @@ func TestGenerateKongExpressionRoutesFromGRPCRouteRule(t *testing.T) { Route: kong.Route{ Name: kong.String("grpcroute.default.single-match-with-annotations.0.0"), Expression: kong.String(`(http.path == "/service0/method0") && (tls.sni == "kong.foo.com")`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, }, }, @@ -211,7 +211,7 @@ func TestGenerateKongExpressionRoutesFromGRPCRouteRule(t *testing.T) { Route: kong.Route{ Name: kong.String("grpcroute.default.hostname-only.0.0"), Expression: kong.String(`http.host == "foo.com"`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, }, }, @@ -605,7 +605,7 @@ func TestGRPCRouteTraitsEncodeToPriority(t *testing.T) { testCases := []struct { name string traits GRPCRoutePriorityTraits - exprectedPriority int + exprectedPriority RoutePriorityType }{ { name: "precise hostname", @@ -654,7 +654,7 @@ func TestAssignRoutePriorityToSplitGRPCRouteMatches(t *testing.T) { name string splitGRPCRouteMatches []SplitGRPCRouteMatch // GRPCRoute index -> priority - priorities map[splitGRPCRouteMatchIndex]int + priorities map[splitGRPCRouteMatchIndex]RoutePriorityType }{ { name: "no dupelicated fixed priority", @@ -724,7 +724,7 @@ func TestAssignRoutePriorityToSplitGRPCRouteMatches(t *testing.T) { }, }, }, - priorities: map[splitGRPCRouteMatchIndex]int{ + priorities: map[splitGRPCRouteMatchIndex]RoutePriorityType{ { namespace: "default", name: "grpcroute-1", @@ -822,7 +822,7 @@ func TestAssignRoutePriorityToSplitGRPCRouteMatches(t *testing.T) { MatchIndex: 0, }, }, - priorities: map[splitGRPCRouteMatchIndex]int{ + priorities: map[splitGRPCRouteMatchIndex]RoutePriorityType{ { namespace: "default", name: "grpcroute-1", @@ -919,7 +919,7 @@ func TestAssignRoutePriorityToSplitGRPCRouteMatches(t *testing.T) { MatchIndex: 0, }, }, - priorities: map[splitGRPCRouteMatchIndex]int{ + priorities: map[splitGRPCRouteMatchIndex]RoutePriorityType{ { namespace: "default", name: "grpcroute-1", @@ -1029,7 +1029,7 @@ func TestAssignRoutePriorityToSplitGRPCRouteMatches(t *testing.T) { MatchIndex: 1, }, }, - priorities: map[splitGRPCRouteMatchIndex]int{ + priorities: map[splitGRPCRouteMatchIndex]RoutePriorityType{ { namespace: "default", name: "grpcroute-1", @@ -1131,7 +1131,7 @@ func TestKongExpressionRouteFromSplitGRPCRouteWithPriority(t *testing.T) { Name: kong.String("grpcroute.default.no-hostname-exact-method._.0.0"), PreserveHost: kong.Bool(true), Expression: kong.String(`http.path == "/pets/list"`), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, ExpressionRoutes: true, }, @@ -1183,7 +1183,7 @@ func TestKongExpressionRouteFromSplitGRPCRouteWithPriority(t *testing.T) { Name: kong.String("grpcroute.default.precise-hostname-regex-method.foo.com.0.0"), Expression: kong.String(`(http.path ~ "^/name/[a-z0-9]+") && (http.host == "foo.com")`), PreserveHost: kong.Bool(true), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, ExpressionRoutes: true, }, @@ -1252,7 +1252,7 @@ func TestKongExpressionRouteFromSplitGRPCRouteWithPriority(t *testing.T) { Name: kong.String("grpcroute.default.wildcard-hostname-header-match._.foo.com.0.1"), Expression: kong.String(`(http.path ^= "/name/") && (http.headers.foo == "bar") && (http.host =^ ".foo.com")`), PreserveHost: kong.Bool(true), - Priority: kong.Int(1024), + Priority: kong.Uint64(1024), }, ExpressionRoutes: true, }, diff --git a/internal/dataplane/parser/translators/httproute_atc.go b/internal/dataplane/parser/translators/httproute_atc.go index 568deaa793..f2c32f7d3f 100644 --- a/internal/dataplane/parser/translators/httproute_atc.go +++ b/internal/dataplane/parser/translators/httproute_atc.go @@ -273,7 +273,7 @@ func SplitHTTPRoute(httproute *gatewayv1beta1.HTTPRoute) []SplitHTTPRouteMatch { type SplitHTTPRouteMatchToKongRoutePriority struct { Match SplitHTTPRouteMatch - Priority int + Priority RoutePriorityType } type HTTPRoutePriorityTraits struct { @@ -363,7 +363,7 @@ func CalculateHTTPRouteMatchPriorityTraits(match SplitHTTPRouteMatch) HTTPRouteP // Header No.: number of header matches. // Query No.: number of query parameter matches. // relative order: relative order of creation timestamp, namespace and name and internal rule/match order between different (split) HTTPRoutes. -func (t HTTPRoutePriorityTraits) EncodeToPriority() int { +func (t HTTPRoutePriorityTraits) EncodeToPriority() RoutePriorityType { const ( // PreciseHostnameShiftBits assigns bit 49 for marking if the hostname is non-wildcard. PreciseHostnameShiftBits = 49 @@ -386,11 +386,11 @@ func (t HTTPRoutePriorityTraits) EncodeToPriority() int { // and start from all 1s, then decrease by one for each HTTPRoute. ) - var priority int + var priority RoutePriorityType if t.PreciseHostname { priority += (1 << PreciseHostnameShiftBits) } - priority += t.HostnameLength << HostnameLengthShiftBits + priority += RoutePriorityType(t.HostnameLength << HostnameLengthShiftBits) if t.PathType == gatewayv1beta1.PathMatchExact { priority += (1 << ExactPathShiftBits) @@ -401,15 +401,15 @@ func (t HTTPRoutePriorityTraits) EncodeToPriority() int { // max length of path is 1024, but path must start with /, so we use PathLength-1 to fill the bits. if t.PathLength > 0 { - priority += ((t.PathLength - 1) << PathLengthShiftBits) + priority += RoutePriorityType(((t.PathLength - 1) << PathLengthShiftBits)) } - priority += (t.HeaderCount << HeaderNumberShiftBits) + priority += RoutePriorityType(t.HeaderCount << HeaderNumberShiftBits) if t.HasMethodMatch { priority += (1 << MethodMatchShiftBits) } - priority += (t.QueryParamCount << QueryParamNumberShiftBits) - priority += (ResourceKindBitsHTTPRoute << FromResourceKindPriorityShiftBits) + priority += RoutePriorityType(t.QueryParamCount << QueryParamNumberShiftBits) + priority += RoutePriorityType(ResourceKindBitsHTTPRoute << FromResourceKindPriorityShiftBits) return priority } @@ -425,7 +425,7 @@ func AssignRoutePriorityToSplitHTTPRouteMatches( logger logr.Logger, splitHTTPRouteMatches []SplitHTTPRouteMatch, ) []SplitHTTPRouteMatchToKongRoutePriority { - priorityToSplitHTTPRouteMatches := map[int][]SplitHTTPRouteMatch{} + priorityToSplitHTTPRouteMatches := map[RoutePriorityType][]SplitHTTPRouteMatch{} for _, match := range splitHTTPRouteMatches { priority := CalculateHTTPRouteMatchPriorityTraits(match).EncodeToPriority() @@ -439,7 +439,7 @@ func AssignRoutePriorityToSplitHTTPRouteMatches( // sort them then starts with 2^18 -1 and decrease by one for each HTTPRoute; // If only one match occupies the priority, fill the relative order bits with all 1s. const RelativeOrderAssignedBits = 18 - const defaultRelativeOrderPriorityBits = (1 << RelativeOrderAssignedBits) - 1 + const defaultRelativeOrderPriorityBits = (uint64(1) << RelativeOrderAssignedBits) - 1 for priority, matches := range priorityToSplitHTTPRouteMatches { if len(matches) == 1 { httpRouteMatchesToPriorities = append(httpRouteMatchesToPriorities, SplitHTTPRouteMatchToKongRoutePriority{ @@ -454,7 +454,7 @@ func AssignRoutePriorityToSplitHTTPRouteMatches( }) for i, match := range matches { - relativeOrderBits := defaultRelativeOrderPriorityBits - i + relativeOrderBits := defaultRelativeOrderPriorityBits - RoutePriorityType(i) // Although it is very unlikely that there are 2^18 = 262144 HTTPRoutes // should be given priority by their relative order, here we limit the // relativeOrderBits to be at least 0. @@ -549,7 +549,7 @@ func KongExpressionRouteFromHTTPRouteMatchWithPriority( // generate a "catch-all" route if the generated expression is empty. if r.Expression == nil || len(*r.Expression) == 0 { r.Expression = kong.String(CatchAllHTTPExpression) - r.Priority = kong.Int(httpRouteMatchWithPriority.Priority) + r.Priority = kong.Uint64(httpRouteMatchWithPriority.Priority) } // translate filters in the rule. diff --git a/internal/dataplane/parser/translators/httproute_atc_test.go b/internal/dataplane/parser/translators/httproute_atc_test.go index 0a5376f70f..90b772ec1f 100644 --- a/internal/dataplane/parser/translators/httproute_atc_test.go +++ b/internal/dataplane/parser/translators/httproute_atc_test.go @@ -57,7 +57,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`(http.host == "foo.com") || (http.host =^ ".bar.com")`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, ExpressionRoutes: true, }, @@ -77,7 +77,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`(http.path == "/prefix") || (http.path ^= "/prefix/")`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, @@ -99,7 +99,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`((http.path == "/prefix") || (http.path ^= "/prefix/")) || ((http.path == "/exact") && (http.method == "GET"))`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, @@ -128,7 +128,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`http.path == "/exact/0"`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, Plugins: []kong.Plugin{ { @@ -154,7 +154,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`http.path == "/exact/1"`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, Plugins: []kong.Plugin{ { @@ -196,7 +196,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`(http.path == "/exact/0") || (http.path ~ "^/regex/[a-z]+")`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, Plugins: []kong.Plugin{ { @@ -242,7 +242,7 @@ func TestGenerateKongExpressionRoutesFromHTTPRouteMatches(t *testing.T) { PreserveHost: kong.Bool(true), StripPath: kong.Bool(false), Expression: kong.String(`((http.path == "/prefix/0") || (http.path ^= "/prefix/0/")) && (http.host == "a.foo.com") && (tls.sni == "a.foo.com")`), - Priority: kong.Int(1), + Priority: kong.Uint64(1), }, Plugins: []kong.Plugin{}, ExpressionRoutes: true, @@ -468,7 +468,7 @@ func TestEncodeHTTPRoutePriorityFromTraits(t *testing.T) { testCases := []struct { name string traits HTTPRoutePriorityTraits - expectedPriority int + expectedPriority RoutePriorityType }{ { name: "precise hostname and exact path", @@ -734,7 +734,7 @@ func TestAssignRoutePriorityToSplitHTTPRouteMatches(t *testing.T) { name string matches []SplitHTTPRouteMatch // HTTPRoute index -> priority - priorities map[splitHTTPRouteIndex]int + priorities map[splitHTTPRouteIndex]RoutePriorityType }{ { name: "no dupelicated fixed priority", @@ -782,7 +782,7 @@ func TestAssignRoutePriorityToSplitHTTPRouteMatches(t *testing.T) { MatchIndex: 0, }, }, - priorities: map[splitHTTPRouteIndex]int{ + priorities: map[splitHTTPRouteIndex]RoutePriorityType{ { namespace: "default", name: "httproute-1", @@ -859,7 +859,7 @@ func TestAssignRoutePriorityToSplitHTTPRouteMatches(t *testing.T) { MatchIndex: 0, }, }, - priorities: map[splitHTTPRouteIndex]int{ + priorities: map[splitHTTPRouteIndex]RoutePriorityType{ { namespace: "default", name: "httproute-1", @@ -932,7 +932,7 @@ func TestAssignRoutePriorityToSplitHTTPRouteMatches(t *testing.T) { MatchIndex: 0, }, }, - priorities: map[splitHTTPRouteIndex]int{ + priorities: map[splitHTTPRouteIndex]RoutePriorityType{ { namespace: "default", name: "httproute-1", @@ -1011,7 +1011,7 @@ func TestAssignRoutePriorityToSplitHTTPRouteMatches(t *testing.T) { MatchIndex: 1, }, }, - priorities: map[splitHTTPRouteIndex]int{ + priorities: map[splitHTTPRouteIndex]RoutePriorityType{ { namespace: "default", name: "httproute-1", diff --git a/internal/dataplane/parser/translators/ingress_atc.go b/internal/dataplane/parser/translators/ingress_atc.go index c61f1a1f3c..f8ccb9f109 100644 --- a/internal/dataplane/parser/translators/ingress_atc.go +++ b/internal/dataplane/parser/translators/ingress_atc.go @@ -27,8 +27,8 @@ var ( ) var ( - NormalIngressExpressionPriority = 1 - IngressDefaultBackendPriority = 0 + NormalIngressExpressionPriority RoutePriorityType = 1 + IngressDefaultBackendPriority RoutePriorityType = 0 ) func (m *ingressTranslationMeta) translateIntoKongExpressionRoute() *kongstate.Route { @@ -244,7 +244,7 @@ type IngressRoutePriorityTraits struct { // - P (Plain Host): set if ALL hosts are non-wildcard. // - R (Regex): if set, regex match is used. // - Path Length: maximum length of the path to match. -func (t IngressRoutePriorityTraits) EncodeToPriority() int { +func (t IngressRoutePriorityTraits) EncodeToPriority() RoutePriorityType { // route.priority in admin API could only use the lowest 52 bits // because the numbers in JSON are parsed into double precision floating numbers. const ( @@ -265,12 +265,12 @@ func (t IngressRoutePriorityTraits) EncodeToPriority() int { pathLengthLimit = (1 << 16) - 1 ) - var priority int + var priority RoutePriorityType // add max path length. if t.MaxPathLength > pathLengthLimit { t.MaxPathLength = pathLengthLimit } - priority += t.MaxPathLength + priority += RoutePriorityType(t.MaxPathLength) // add regex path mark. if t.HasRegexPath { priority += (1 << regexPathShiftBits) @@ -282,9 +282,9 @@ func (t IngressRoutePriorityTraits) EncodeToPriority() int { if t.HeaderCount > headerNumberLimit { t.HeaderCount = headerNumberLimit } - priority += (t.HeaderCount << headerNumberShiftBits) - priority += (t.MatchFields << matchFieldsShiftBits) - priority += (ResourceKindBitsIngress << FromResourceKindPriorityShiftBits) + priority += RoutePriorityType(t.HeaderCount << headerNumberShiftBits) + priority += RoutePriorityType(t.MatchFields << matchFieldsShiftBits) + priority += RoutePriorityType(ResourceKindBitsIngress << FromResourceKindPriorityShiftBits) return priority } @@ -400,7 +400,7 @@ func calculateExpressionRoutePriority( regexPathPrefix string, ingressHost string, ingressAnnotations map[string]string, -) int { +) RoutePriorityType { traits := calculateIngressRoutePriorityTraits( paths, regexPathPrefix, ingressHost, ingressAnnotations, ) diff --git a/internal/dataplane/parser/translators/ingress_atc_test.go b/internal/dataplane/parser/translators/ingress_atc_test.go index 2a099425f5..db2acd01e0 100644 --- a/internal/dataplane/parser/translators/ingress_atc_test.go +++ b/internal/dataplane/parser/translators/ingress_atc_test.go @@ -74,7 +74,7 @@ func TestTranslateIngressATC(t *testing.T) { Route: kong.Route{ Name: kong.String("default.test-ingress.test-service.konghq.com.80"), Expression: kong.String(`(http.host == "konghq.com") && ((http.path == "/api") || (http.path ^= "/api/"))`), - Priority: kong.Int(IngressRoutePriorityTraits{ + Priority: kong.Uint64(IngressRoutePriorityTraits{ MatchFields: 2, PlainHostOnly: true, MaxPathLength: 5, @@ -151,7 +151,7 @@ func TestTranslateIngressATC(t *testing.T) { Route: kong.Route{ Name: kong.String("default.test-ingress.test-service.konghq.com.80"), Expression: kong.String(`(http.host == "konghq.com") && (http.path ^= "/api/")`), - Priority: kong.Int(IngressRoutePriorityTraits{ + Priority: kong.Uint64(IngressRoutePriorityTraits{ MatchFields: 2, PlainHostOnly: true, MaxPathLength: 5, @@ -238,7 +238,7 @@ func TestTranslateIngressATC(t *testing.T) { Route: kong.Route{ Name: kong.String("default.test-ingress-annotations.test-service.konghq.com.80"), Expression: kong.String(`(http.host == "konghq.com") && (http.path ^= "/api/") && (http.headers.foo == "bar") && (http.method == "GET")`), - Priority: kong.Int(IngressRoutePriorityTraits{ + Priority: kong.Uint64(IngressRoutePriorityTraits{ MatchFields: 4, PlainHostOnly: true, MaxPathLength: 5, @@ -422,7 +422,7 @@ func TestEncodeIngressRoutePriorityFromTraits(t *testing.T) { testCases := []struct { name string traits IngressRoutePriorityTraits - expectedPriority int + expectedPriority RoutePriorityType }{ { name: "plain host true regex path false",