Skip to content

Commit

Permalink
fixing lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Feb 12, 2024
1 parent 05ffaef commit 5ebb6f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 53 deletions.
54 changes: 5 additions & 49 deletions controllers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 6 additions & 3 deletions test/dynamic_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5ebb6f2

Please sign in to comment.