mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
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:
parent
dbbda5473b
commit
5c40f1ef33
@ -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)
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user