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 <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2024-10-01 11:45:20 +02:00
parent 88b964fe18
commit 611e5d920e

View File

@ -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