rbd: remove the clone in case of failure

This commit removes the clone incase
unsetAllMetadata or copyEncryptionConfig or
expand fails for createVolumeFromSnapshot
and CreateSnapshot.
It also removes the clone in case of
any failure in createCloneFromImage.

issue: #3103

Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
Yati Padia 2022-06-02 16:31:43 +05:30 committed by mergify[bot]
parent dbbda5473b
commit 5c40f1ef33
2 changed files with 31 additions and 0 deletions

View File

@ -138,6 +138,16 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol
return err
}
defer func() {
if err != nil {
log.DebugLog(ctx, "Removing clone image %q", rv)
errDefer := rv.deleteImage(ctx)
if errDefer != nil {
log.ErrorLog(ctx, "failed to delete clone image %q: %v", rv, errDefer)
}
}
}()
err = rv.getImageID()
if err != nil {
log.ErrorLog(ctx, "failed to get volume id %s: %v", rv, err)

View File

@ -644,6 +644,17 @@ func (cs *ControllerServer) createVolumeFromSnapshot(
return err
}
defer func() {
if err != nil {
log.DebugLog(ctx, "Removing clone image %q", rbdVol)
errDefer := rbdVol.deleteImage(ctx)
if errDefer != nil {
log.ErrorLog(ctx, "failed to delete clone image %q: %v", rbdVol, errDefer)
}
}
}()
err = rbdVol.unsetAllMetadata(k8s.GetSnapshotMetadataKeys())
if err != nil {
log.ErrorLog(ctx, "failed to unset snapshot metadata on rbd image %q: %v", rbdVol, err)
@ -1142,6 +1153,16 @@ func (cs *ControllerServer) CreateSnapshot(
rbdVol.RbdImageName = rbdSnap.RbdSnapName
rbdVol.ClusterName = cs.ClusterName
defer func() {
if err != nil {
log.DebugLog(ctx, "Removing clone image %q", rbdVol)
errDefer := rbdVol.deleteImage(ctx)
if errDefer != nil {
log.ErrorLog(ctx, "failed to delete clone image %q: %v", rbdVol, errDefer)
}
}
}()
err = rbdVol.unsetAllMetadata(k8s.GetVolumeMetadataKeys())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())