From 18ad20f1c52410f2c34af5f64e9f2f141ee6cbb6 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 9 Sep 2020 10:26:30 +0200 Subject: [PATCH] Display errors if resource not found when deleting volumes (file share or storage account) Signed-off-by: Guillaume Tardif --- aci/volumes.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/aci/volumes.go b/aci/volumes.go index 87791923..df7ab108 100644 --- a/aci/volumes.go +++ b/aci/volumes.go @@ -152,7 +152,6 @@ func (cs *aciVolumeService) Create(ctx context.Context, options interface{}) (vo w.Event(errorEvent(opts.Fileshare)) return volumes.Volume{}, err } - //TODO tag fileshare fileShare, err = fileShareClient.Create(ctx, cs.aciContext.ResourceGroup, *account.Name, opts.Fileshare, storage.FileShare{}) if err != nil { w.Event(errorEvent(opts.Fileshare)) @@ -185,14 +184,16 @@ func (cs *aciVolumeService) Delete(ctx context.Context, options interface{}) err } if opts.DeleteAccount { //TODO check if there are other fileshares on this account - //TODO flag account and only delete ours? - //TODO error when not found storageAccountsClient, err := login.NewStorageAccountsClient(cs.aciContext.SubscriptionID) if err != nil { return err } - _, err = storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account) + result, err := storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account) + if result.StatusCode == 204 { + return errors.Wrapf(errdefs.ErrNotFound, "storage account %s does not exist", opts.Account) + } + return err } @@ -201,7 +202,13 @@ func (cs *aciVolumeService) Delete(ctx context.Context, options interface{}) err return err } - _, err = fileShareClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account, opts.Fileshare) + result, err := fileShareClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account, opts.Fileshare) + if result.StatusCode == 204 { + return errors.Wrapf(errdefs.ErrNotFound, "fileshare %s does not exist", opts.Fileshare) + } + if result.StatusCode == 404 { + return errors.Wrapf(errdefs.ErrNotFound, "storage account %s does not exist", opts.Account) + } return err }