From 5ebb6f2856c3778afd4ba582f486a711787d7be1 Mon Sep 17 00:00:00 2001 From: Tanmay Jain Date: Tue, 13 Feb 2024 00:44:47 +0530 Subject: [PATCH] fixing lint --- controllers/pod.go | 54 ++++--------------------------------- go.mod | 2 +- go.sum | 2 ++ test/dynamic_config_test.go | 9 ++++--- 4 files changed, 14 insertions(+), 53 deletions(-) diff --git a/controllers/pod.go b/controllers/pod.go index 172e33116..ec09eb9b9 100644 --- a/controllers/pod.go +++ b/controllers/pod.go @@ -21,7 +21,6 @@ import ( asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1" "github.com/aerospike/aerospike-kubernetes-operator/pkg/jsonpatch" "github.com/aerospike/aerospike-kubernetes-operator/pkg/utils" - lib "github.com/aerospike/aerospike-management-lib" "github.com/aerospike/aerospike-management-lib/asconfig" libcommons "github.com/aerospike/aerospike-management-lib/commons" ) @@ -1321,61 +1320,18 @@ func (r *SingleClusterReconciler) handleDynamicConfigChange(rackState *RackState return specToStatusDiffs, nil } -func toPlural(k string, v any, m configMap) { - // convert asconfig fields/contexts that need to be plural - // in order to create valid asconfig yaml. - if plural := asconfig.PluralOf(k); plural != k { - // if the config item can be plural or singular and is not a slice - // then the item should not be converted to the plural form. - // If the management lib ever parses list entries as anything other - // than []string this might have to change. - if isListOrString(k) { - if _, ok := v.([]string); !ok { - return - } - - if len(v.([]string)) == 1 { - // the management lib parses all config fields - // that are in singularToPlural as lists. If these - // fields are actually scalars then overwrite the list - // with the single value - m[k] = v.([]string)[0] - return - } - } - - delete(m, k) - m[plural] = v - } -} - -// isListOrString returns true for special config fields that may be a -// single string value or a list with multiple strings in the schema files -// NOTE: any time the schema changes to make a value -// a string or a list (array) that value needs to be added here -func isListOrString(name string) bool { - switch name { - case "feature-key-file", "tls-authenticate-client": - return true - default: - return false - } -} - -type configMap = lib.Stats - // mapping functions get mapped to each key value pair in a management lib Stats map // m is the map that k and v came from -type mapping func(k string, v any, m configMap) +type mapping func(k string, v any, m asconfig.Conf) // mutateMap maps functions to each key value pair in the management lib's Stats map // the functions are applied sequentially to each k,v pair. -func mutateMap(in configMap, funcs []mapping) { +func mutateMap(in asconfig.Conf, funcs []mapping) { for k, v := range in { switch v := v.(type) { - case configMap: + case asconfig.Conf: mutateMap(v, funcs) - case []configMap: + case []asconfig.Conf: for _, lv := range v { mutateMap(lv, funcs) } @@ -1396,7 +1352,7 @@ func getFlatConfig(log logger, confStr string) (*asconfig.Conf, error) { cmap := *asConf.ToMap() mutateMap(cmap, []mapping{ - toPlural, + asconfig.ToPlural, }) asConf, err = asconfig.NewMapAsConfig( diff --git a/go.mod b/go.mod index 731ba75bf..b5c96c706 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/aerospike/aerospike-client-go/v6 v6.14.0 - github.com/aerospike/aerospike-management-lib v1.2.1-0.20240212090410-ceae9d0d0462 + github.com/aerospike/aerospike-management-lib v1.2.1-0.20240212190343-4526f5f309b2 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v4.12.0+incompatible github.com/go-logr/logr v1.3.0 diff --git a/go.sum b/go.sum index 0aafbdc39..d230ccc70 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/aerospike/aerospike-management-lib v1.2.1-0.20240129073609-fa537ce5d0 github.com/aerospike/aerospike-management-lib v1.2.1-0.20240129073609-fa537ce5d006/go.mod h1:cSmDG+UbsNt6uTpjdHPfVYvxsHiDh0R+iA5D6vqcLeI= github.com/aerospike/aerospike-management-lib v1.2.1-0.20240212090410-ceae9d0d0462 h1:ANVS9H64iUL70GEYS7VB1LGKRPwMUumk9xsooHfvw2I= github.com/aerospike/aerospike-management-lib v1.2.1-0.20240212090410-ceae9d0d0462/go.mod h1:cSmDG+UbsNt6uTpjdHPfVYvxsHiDh0R+iA5D6vqcLeI= +github.com/aerospike/aerospike-management-lib v1.2.1-0.20240212190343-4526f5f309b2 h1:75mpNdTAZW0hUgY4wg176Y1+87qTFyUmsscl+c7gOOI= +github.com/aerospike/aerospike-management-lib v1.2.1-0.20240212190343-4526f5f309b2/go.mod h1:cSmDG+UbsNt6uTpjdHPfVYvxsHiDh0R+iA5D6vqcLeI= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= diff --git a/test/dynamic_config_test.go b/test/dynamic_config_test.go index 65f85e4a5..3f87ddabc 100644 --- a/test/dynamic_config_test.go +++ b/test/dynamic_config_test.go @@ -111,8 +111,10 @@ var _ = Describe( ) Expect(err).ToNot(HaveOccurred()) - Expect(aeroCluster.Spec.AerospikeConfig.Value["service"].(map[string]interface{})["proto-fd-max"]).To(Equal(float64(18000))) - Expect(aeroCluster.Spec.AerospikeConfig.Value["security"].(map[string]interface{})["log"].(map[string]interface{})["report-data-op"].([]interface{})[0]).To(Equal("test")) + logs := aeroCluster.Spec.AerospikeConfig.Value["security"].(map[string]interface{})["log"] + Expect(aeroCluster.Spec.AerospikeConfig.Value["service"].(map[string]interface{})["proto-fd-max"]). + To(Equal(float64(18000))) + Expect(logs.(map[string]interface{})["report-data-op"].([]interface{})[0]).To(Equal("test")) Expect(aeroCluster.Spec.AerospikeConfig.Value["xdr"].(map[string]interface{})["dcs"]).To(HaveLen(2)) By("Verify no warm/cold restarts in Pods") @@ -176,7 +178,8 @@ var _ = Describe( ) Expect(err).ToNot(HaveOccurred()) - Expect(aeroCluster.Spec.AerospikeConfig.Value["security"].(map[string]interface{})["enable-quotas"]).To(Equal(false)) + Expect(aeroCluster.Spec.AerospikeConfig.Value["security"].(map[string]interface{})["enable-quotas"]). + To(Equal(false)) By("Verify warm restarts in Pods") noRestart, err := verifyNoRestart(ctx, aeroCluster, podPIDMap)