From b83fb5b6114eb25a47c1553e37987d5e893184dd Mon Sep 17 00:00:00 2001 From: Dmitry Shmulevich Date: Thu, 23 Nov 2017 10:26:42 -0800 Subject: [PATCH 1/2] confirm existence of OS disk prior to deleting --- pkg/operations/deletevm.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/operations/deletevm.go b/pkg/operations/deletevm.go index 610f20819c..f958056bee 100644 --- a/pkg/operations/deletevm.go +++ b/pkg/operations/deletevm.go @@ -68,11 +68,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 + } } } From ba7b11d356fea99428387161d146ed969fef2ced Mon Sep 17 00:00:00 2001 From: Dmitry Shmulevich Date: Thu, 23 Nov 2017 10:42:30 -0800 Subject: [PATCH 2/2] cconfirm valid nic id before deleting --- pkg/operations/deletevm.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/operations/deletevm.go b/pkg/operations/deletevm.go index f958056bee..88394ba396 100644 --- a/pkg/operations/deletevm.go +++ b/pkg/operations/deletevm.go @@ -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) @@ -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 {