diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 431280d..dc41d1d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,11 +1,8 @@ name: Tests on: push: - branches-ignore: - - main - pull_request: branches: - - main + - '*' workflow_call: jobs: diff --git a/asconfig/generate.go b/asconfig/generate.go index 1999b70..375595a 100644 --- a/asconfig/generate.go +++ b/asconfig/generate.go @@ -368,7 +368,7 @@ func newFlattenConfStep(log logr.Logger) *flattenConfStep { } } -func sortKeys(config lib.Stats) []string { +func sortKeys(config Conf) []string { keys := make([]string, len(config)) idx := 0 @@ -507,19 +507,6 @@ func disallowedInConfigWhenSC() []string { } } -// sortedKeys returns the sorted keys of a map. -func sortedKeys(m Conf) []string { - keys := make([]string, len(Conf{})) - - for key := range m { - keys = append(keys, key) - } - - sort.Strings(keys) - - return keys -} - // undefinedOrNull checks if a value is undefined or null. func undefinedOrNull(val interface{}) bool { if str, ok := val.(string); ok { @@ -531,7 +518,7 @@ func undefinedOrNull(val interface{}) bool { } // convertIndexedToList converts an indexed key to a list key. It returns the -// new key, the index, and the value as a string. If the key is not indexed or the value is +// new key and the value as a string. If the key is not indexed or the value is // not a string, it returns empty strings. func convertIndexedToList(key string, value interface{}) (newKey, strVal string) { if newKey, _, _ = parseIndexField(key); newKey != "" { @@ -566,7 +553,7 @@ func (s *transformKeyValuesStep) execute(conf Conf) error { origFlatConf := conf[flatConfKey].(Conf) newFlatConf := make(Conf, len(origFlatConf)) // we will overwrite flat_config - sortedKeys := sortedKeys(origFlatConf) + sortedKeys := sortKeys(origFlatConf) scNamspaces := []string{} for _, key := range sortedKeys { @@ -750,7 +737,6 @@ func compareDefaults(log logr.Logger, defVal, confVal interface{}) bool { return defVal == confVal case uint64: - // Schema deals with uint64 when positive but config deals with int switch confVal := confVal.(type) { case int64: if confVal < 0 { @@ -760,9 +746,10 @@ func compareDefaults(log logr.Logger, defVal, confVal interface{}) bool { return val == uint64(confVal) case uint64: return val == confVal + default: + log.V(-1).Info("Unexpected type when comparing default (%s) to config value (%s)", val, confVal) } case int64: - // Schema deals with int64 when negative but config deals with int switch confVal := confVal.(type) { case uint64: if val < 0 { diff --git a/asconfig/schema.go b/asconfig/schema.go index 832996f..3b01998 100644 --- a/asconfig/schema.go +++ b/asconfig/schema.go @@ -165,7 +165,7 @@ func getDynamicSchema(flatSchema map[string]interface{}) map[string]bool { return dynMap } -// getDefaultSchema return the map of values which are dynamic +// getDefaultSchema return the map of values which are default // values. func getDefaultSchema(flatSchema map[string]interface{}) map[string]interface{} { defMap := make(map[string]interface{}) diff --git a/info/as_parser.go b/info/as_parser.go index 4ee8acb..f38b6a5 100644 --- a/info/as_parser.go +++ b/info/as_parser.go @@ -189,7 +189,7 @@ func (info *AsInfo) AllConfigs() (lib.Stats, error) { values, err := info.GetAsInfo(key) if err != nil { - return nil, fmt.Errorf("failed to get config info from node: %v", err) + return nil, fmt.Errorf("failed to get config info from node: %w", err) } configs, ok := values[key].(lib.Stats) @@ -252,7 +252,7 @@ func (info *AsInfo) doInfo(commands ...string) (map[string]string, error) { if err == io.EOF { // Peer closed connection. info.conn.Close() - return nil, fmt.Errorf("connection reset: %v", err) + return nil, fmt.Errorf("connection reset: %w", err) } // FIXME: timeout is also closing connection info.conn.Close() @@ -289,7 +289,7 @@ func (info *AsInfo) GetAsInfo(cmdList ...string) (NodeAsStats, error) { // statNSNames, statDCNames, statSIndex, statLogIDS m, err := info.getCoreInfo() if err != nil { - return nil, fmt.Errorf("failed to get basic ns/dc/sindex info: %v", err) + return nil, fmt.Errorf("failed to get basic ns/dc/sindex info: %w", err) } if len(cmdList) == 0 { @@ -298,7 +298,7 @@ func (info *AsInfo) GetAsInfo(cmdList ...string) (NodeAsStats, error) { rawCmdList, err := info.createCmdList(m, cmdList...) if err != nil { - return nil, fmt.Errorf("failed to create cmd list: %v", err) + return nil, fmt.Errorf("failed to create cmd list: %w", err) } return info.execute(info.log, rawCmdList, m, cmdList...) @@ -311,7 +311,7 @@ func (info *AsInfo) GetAsConfig(contextList ...string) (lib.Stats, error) { // statNSNames, statDCNames, statSIndex, statLogIDS m, err := info.getCoreInfo() if err != nil { - return nil, fmt.Errorf("failed to get basic ns/dc/sindex info: %v", err) + return nil, fmt.Errorf("failed to get basic ns/dc/sindex info: %w", err) } if len(contextList) == 0 { @@ -325,7 +325,7 @@ func (info *AsInfo) GetAsConfig(contextList ...string) (lib.Stats, error) { rawCmdList, err := info.createConfigCmdList(m, contextList...) if err != nil { - return nil, fmt.Errorf("failed to create config cmd list: %v", err) + return nil, fmt.Errorf("failed to create config cmd list: %w", err) } key := constConfigs @@ -333,7 +333,7 @@ func (info *AsInfo) GetAsConfig(contextList ...string) (lib.Stats, error) { if err != nil { return nil, fmt.Errorf( - "failed to get config info from aerospike server: %v", err, + "failed to get config info from aerospike server: %w", err, ) } @@ -1633,34 +1633,3 @@ func contains(list []string, str string) bool { return false } - -// func compareBuilds(a string, b string) int { -// aSplit := strings.Split(a, ".") -// bSplit := strings.Split(b, ".") -// maxLen := len(bSplit) - -// if len(aSplit) > len(bSplit) { -// maxLen = len(aSplit) -// } - -// for i := len(aSplit); i < maxLen; i++ { -// aSplit = append(aSplit, "0") -// } - -// for i := len(bSplit); i < maxLen; i++ { -// bSplit = append(bSplit, "0") -// } - -// for i := 0; i < maxLen; i++ { -// a_val, _ := strconv.Atoi(aSplit[i]) -// b_val, _ := strconv.Atoi(bSplit[i]) - -// if a_val < b_val { -// return -1 -// } else if b_val > a_val { -// return 1 -// } -// } - -// return 0 -// }