diff --git a/asconfig/as_setconfig.go b/asconfig/as_setconfig.go index 3f2b1b2..0fa0468 100644 --- a/asconfig/as_setconfig.go +++ b/asconfig/as_setconfig.go @@ -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 } @@ -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 { @@ -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) } } } @@ -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) diff --git a/asconfig/as_setconfig_test.go b/asconfig/as_setconfig_test.go index 937de8b..8f7dbb0 100644 --- a/asconfig/as_setconfig_test.go +++ b/asconfig/as_setconfig_test.go @@ -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", },