From 42bed5a34691379694ba535a745b13b88b045c32 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Fri, 14 Oct 2022 14:46:01 +0200 Subject: [PATCH] rbd: delete volume if setallmetadata fails If any operations fails after the volume creation we will cleanup the omap objects, but it is missing if setAllMetadata fails. This commits adds the code to cleanup the rbd image if metadata operation fails. Signed-off-by: Madhu Rajanna (cherry picked from commit 01d4a614c307188677a3fcec93fd303bbc7cc298) --- internal/rbd/controllerserver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 2814813d1..475caef69 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -384,6 +384,10 @@ func (cs *ControllerServer) CreateVolume( metadata := k8s.GetVolumeMetadata(req.GetParameters()) err = rbdVol.setAllMetadata(metadata) if err != nil { + if deleteErr := rbdVol.deleteImage(ctx); deleteErr != nil { + log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, deleteErr) + } + return nil, err }