Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

fix: deleting a VM in failed provisioning state #1824

Merged
merged 2 commits into from
Nov 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions pkg/operations/deletevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ func CleanDeleteVirtualMachine(az armhelpers.ACSEngineClient, logger *log.Entry,

osDiskName := vm.VirtualMachineProperties.StorageProfile.OsDisk.Name

var nicName string
nicID := (*vm.VirtualMachineProperties.NetworkProfile.NetworkInterfaces)[0].ID
nicName, err := armhelpers.ResourceName(*nicID)
if err != nil {
return err
if nicID == nil {
logger.Warnf("NIC ID is not set for VM (%s/%s)", resourceGroup, name)
} else {
nicName, err = armhelpers.ResourceName(*nicID)
if err != nil {
return err
}
logger.Infof("found nic name for VM (%s/%s): %s", resourceGroup, name, nicName)
}

logger.Infof("found nic name for VM (%s/%s): %s", resourceGroup, name, nicName)

logger.Infof("deleting VM: %s/%s", resourceGroup, name)
_, deleteErrChan := az.DeleteVirtualMachine(resourceGroup, name, nil)

Expand All @@ -42,12 +45,14 @@ func CleanDeleteVirtualMachine(az armhelpers.ACSEngineClient, logger *log.Entry,
return err
}

logger.Infof("deleting nic: %s/%s", resourceGroup, nicName)
_, nicErrChan := az.DeleteNetworkInterface(resourceGroup, nicName, nil)
if len(nicName) > 0 {
logger.Infof("deleting nic: %s/%s", resourceGroup, nicName)
_, nicErrChan := az.DeleteNetworkInterface(resourceGroup, nicName, nil)

logger.Infof("waiting for nic deletion: %s/%s", resourceGroup, nicName)
if nicErr := <-nicErrChan; nicErr != nil {
return nicErr
logger.Infof("waiting for nic deletion: %s/%s", resourceGroup, nicName)
if nicErr := <-nicErrChan; nicErr != nil {
return nicErr
}
}

if vhd != nil {
Expand All @@ -68,11 +73,15 @@ func CleanDeleteVirtualMachine(az armhelpers.ACSEngineClient, logger *log.Entry,
return err
}
} else if managedDisk != nil {
logger.Infof("deleting managed disk: %s/%s", resourceGroup, *osDiskName)
_, diskErrChan := az.DeleteManagedDisk(resourceGroup, *osDiskName, nil)

if err := <-diskErrChan; err != nil {
return err
if osDiskName == nil {
logger.Warnf("osDisk is not set for VM %s/%s", resourceGroup, name)
} else {
logger.Infof("deleting managed disk: %s/%s", resourceGroup, *osDiskName)
_, diskErrChan := az.DeleteManagedDisk(resourceGroup, *osDiskName, nil)

if err := <-diskErrChan; err != nil {
return err
}
}
}

Expand Down