19127: remove config file support for InstanceTypes specified as an
authorWard Vandewege <ward@curii.com>
Thu, 12 May 2022 18:31:53 +0000 (14:31 -0400)
committerWard Vandewege <ward@curii.com>
Thu, 12 May 2022 23:49:06 +0000 (19:49 -0400)
       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@curii.com>

sdk/go/arvados/config.go
sdk/go/arvados/config_test.go

index 9d77c5cd74b49ca35a92f7d9f331708ecf2d8af6..6a90c30ce4932926840d969de30216fa8495b390 100644 (file)
@@ -528,49 +528,23 @@ type InstanceTypeMap map[string]InstanceType
 
 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
 
 
 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
                }
 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] == '[' {
                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)
        }
        var hash map[string]InstanceType
        err := json.Unmarshal(data, &hash)
index 8c77e292875f23b536edcf8dbdef2a1d4f46d51d..58f4b961bbcc7c9b8945ed2b56ff69b502e1f99c 100644 (file)
@@ -15,7 +15,7 @@ var _ = check.Suite(&ConfigSuite{})
 
 type ConfigSuite struct{}
 
 
 type ConfigSuite struct{}
 
-func (s *ConfigSuite) TestInstanceTypesAsArray(c *check.C) {
+func (s *ConfigSuite) TestStringSetAsArray(c *check.C) {
        var cluster Cluster
        yaml.Unmarshal([]byte(`
 API:
        var cluster Cluster
        yaml.Unmarshal([]byte(`
 API:
@@ -25,13 +25,6 @@ API:
        c.Check(ok, check.Equals, true)
 }
 
        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)
 func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
        var cluster Cluster
        yaml.Unmarshal([]byte("InstanceTypes:\n  foo:\n    ProviderType: bar\n"), &cluster)
@@ -42,18 +35,16 @@ func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
 
 func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
        var it InstanceType
 
 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(err, check.IsNil)
-       c.Check(int64(it.Scratch), check.Equals, int64(4000000000))
+       c.Check(int64(it.IncludedScratch), check.Equals, int64(4000000000))
        c.Check(int64(it.RAM), check.Equals, int64(4294967296))
 }
 
 func (s *ConfigSuite) TestInstanceTypeFixup(c *check.C) {
        for _, confdata := range []string{
                // Current format: map of entries
        c.Check(int64(it.RAM), check.Equals, int64(4294967296))
 }
 
 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
        } {
                c.Log(confdata)
                var itm InstanceTypeMap