[ARVADOS] created: 2.1.0-1870-ge414e9d90

Git user git at public.arvados.org
Wed Feb 2 22:03:18 UTC 2022


        at  e414e9d90df8756ab4fc9dab4d2a5729a51a525c (commit)


commit e414e9d90df8756ab4fc9dab4d2a5729a51a525c
Author: Ward Vandewege <ward at curii.com>
Date:   Wed Feb 2 17:02:43 2022 -0500

    18679: if a config file contains a key with a null value, do not
           override the default value for that key.
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>

diff --git a/lib/config/load.go b/lib/config/load.go
index b4a34335b..c2eb55554 100644
--- a/lib/config/load.go
+++ b/lib/config/load.go
@@ -230,6 +230,9 @@ func (ldr *Loader) Load() (*arvados.Config, error) {
 	}
 	ldr.logExtraKeys(merged, src, "")
 	removeSampleKeys(merged)
+	// We merge the loaded config into the default, overriding any existing keys.
+	// Make sure we do not override a default with a key that has a 'null' value.
+	removeNullKeys(src)
 	err = mergo.Merge(&merged, src, mergo.WithOverride)
 	if err != nil {
 		return nil, fmt.Errorf("merging config data: %s", err)
@@ -435,6 +438,17 @@ func checkKeyConflict(label string, m map[string]string) error {
 	return nil
 }
 
+func removeNullKeys(m map[string]interface{}) {
+	for k, v := range m {
+		if v == nil {
+			delete(m, k)
+		}
+		if v, _ := v.(map[string]interface{}); v != nil {
+			removeNullKeys(v)
+		}
+	}
+}
+
 func removeSampleKeys(m map[string]interface{}) {
 	delete(m, "SAMPLE")
 	for _, v := range m {
diff --git a/lib/config/load_test.go b/lib/config/load_test.go
index d4896c39c..1ede805b0 100644
--- a/lib/config/load_test.go
+++ b/lib/config/load_test.go
@@ -71,6 +71,18 @@ func (s *LoadSuite) TestNoConfigs(c *check.C) {
 	c.Check(cc.API.MaxItemsPerResponse, check.Equals, 1000)
 }
 
+func (s *LoadSuite) TestNullKeyDoesNotOverrideDefault(c *check.C) {
+	ldr := testLoader(c, `{"Clusters":{"z1111":{"API":}}}`, nil)
+	ldr.SkipDeprecated = true
+	cfg, err := ldr.Load()
+	c.Assert(err, check.IsNil)
+	c1, err := cfg.GetCluster("z1111")
+	c.Assert(err, check.IsNil)
+	c.Check(c1.ClusterID, check.Equals, "z1111")
+	c.Check(c1.API.MaxRequestAmplification, check.Equals, 4)
+	c.Check(c1.API.MaxItemsPerResponse, check.Equals, 1000)
+}
+
 func (s *LoadSuite) TestMungeLegacyConfigArgs(c *check.C) {
 	f, err := ioutil.TempFile("", "")
 	c.Check(err, check.IsNil)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list