Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Dec 13, 2023
1 parent 707d2e3 commit b0a6905
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 61 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: Tests
on:
push:
branches-ignore:
- main
pull_request:
branches:
- main
- '*'
workflow_call:

jobs:
Expand Down
23 changes: 5 additions & 18 deletions asconfig/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion asconfig/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
45 changes: 7 additions & 38 deletions info/as_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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...)
Expand All @@ -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 {
Expand All @@ -325,15 +325,15 @@ 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
configs, err := info.execute(info.log, rawCmdList, m, key)

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,
)
}

Expand Down Expand Up @@ -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
// }

0 comments on commit b0a6905

Please sign in to comment.