[ARVADOS] created: 2.1.0-2454-gc10e9d305

Git user git at public.arvados.org
Thu May 12 19:07:03 UTC 2022


        at  c10e9d30588e479da7801f7c60fd2503349534e9 (commit)


commit c10e9d30588e479da7801f7c60fd2503349534e9
Author: Ward Vandewege <ward at curii.com>
Date:   Thu May 12 14:31:53 2022 -0400

    19127: remove config file support for InstanceTypes specified as an
           array (deprecated since Arvados 1.2.0). Remove support for
           InstanceType "Scratch" field from config file (deprecated since
           Arvados 1.4.0).
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>

diff --git a/sdk/go/arvados/config.go b/sdk/go/arvados/config.go
index 9d77c5cd7..6a90c30ce 100644
--- a/sdk/go/arvados/config.go
+++ b/sdk/go/arvados/config.go
@@ -528,49 +528,23 @@ type InstanceTypeMap map[string]InstanceType
 
 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
 
-// UnmarshalJSON handles old config files that provide an array of
-// instance types instead of a hash.
+// UnmarshalJSON does special handling of InstanceTypes:
+// * populate computed fields (Name and Scratch)
+// * error out if InstancesTypes are populated as an array, which was
+//   deprecated in Arvados 1.2.0
 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
 	fixup := func(t InstanceType) (InstanceType, error) {
 		if t.ProviderType == "" {
 			t.ProviderType = t.Name
 		}
-		if t.Scratch == 0 {
-			t.Scratch = t.IncludedScratch + t.AddedScratch
-		} else if t.AddedScratch == 0 {
-			t.AddedScratch = t.Scratch - t.IncludedScratch
-		} else if t.IncludedScratch == 0 {
-			t.IncludedScratch = t.Scratch - t.AddedScratch
-		}
-
-		if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
-			return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
-		}
+		// If t.Scratch is set in the configuration file, it will be ignored and overwritten.
+		// It will also generate a "deprecated or unknown config entry" warning.
+		t.Scratch = t.IncludedScratch + t.AddedScratch
 		return t, nil
 	}
 
 	if len(data) > 0 && data[0] == '[' {
-		var arr []InstanceType
-		err := json.Unmarshal(data, &arr)
-		if err != nil {
-			return err
-		}
-		if len(arr) == 0 {
-			*it = nil
-			return nil
-		}
-		*it = make(map[string]InstanceType, len(arr))
-		for _, t := range arr {
-			if _, ok := (*it)[t.Name]; ok {
-				return errDuplicateInstanceTypeName
-			}
-			t, err := fixup(t)
-			if err != nil {
-				return err
-			}
-			(*it)[t.Name] = t
-		}
-		return nil
+		return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
 	}
 	var hash map[string]InstanceType
 	err := json.Unmarshal(data, &hash)
diff --git a/sdk/go/arvados/config_test.go b/sdk/go/arvados/config_test.go
index 8c77e2928..ba325fd0c 100644
--- a/sdk/go/arvados/config_test.go
+++ b/sdk/go/arvados/config_test.go
@@ -15,7 +15,7 @@ var _ = check.Suite(&ConfigSuite{})
 
 type ConfigSuite struct{}
 
-func (s *ConfigSuite) TestInstanceTypesAsArray(c *check.C) {
+func (s *ConfigSuite) TestStringSetAsArray(c *check.C) {
 	var cluster Cluster
 	yaml.Unmarshal([]byte(`
 API:
@@ -25,13 +25,6 @@ API:
 	c.Check(ok, check.Equals, true)
 }
 
-func (s *ConfigSuite) TestStringSetAsArray(c *check.C) {
-	var cluster Cluster
-	yaml.Unmarshal([]byte("InstanceTypes:\n- Name: foo\n"), &cluster)
-	c.Check(len(cluster.InstanceTypes), check.Equals, 1)
-	c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
-}
-
 func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
 	var cluster Cluster
 	yaml.Unmarshal([]byte("InstanceTypes:\n  foo:\n    ProviderType: bar\n"), &cluster)
@@ -42,7 +35,7 @@ func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
 
 func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
 	var it InstanceType
-	err := yaml.Unmarshal([]byte("Name: foo\nScratch: 4GB\nRAM: 4GiB\n"), &it)
+	err := yaml.Unmarshal([]byte("Name: foo\nIncludedScratch: 4GB\nRAM: 4GiB\n"), &it)
 	c.Check(err, check.IsNil)
 	c.Check(int64(it.Scratch), check.Equals, int64(4000000000))
 	c.Check(int64(it.RAM), check.Equals, int64(4294967296))
@@ -51,9 +44,7 @@ func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
 func (s *ConfigSuite) TestInstanceTypeFixup(c *check.C) {
 	for _, confdata := range []string{
 		// Current format: map of entries
-		`{foo4: {IncludedScratch: 4GB}, foo8: {ProviderType: foo_8, Scratch: 8GB}}`,
-		// Legacy format: array of entries with key in "Name" field
-		`[{Name: foo4, IncludedScratch: 4GB}, {Name: foo8, ProviderType: foo_8, Scratch: 8GB}]`,
+		`{foo4: {IncludedScratch: 4GB}, foo8: {ProviderType: foo_8, AddedScratch: 8GB}}`,
 	} {
 		c.Log(confdata)
 		var itm InstanceTypeMap

commit 2a1924361a836d95fd3a055fd501c96599489547
Author: Tom Clegg <tom at curii.com>
Date:   Wed May 11 19:40:43 2022 -0400

    19127: Update test to catch InstanceTypes computed fields.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/config/load_test.go b/lib/config/load_test.go
index abf321705..4ae9a513c 100644
--- a/lib/config/load_test.go
+++ b/lib/config/load_test.go
@@ -316,7 +316,11 @@ Clusters:
   ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
   SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
   Collections:
-   BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`, &logbuf).Load()
+   BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  InstanceTypes:
+   abc:
+    IncludedScratch: 123456
+`, &logbuf).Load()
 	c.Assert(err, check.IsNil)
 	yaml, err := yaml.Marshal(cfg)
 	c.Assert(err, check.IsNil)

commit fb553cae8d2132a17bc31d06d7b5f95aeebff78a
Author: Ward Vandewege <ward at curii.com>
Date:   Wed May 11 17:03:07 2022 -0400

    19127: do not dump InstanceTypes...Name and InstanceTypes...Scratch,
           they are computed fields.
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>

diff --git a/sdk/go/arvados/config.go b/sdk/go/arvados/config.go
index f0adcda5f..9d77c5cd7 100644
--- a/sdk/go/arvados/config.go
+++ b/sdk/go/arvados/config.go
@@ -424,11 +424,11 @@ type CUDAFeatures struct {
 }
 
 type InstanceType struct {
-	Name            string
+	Name            string `json:"-"`
 	ProviderType    string
 	VCPUs           int
 	RAM             ByteSize
-	Scratch         ByteSize
+	Scratch         ByteSize `json:"-"`
 	IncludedScratch ByteSize
 	AddedScratch    ByteSize
 	Price           float64

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list