Skip to content

Commit

Permalink
rbd: do not return an error when deleting a non-existing image
Browse files Browse the repository at this point in the history
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 <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Oct 3, 2024
1 parent 88b964f commit 611e5d9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 611e5d9

Please sign in to comment.