Skip to content

Commit

Permalink
handle tls-name and node-address-ports ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Mar 25, 2024
1 parent d1f008f commit dbb9f48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
40 changes: 21 additions & 19 deletions asconfig/as_setconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,7 @@ func createSetConfigXDRCmdList(tokens []string, operationValueMap map[Operation]

// example of a command: "set-config:context=xdr;dc=dc1;node-address-port=192.168.55.210:3000;action=add
if prevToken == keyNodeAddressPorts {
val := v

tokens := strings.Split(v, colon)
if len(tokens) >= 2 {
val = tokens[0] + colon + tokens[1]
}

finalCMD = cmd + semicolon + SingularOf(prevToken) + equal + val + semicolon + "action" + equal + string(op)
finalCMD = cmd + semicolon + SingularOf(prevToken) + equal + v + semicolon + "action" + equal + string(op)
} else {
finalCMD = cmd + semicolon + SingularOf(prevToken) + equal + v
}
Expand Down Expand Up @@ -380,8 +373,8 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string {
finalList := make([]string, 0, len(configMap))

var (
lastDC *list.Element // Last DC name
lastNAP *list.Element // Last DC direct field eg. node-address-ports
lastDC *list.Element // Last DC name
lastDCConfig *list.Element // Last DC config eg. node-address-ports
)

for k, v := range configMap {
Expand All @@ -404,14 +397,14 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string {
finalList = append(finalList, k)
} else {
// If namespace is added, add it after all DCs and their direct fields
if lastNAP == nil {
if lastDCConfig == nil {
if lastDC != nil {
rearrangedConfigMap.InsertAfter(k, lastDC)
} else {
rearrangedConfigMap.PushFront(k)
}
} else {
rearrangedConfigMap.InsertAfter(k, lastNAP)
rearrangedConfigMap.InsertAfter(k, lastDCConfig)
}
}
}
Expand All @@ -424,14 +417,23 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string {
// Handle DC direct fields
if tokens[len(tokens)-3] == info.ConfigDCContext {
var nap *list.Element
if lastDC == nil {
nap = rearrangedConfigMap.PushFront(k)
// Check if the key is related to 'node-address-ports'
isNodeAddressPortsKey := strings.HasSuffix(k, sep+keyNodeAddressPorts)

if isNodeAddressPortsKey && lastDCConfig != nil {
// Add 'node-address-ports' after all DC direct fields
// There are certain fields that must be set before 'node-address-ports', for example, 'tls-name'.
lastDCConfig = rearrangedConfigMap.InsertAfter(k, lastDCConfig)
} else {
// Add modified DC direct fields after the DC names and before the namespaces
nap = rearrangedConfigMap.InsertAfter(k, lastDC)
}
if lastNAP == nil {
lastNAP = nap
if lastDC == nil {
nap = rearrangedConfigMap.PushFront(k)
} else {
// Add modified DC direct fields after the DC names and before the namespaces
nap = rearrangedConfigMap.InsertAfter(k, lastDC)
}
if lastDCConfig == nil {
lastDCConfig = nap
}
}
} else {
rearrangedConfigMap.PushBack(k)
Expand Down
6 changes: 4 additions & 2 deletions asconfig/as_setconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdListOrdered() {
"xdr.dcs.{DC1}.namespaces.{ns1}.bin-policy": {Update: "no-bins"},
"xdr.dcs.{DC3}.name": {Add: "DC3"},
"xdr.dcs.{DC1}.namespaces.{ns2}.name": {Remove: "ns2"},
"xdr.dcs.{DC1}.node-address-ports": {Add: []string{"1.1.1.1:3000"}},
"xdr.dcs.{DC1}.node-address-ports": {Add: []string{"1.1.1.1:3000:tls-name"}},
"xdr.dcs.{DC1}.namespaces.{ns1}.name": {Add: "ns1"},
"xdr.dcs.{DC1}.tls-name": {Update: "tls-name"},
},
[]string{"set-config:context=xdr;dc=DC1;namespace=ns2;action=remove",
"set-config:context=xdr;dc=DC3;action=create",
"set-config:context=xdr;dc=DC1;node-address-port=1.1.1.1:3000;action=add",
"set-config:context=xdr;dc=DC1;tls-name=tls-name",
"set-config:context=xdr;dc=DC1;node-address-port=1.1.1.1:3000:tls-name;action=add",
"set-config:context=xdr;dc=DC1;namespace=ns1;action=add",
"set-config:context=xdr;dc=DC1;namespace=ns1;bin-policy=no-bins",
},
Expand Down

0 comments on commit dbb9f48

Please sign in to comment.