16106: add Azure spot instance support.
authorWard Vandewege <ward@curii.com>
Sat, 3 Oct 2020 00:49:22 +0000 (20:49 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 12 Feb 2021 15:22:39 +0000 (10:22 -0500)
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

lib/cloud/azure/azure.go
lib/cloud/azure/azure_test.go

index 7f949d9bdb3e2fb83c539a0df5f15efec6ca2612..ad1f8c532d6a1a8a1630c1c83d35a67aaa8a6d0d 100644 (file)
@@ -491,6 +491,21 @@ func (az *azureInstanceSet) Create(
                }
        }
 
+       priority := compute.Regular
+       evictionPolicy := compute.Deallocate
+       var billingProfile compute.BillingProfile
+       var maxPrice float64
+       if instanceType.Preemptible {
+               priority = compute.Spot
+               evictionPolicy = compute.Delete
+               // Setting maxPrice to -1 is the equivalent of paying spot price, up to the
+               // normal price. This means the node will not be pre-empted for price
+               // reasons. It may still be pre-empted for capacity reasons though. And
+               // Azure offers *no* SLA on spot instances.
+               maxPrice = -1
+               billingProfile = compute.BillingProfile{MaxPrice: &maxPrice}
+       }
+
        vmParameters := compute.VirtualMachine{
                Location: &az.azconfig.Location,
                Tags:     tags,
@@ -499,6 +514,9 @@ func (az *azureInstanceSet) Create(
                                VMSize: compute.VirtualMachineSizeTypes(instanceType.ProviderType),
                        },
                        StorageProfile: storageProfile,
+                       Priority:       priority,
+                       EvictionPolicy: evictionPolicy,
+                       BillingProfile: &billingProfile,
                        NetworkProfile: &compute.NetworkProfile{
                                NetworkInterfaces: &[]compute.NetworkInterfaceReference{
                                        {
index 96d6dca69e451c0802220a884e4978fbb906f447..b6aa9a16b6187b4fd5486037076885fe4eb69d19 100644 (file)
@@ -136,6 +136,15 @@ func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error)
                                Price:        .02,
                                Preemptible:  false,
                        },
+                       "tinyp": {
+                               Name:         "tiny",
+                               ProviderType: "Standard_D1_v2",
+                               VCPUs:        1,
+                               RAM:          4000000000,
+                               Scratch:      10000000000,
+                               Price:        .002,
+                               Preemptible:  true,
+                       },
                })}
        if *live != "" {
                var exampleCfg testConfig
@@ -185,6 +194,17 @@ func (*AzureInstanceSetSuite) TestCreate(c *check.C) {
        c.Check(tags["TestTagName"], check.Equals, "test tag value")
        c.Logf("inst.String()=%v Address()=%v Tags()=%v", inst.String(), inst.Address(), tags)
 
+       instPreemptable, err := ap.Create(cluster.InstanceTypes["tinyp"],
+               img, map[string]string{
+                       "TestTagName": "test tag value",
+               }, "umask 0600; echo -n test-file-data >/var/run/test-file", pk)
+
+       c.Assert(err, check.IsNil)
+
+       tags = instPreemptable.Tags()
+       c.Check(tags["TestTagName"], check.Equals, "test tag value")
+       c.Logf("instPreemptable.String()=%v Address()=%v Tags()=%v", instPreemptable.String(), instPreemptable.Address(), tags)
+
 }
 
 func (*AzureInstanceSetSuite) TestListInstances(c *check.C) {