diff --git a/pkg/controller/configuration/template_merger.go b/pkg/controller/configuration/template_merger.go index 6d21ebfd814..b26b30a032c 100644 --- a/pkg/controller/configuration/template_merger.go +++ b/pkg/controller/configuration/template_merger.go @@ -94,21 +94,21 @@ func (c *configPatcher) Merge(baseData map[string]string, updatedData map[string return baseData, nil } - r := make(map[string]string) + mergedData := copyMap(baseData) params := core.GenerateVisualizedParamsList(configPatch, formatter, nil) for key, patch := range splitParameters(params) { v, ok := baseData[key] if !ok { - r[key] = updatedData[key] + mergedData[key] = updatedData[key] continue } newConfig, err := core.ApplyConfigPatch([]byte(v), patch, formatter) if err != nil { return nil, err } - r[key] = newConfig + mergedData[key] = newConfig } - return r, err + return mergedData, err } func (c *configReplaceMerger) Merge(baseData map[string]string, updatedData map[string]string) (map[string]string, error) { diff --git a/pkg/controller/configuration/template_merger_test.go b/pkg/controller/configuration/template_merger_test.go index 1ffd8887808..d7776eb8c74 100644 --- a/pkg/controller/configuration/template_merger_test.go +++ b/pkg/controller/configuration/template_merger_test.go @@ -56,6 +56,9 @@ xengine_block_cache_size=307 xengine_row_cache_size=102 max_connections=666 ` + + testString := "// this is a test string" + const ( baseCMName = "base-cm" updatedCMName = "updated-cm" @@ -63,6 +66,7 @@ max_connections=666 testConfigSpecName = "test-config" testClusterName = "test-cluster" testConfigName = "my.cnf" + testConfig2Name = "test.txt" ) var ( @@ -82,12 +86,14 @@ max_connections=666 &appsv1beta1.ConfigConstraint{}) baseCMObject = &corev1.ConfigMap{ Data: map[string]string{ - testConfigName: baseConfig, + testConfigName: baseConfig, + testConfig2Name: testString, }, } updatedCMObject = &corev1.ConfigMap{ Data: map[string]string{ - testConfigName: extendConfig, + testConfigName: extendConfig, + testConfig2Name: testString, }, } baseCMObject.SetName(baseCMName) @@ -101,6 +107,7 @@ max_connections=666 TemplateRef: baseCMObject.GetName(), Namespace: "default", }, + Keys: []string{"my.cnf"}, ConfigConstraintRef: configConstraintObj.GetName(), } @@ -141,6 +148,7 @@ max_connections=666 tmpCM := baseCMObject.DeepCopy() mergedData, err := mergerConfigTemplate(importedTemplate, templateBuilder, configSpec, tmpCM.Data, ctx, mockClient.Client()) Expect(err).To(Succeed()) + Expect(mergedData).Should(HaveLen(2)) configReaders, err := cfgcore.LoadRawConfigObject(mergedData, configConstraintObj.Spec.FileFormatConfig, configSpec.Keys) Expect(err).Should(Succeed()) @@ -169,6 +177,7 @@ max_connections=666 tmpCM := baseCMObject.DeepCopy() mergedData, err := mergerConfigTemplate(importedTemplate, templateBuilder, configSpec, tmpCM.Data, ctx, mockClient.Client()) Expect(err).Should(Succeed()) + Expect(mergedData).Should(HaveLen(2)) Expect(reflect.DeepEqual(mergedData, updatedCMObject.Data)).Should(BeTrue()) configReaders, err := cfgcore.LoadRawConfigObject(mergedData, configConstraintObj.Spec.FileFormatConfig, configSpec.Keys) diff --git a/pkg/controller/configuration/utils.go b/pkg/controller/configuration/utils.go index 0b8a7a3b78b..291637c047d 100644 --- a/pkg/controller/configuration/utils.go +++ b/pkg/controller/configuration/utils.go @@ -30,3 +30,11 @@ func inDataContext() *multicluster.ClientOption { func inDataContextUnspecified() *multicluster.ClientOption { return multicluster.InDataContextUnspecified() } + +func copyMap(data map[string]string) map[string]string { + r := make(map[string]string, len(data)) + for k, v := range data { + r[k] = v + } + return r +}