From 611e5d920e1623a2f58e2eff8bbb15cb3c21213d Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 1 Oct 2024 11:45:20 +0200 Subject: [PATCH] rbd: do not return an error when deleting a non-existing image Deleting an image that has been already remove, should not be reported as a failure. This improves the idempotency of the `rbdImage.Delete()` function, making it easier for callers to detect real errors. Signed-off-by: Niels de Vos --- internal/rbd/rbd_util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 3b07d235d..18585bd17 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -671,7 +671,7 @@ func (ri *rbdImage) Delete(ctx context.Context) error { rbdImage := librbd.GetImage(ri.ioctx, image) err = rbdImage.Trash(0) - if err != nil { + if err != nil && !errors.Is(err, librbd.ErrNotFound) { log.ErrorLog(ctx, "failed to delete rbd image: %s, error: %v", ri, err) return err @@ -694,7 +694,7 @@ func (ri *rbdImage) trashRemoveImage(ctx context.Context) error { _, err = ta.AddTrashRemove(admin.NewImageSpec(ri.Pool, ri.RadosNamespace, ri.ImageID)) rbdCephMgrSupported := isCephMgrSupported(ctx, ri.ClusterID, err) - if rbdCephMgrSupported && err != nil { + if rbdCephMgrSupported && err != nil && !errors.Is(err, librbd.ErrNotFound) { log.ErrorLog(ctx, "failed to add task to delete rbd image: %s, %v", ri, err) return err