From cc8ae3b8922d5468e58923c7bb3ff8cf815bd11a Mon Sep 17 00:00:00 2001 From: Helene Durand Date: Fri, 5 Apr 2024 14:22:37 +0200 Subject: [PATCH] BUG/MINOR: add missing hash-balance-factor for defaults and backend --- go.mod | 4 ++-- go.sum | 8 ++++---- models/backend.go | 3 +++ models/backend_compare.go | 8 ++++++++ models/backend_compare_test.go | 6 ++++-- models/defaults.go | 3 +++ models/defaults_compare.go | 8 ++++++++ models/defaults_compare_test.go | 6 ++++-- specification/build/haproxy_spec.yaml | 6 ++++++ specification/models/configuration/backend.yaml | 3 +++ specification/models/configuration/defaults.yaml | 3 +++ test/configuration_test.go | 2 ++ test/expected/structured.json | 2 ++ 13 files changed, 52 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index f33b08d1..b4d8e5e2 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/renameio v1.0.1 github.com/google/uuid v1.6.0 - github.com/haproxytech/config-parser/v5 v5.1.1-0.20240326140233-2ebfd8254626 + github.com/haproxytech/config-parser/v5 v5.1.1-0.20240408103122-267515d6336b github.com/json-iterator/go v1.1.12 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mitchellh/mapstructure v1.5.0 @@ -40,6 +40,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect go.mongodb.org/mongo-driver v1.13.1 // indirect golang.org/x/mod v0.15.0 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/sys v0.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 77082b5f..957a2284 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/haproxytech/config-parser/v5 v5.1.1-0.20240326140233-2ebfd8254626 h1:fDNM12Gd7IKzxtFxTTMWPMfnVvOuJmLuKDHA+Gs9oHY= -github.com/haproxytech/config-parser/v5 v5.1.1-0.20240326140233-2ebfd8254626/go.mod h1:dtksMYl/vyh+6M6Bkwx9d5Mvz0jVNR4AHPJoyfscPFA= +github.com/haproxytech/config-parser/v5 v5.1.1-0.20240408103122-267515d6336b h1:7mp51CTK3V+D7c7CInseuMBhFSaQU0mf2gs8z0pzZbU= +github.com/haproxytech/config-parser/v5 v5.1.1-0.20240408103122-267515d6336b/go.mod h1:T2iWRfXW84pxyk3PlYresm1ntHodIWgBN6ZxzB5Yqow= github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE= github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -102,8 +102,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/models/backend.go b/models/backend.go index 9fff154e..b9c1ada8 100644 --- a/models/backend.go +++ b/models/backend.go @@ -150,6 +150,9 @@ type Backend struct { // +kubebuilder:validation:Enum=enabled;disabled; H1CaseAdjustBogusServer string `json:"h1_case_adjust_bogus_server,omitempty"` + // hash balance factor + HashBalanceFactor *int64 `json:"hash_balance_factor,omitempty"` + // hash type HashType *HashType `json:"hash_type,omitempty"` diff --git a/models/backend_compare.go b/models/backend_compare.go index 76a3a5a5..700b66c2 100644 --- a/models/backend_compare.go +++ b/models/backend_compare.go @@ -327,6 +327,10 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } + if !equalPointers(s.HashBalanceFactor, t.HashBalanceFactor) { + return false + } + if s.HashType == nil || t.HashType == nil { if s.HashType != nil || t.HashType != nil { if opt.NilSameAsEmpty { @@ -1117,6 +1121,10 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["H1CaseAdjustBogusServer"] = []interface{}{s.H1CaseAdjustBogusServer, t.H1CaseAdjustBogusServer} } + if !equalPointers(s.HashBalanceFactor, t.HashBalanceFactor) { + diff["HashBalanceFactor"] = []interface{}{ValueOrNil(s.HashBalanceFactor), ValueOrNil(t.HashBalanceFactor)} + } + if s.HashType == nil || t.HashType == nil { if s.HashType != nil || t.HashType != nil { if opt.NilSameAsEmpty { diff --git a/models/backend_compare_test.go b/models/backend_compare_test.go index 75ddfac0..29ba60a9 100644 --- a/models/backend_compare_test.go +++ b/models/backend_compare_test.go @@ -88,6 +88,7 @@ func TestBackendEqualFalse(t *testing.T) { result.Disabled = !sample.Disabled result.Enabled = !sample.Enabled result.Fullconn = Ptr(*sample.Fullconn + 1) + result.HashBalanceFactor = Ptr(*sample.HashBalanceFactor + 1) result.HTTPKeepAliveTimeout = Ptr(*sample.HTTPKeepAliveTimeout + 1) result.HTTPRequestTimeout = Ptr(*sample.HTTPRequestTimeout + 1) result.ID = Ptr(*sample.ID + 1) @@ -185,6 +186,7 @@ func TestBackendDiffFalse(t *testing.T) { result.Disabled = !sample.Disabled result.Enabled = !sample.Enabled result.Fullconn = Ptr(*sample.Fullconn + 1) + result.HashBalanceFactor = Ptr(*sample.HashBalanceFactor + 1) result.HTTPKeepAliveTimeout = Ptr(*sample.HTTPKeepAliveTimeout + 1) result.HTTPRequestTimeout = Ptr(*sample.HTTPRequestTimeout + 1) result.ID = Ptr(*sample.ID + 1) @@ -205,7 +207,7 @@ func TestBackendDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 87 { + if len(result) != 88 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -215,7 +217,7 @@ func TestBackendDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected Backend to be different in 87 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected Backend to be different in 88 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/defaults.go b/models/defaults.go index af20956e..7eb8f079 100644 --- a/models/defaults.go +++ b/models/defaults.go @@ -207,6 +207,9 @@ type Defaults struct { // +kubebuilder:validation:Enum=enabled;disabled; H1CaseAdjustBogusServer string `json:"h1_case_adjust_bogus_server,omitempty"` + // hash balance factor + HashBalanceFactor *int64 `json:"hash_balance_factor,omitempty"` + // hash type HashType *HashType `json:"hash_type,omitempty"` diff --git a/models/defaults_compare.go b/models/defaults_compare.go index 5089cb4d..eace265a 100644 --- a/models/defaults_compare.go +++ b/models/defaults_compare.go @@ -365,6 +365,10 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } + if !equalPointers(s.HashBalanceFactor, t.HashBalanceFactor) { + return false + } + if s.HashType == nil || t.HashType == nil { if s.HashType != nil || t.HashType != nil { if opt.NilSameAsEmpty { @@ -1181,6 +1185,10 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["H1CaseAdjustBogusServer"] = []interface{}{s.H1CaseAdjustBogusServer, t.H1CaseAdjustBogusServer} } + if !equalPointers(s.HashBalanceFactor, t.HashBalanceFactor) { + diff["HashBalanceFactor"] = []interface{}{ValueOrNil(s.HashBalanceFactor), ValueOrNil(t.HashBalanceFactor)} + } + if s.HashType == nil || t.HashType == nil { if s.HashType != nil || t.HashType != nil { if opt.NilSameAsEmpty { diff --git a/models/defaults_compare_test.go b/models/defaults_compare_test.go index 944b03c1..21d32733 100644 --- a/models/defaults_compare_test.go +++ b/models/defaults_compare_test.go @@ -95,6 +95,7 @@ func TestDefaultsEqualFalse(t *testing.T) { result.Disabled = !sample.Disabled result.Enabled = !sample.Enabled result.Fullconn = Ptr(*sample.Fullconn + 1) + result.HashBalanceFactor = Ptr(*sample.HashBalanceFactor + 1) result.HTTPKeepAliveTimeout = Ptr(*sample.HTTPKeepAliveTimeout + 1) result.HTTPRequestTimeout = Ptr(*sample.HTTPRequestTimeout + 1) result.Httplog = !sample.Httplog @@ -201,6 +202,7 @@ func TestDefaultsDiffFalse(t *testing.T) { result.Disabled = !sample.Disabled result.Enabled = !sample.Enabled result.Fullconn = Ptr(*sample.Fullconn + 1) + result.HashBalanceFactor = Ptr(*sample.HashBalanceFactor + 1) result.HTTPKeepAliveTimeout = Ptr(*sample.HTTPKeepAliveTimeout + 1) result.HTTPRequestTimeout = Ptr(*sample.HTTPRequestTimeout + 1) result.Httplog = !sample.Httplog @@ -223,7 +225,7 @@ func TestDefaultsDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 107 { + if len(result) != 108 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -233,7 +235,7 @@ func TestDefaultsDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected Defaults to be different in 107 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected Defaults to be different in 108 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index 62e011bc..d91260ef 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -2126,6 +2126,9 @@ definitions: - disabled type: string x-display-name: H1 Adjust Bogus Server + hash_balance_factor: + type: integer + x-nullable: true hash_type: $ref: '#/definitions/hash_type' http-buffer-request: @@ -2906,6 +2909,9 @@ definitions: mode: value: http x-display-name: H1 Adjust Bogus Server + hash_balance_factor: + type: integer + x-nullable: true hash_type: $ref: '#/definitions/hash_type' http-buffer-request: diff --git a/specification/models/configuration/backend.yaml b/specification/models/configuration/backend.yaml index 5f4e3531..c9e774a7 100644 --- a/specification/models/configuration/backend.yaml +++ b/specification/models/configuration/backend.yaml @@ -19,6 +19,9 @@ backend: $ref: "#/definitions/persist_rule" hash_type: $ref: "#/definitions/hash_type" + hash_balance_factor: + type: integer + x-nullable: true http-check: $ref: "#/definitions/http_check" bind_process: diff --git a/specification/models/configuration/defaults.yaml b/specification/models/configuration/defaults.yaml index f969115a..535b1eda 100644 --- a/specification/models/configuration/defaults.yaml +++ b/specification/models/configuration/defaults.yaml @@ -17,6 +17,9 @@ defaults: $ref: "#/definitions/balance" hash_type: $ref: "#/definitions/hash_type" + hash_balance_factor: + type: integer + x-nullable: true persist_rule: $ref: "#/definitions/persist_rule" maxconn: diff --git a/test/configuration_test.go b/test/configuration_test.go index d0b20c39..ce540c47 100644 --- a/test/configuration_test.go +++ b/test/configuration_test.go @@ -254,6 +254,7 @@ defaults test_defaults mode http bind-process 1-4 balance roundrobin + hash-balance-factor 150 defaults test_defaults_2 from test_defaults option srvtcpka @@ -637,6 +638,7 @@ backend test balance roundrobin bind-process all hash-type consistent sdbm avalanche + hash-balance-factor 150 log-tag bla option http-keep-alive option forwardfor header X-Forwarded-For diff --git a/test/expected/structured.json b/test/expected/structured.json index 95841c2c..cf465b01 100644 --- a/test/expected/structured.json +++ b/test/expected/structured.json @@ -457,6 +457,7 @@ "method": "consistent", "modifier": "avalanche" }, + "hash_balance_factor": 150, "http-check": { "index": 0, "type": "connect" @@ -2963,6 +2964,7 @@ "algorithm": "roundrobin" }, "bind_process": "1-4", + "hash_balance_factor": 150, "maxconn": 2000, "mode": "http", "name": "test_defaults"