Skip to content

Commit

Permalink
Azure now powers off VM before deletion
Browse files Browse the repository at this point in the history
- Azure VM deletion takes too long when a running VM is deleted
- As suggested by team Azure, Stopping (Powering off) the VM before deletion should help this process
  • Loading branch information
prashanth26 committed Dec 24, 2018
1 parent c5c9bac commit 04fa1b3
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/driver/driver_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (d *AzureDriver) Create() (string, string, error) {
Name: &nicName,
InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAllocationMethod: network.Dynamic,
Subnet: &subnet,
Subnet: &subnet,
},
},
},
Expand Down Expand Up @@ -218,13 +218,24 @@ func (d *AzureDriver) Delete() error {
listOfResources := make(map[string]string)
d.getvms(d.MachineID, listOfResources)
if len(listOfResources) != 0 {
_, errChan := vmClient.Delete(resourceGroup, vmName, cancel)

_, errChan := vmClient.PowerOff(resourceGroup, vmName, cancel)
err = onErrorFail(<-errChan, fmt.Sprintf("vmClient.PowerOff failed for '%s'", vmName))
if err != nil {
return err
}
glog.V(2).Infof("VM poweroff was successful for %s", vmName)

_, errChan = vmClient.Delete(resourceGroup, vmName, cancel)
err = onErrorFail(<-errChan, fmt.Sprintf("vmClient.Delete failed for '%s'", vmName))
if err != nil {
return err
}
glog.V(2).Infof("VM deletion was successful for %s", vmName)

} else {
glog.Warningf("VM was not found for %s", vmName)
}
glog.V(3).Infof("Deleted VM %s", vmName)

listOfResources = make(map[string]string)
d.getnics(d.MachineID, listOfResources)
Expand All @@ -234,8 +245,10 @@ func (d *AzureDriver) Delete() error {
if err != nil {
return err
}
glog.V(2).Infof("NIC deletion was successful for %s", vmName)
} else {
glog.Warningf("NIC was not found for %s", vmName)
}
glog.V(3).Infof("Deleted NIC %s", nicName)

listOfResources = make(map[string]string)
d.getdisks(d.MachineID, listOfResources)
Expand All @@ -245,8 +258,10 @@ func (d *AzureDriver) Delete() error {
if err != nil {
return err
}
glog.V(2).Infof("OS-Disk deletion was successful for %s", vmName)
} else {
glog.Warningf("OS-Disk was not found for %s", vmName)
}
glog.V(3).Infof("Deleted OS-Disk %s", nicName)

return err
}
Expand Down

0 comments on commit 04fa1b3

Please sign in to comment.