X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8c4fb97b1d34b5f8fc50d239698a08c35a63dac3..0b471c74f2cc392a37aa4f8df8ed931bb5969236:/lib/cloud/azure/azure.go diff --git a/lib/cloud/azure/azure.go b/lib/cloud/azure/azure.go index b88962714e..ab14d6681e 100644 --- a/lib/cloud/azure/azure.go +++ b/lib/cloud/azure/azure.go @@ -50,8 +50,6 @@ type azureInstanceSetConfig struct { AdminUsername string } -const tagKeyInstanceSecret = "InstanceSecret" - type containerWrapper interface { GetBlobReference(name string) *storage.Blob ListBlobs(params storage.ListBlobsParameters) (storage.BlobListResponse, error) @@ -213,19 +211,21 @@ type azureInstanceSet struct { logger logrus.FieldLogger } -func newAzureInstanceSet(config json.RawMessage, dispatcherID cloud.InstanceSetID, logger logrus.FieldLogger) (prv cloud.InstanceSet, err error) { +func newAzureInstanceSet(config json.RawMessage, dispatcherID cloud.InstanceSetID, _ cloud.SharedResourceTags, logger logrus.FieldLogger) (prv cloud.InstanceSet, err error) { azcfg := azureInstanceSetConfig{} err = json.Unmarshal(config, &azcfg) if err != nil { return nil, err } - ap := azureInstanceSet{logger: logger} - err = ap.setup(azcfg, string(dispatcherID)) + az := azureInstanceSet{logger: logger} + az.ctx, az.stopFunc = context.WithCancel(context.Background()) + err = az.setup(azcfg, string(dispatcherID)) if err != nil { + az.stopFunc() return nil, err } - return &ap, nil + return &az, nil } func (az *azureInstanceSet) setup(azcfg azureInstanceSetConfig, dispatcherID string) (err error) { @@ -276,7 +276,6 @@ func (az *azureInstanceSet) setup(azcfg azureInstanceSetConfig, dispatcherID str az.dispatcherID = dispatcherID az.namePrefix = fmt.Sprintf("compute-%s-", az.dispatcherID) - az.ctx, az.stopFunc = context.WithCancel(context.Background()) go func() { az.stopWg.Add(1) defer az.stopWg.Done() @@ -340,6 +339,10 @@ func (az *azureInstanceSet) Create( az.stopWg.Add(1) defer az.stopWg.Done() + if instanceType.AddedScratch > 0 { + return nil, fmt.Errorf("cannot create instance type %q: driver does not implement non-zero AddedScratch (%d)", instanceType.Name, instanceType.AddedScratch) + } + name, err := randutil.String(15, "abcdefghijklmnopqrstuvwxyz0123456789") if err != nil { return nil, err @@ -347,14 +350,11 @@ func (az *azureInstanceSet) Create( name = az.namePrefix + name - timestamp := time.Now().Format(time.RFC3339Nano) - - tags := make(map[string]*string) - tags["created-at"] = ×tamp + tags := map[string]*string{} for k, v := range newTags { - newstr := v - tags["dispatch-"+k] = &newstr + tags[k] = to.StringPtr(v) } + tags["created-at"] = to.StringPtr(time.Now().Format(time.RFC3339Nano)) nicParameters := network.Interface{ Location: &az.azconfig.Location, @@ -477,26 +477,24 @@ func (az *azureInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, err return nil, wrapAzureError(err) } - instances := make([]cloud.Instance, 0) - + var instances []cloud.Instance for ; result.NotDone(); err = result.Next() { if err != nil { return nil, wrapAzureError(err) } - if strings.HasPrefix(*result.Value().Name, az.namePrefix) { - instances = append(instances, &azureInstance{ - provider: az, - vm: result.Value(), - nic: interfaces[*(*result.Value().NetworkProfile.NetworkInterfaces)[0].ID]}) - } + instances = append(instances, &azureInstance{ + provider: az, + vm: result.Value(), + nic: interfaces[*(*result.Value().NetworkProfile.NetworkInterfaces)[0].ID], + }) } return instances, nil } // ManageNics returns a list of Azure network interface resources. -// Also performs garbage collection of NICs which have "namePrefix", are -// not associated with a virtual machine and have a "create-at" time -// more than DeleteDanglingResourcesAfter (to prevent racing and +// Also performs garbage collection of NICs which have "namePrefix", +// are not associated with a virtual machine and have a "created-at" +// time more than DeleteDanglingResourcesAfter (to prevent racing and // deleting newly created NICs) in the past are deleted. func (az *azureInstanceSet) manageNics() (map[string]network.Interface, error) { az.stopWg.Add(1) @@ -598,16 +596,12 @@ func (ai *azureInstance) SetTags(newTags cloud.InstanceTags) error { ai.provider.stopWg.Add(1) defer ai.provider.stopWg.Done() - tags := make(map[string]*string) - + tags := map[string]*string{} for k, v := range ai.vm.Tags { - if !strings.HasPrefix(k, "dispatch-") { - tags[k] = v - } + tags[k] = v } for k, v := range newTags { - newstr := v - tags["dispatch-"+k] = &newstr + tags[k] = to.StringPtr(v) } vmParameters := compute.VirtualMachine{ @@ -624,14 +618,10 @@ func (ai *azureInstance) SetTags(newTags cloud.InstanceTags) error { } func (ai *azureInstance) Tags() cloud.InstanceTags { - tags := make(map[string]string) - + tags := cloud.InstanceTags{} for k, v := range ai.vm.Tags { - if strings.HasPrefix(k, "dispatch-") { - tags[k[9:]] = *v - } + tags[k] = *v } - return tags } @@ -644,13 +634,17 @@ func (ai *azureInstance) Destroy() error { } func (ai *azureInstance) Address() string { - if ai.nic.IPConfigurations != nil && - len(*ai.nic.IPConfigurations) > 0 && - (*ai.nic.IPConfigurations)[0].PrivateIPAddress != nil { - - return *(*ai.nic.IPConfigurations)[0].PrivateIPAddress + if iprops := ai.nic.InterfacePropertiesFormat; iprops == nil { + return "" + } else if ipconfs := iprops.IPConfigurations; ipconfs == nil || len(*ipconfs) == 0 { + return "" + } else if ipconfprops := (*ipconfs)[0].InterfaceIPConfigurationPropertiesFormat; ipconfprops == nil { + return "" + } else if addr := ipconfprops.PrivateIPAddress; addr == nil { + return "" + } else { + return *addr } - return "" } func (ai *azureInstance) RemoteUser() string {