From 31501b79b2d47a0a2881f3be76a7767cd2af5eb9 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Fri, 22 Feb 2019 14:33:07 -0700 Subject: [PATCH] when deleting snapshot, don't error if it doesn't exist Signed-off-by: Steve Kriss --- pkg/cloudprovider/azure/block_store.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/cloudprovider/azure/block_store.go b/pkg/cloudprovider/azure/block_store.go index dc5f28133..d9a84c299 100644 --- a/pkg/cloudprovider/azure/block_store.go +++ b/pkg/cloudprovider/azure/block_store.go @@ -269,20 +269,24 @@ func (b *blockStore) DeleteSnapshot(snapshotID string) error { ctx, cancel := context.WithTimeout(context.Background(), b.apiTimeout) defer cancel() + // we don't want to return an error if the snapshot doesn't exist, and + // the Delete(..) call does not return a clear error if that's the case, + // so first try to get it and return early if we get a 404. + _, err = b.snaps.Get(ctx, snapshotInfo.resourceGroup, snapshotInfo.name) + if azureErr, ok := err.(autorest.DetailedError); ok && azureErr.StatusCode == http.StatusNotFound { + b.log.WithField("snapshotID", snapshotID).Debug("Snapshot not found") + return nil + } + future, err := b.snaps.Delete(ctx, snapshotInfo.resourceGroup, snapshotInfo.name) if err != nil { return errors.WithStack(err) } if err = future.WaitForCompletionRef(ctx, b.snaps.Client); err != nil { + b.log.WithError(err).Errorf("Error waiting for completion ref") return errors.WithStack(err) } - _, err = future.Result(*b.snaps) - // if it's a 404 (not found) error, we don't need to return an error - // since the snapshot is not there. - if azureErr, ok := err.(autorest.DetailedError); ok && azureErr.StatusCode == http.StatusNotFound { - return nil - } if err != nil { return errors.WithStack(err) }