mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-25 14:30:22 +00:00
cleanup: refactor deeply nested if statements in internal/cephfs
Refactored deeply nested if statement in internal/cephfs to reduce cognitive complexity. Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
parent
0f7b653b4e
commit
2d1a572d11
@ -689,20 +689,18 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
|||||||
|
|
||||||
volOpt, snapInfo, sid, err := newSnapshotOptionsFromID(ctx, snapshotID, cr)
|
volOpt, snapInfo, sid, err := newSnapshotOptionsFromID(ctx, snapshotID, cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, util.ErrPoolNotFound):
|
||||||
// if error is ErrPoolNotFound, the pool is already deleted we dont
|
// if error is ErrPoolNotFound, the pool is already deleted we dont
|
||||||
// need to worry about deleting snapshot or omap data, return success
|
// need to worry about deleting snapshot or omap data, return success
|
||||||
if errors.Is(err, util.ErrPoolNotFound) {
|
|
||||||
util.WarningLog(ctx, "failed to get backend snapshot for %s: %v", snapshotID, err)
|
util.WarningLog(ctx, "failed to get backend snapshot for %s: %v", snapshotID, err)
|
||||||
return &csi.DeleteSnapshotResponse{}, nil
|
return &csi.DeleteSnapshotResponse{}, nil
|
||||||
}
|
case errors.Is(err, util.ErrKeyNotFound):
|
||||||
|
|
||||||
// if error is ErrKeyNotFound, then a previous attempt at deletion was complete
|
// if error is ErrKeyNotFound, then a previous attempt at deletion was complete
|
||||||
// or partially complete (snap and snapOMap are garbage collected already), hence return
|
// or partially complete (snap and snapOMap are garbage collected already), hence return
|
||||||
// success as deletion is complete
|
// success as deletion is complete
|
||||||
if errors.Is(err, util.ErrKeyNotFound) {
|
|
||||||
return &csi.DeleteSnapshotResponse{}, nil
|
return &csi.DeleteSnapshotResponse{}, nil
|
||||||
}
|
case errors.Is(err, ErrSnapNotFound):
|
||||||
if errors.Is(err, ErrSnapNotFound) {
|
|
||||||
err = undoSnapReservation(ctx, volOpt, *sid, sid.FsSnapshotName, cr)
|
err = undoSnapReservation(ctx, volOpt, *sid, sid.FsSnapshotName, cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) (%s)",
|
util.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) (%s)",
|
||||||
@ -710,10 +708,9 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
|||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
return &csi.DeleteSnapshotResponse{}, nil
|
return &csi.DeleteSnapshotResponse{}, nil
|
||||||
}
|
case errors.Is(err, ErrVolumeNotFound):
|
||||||
// if the error is ErrVolumeNotFound, the subvolume is already deleted
|
// if the error is ErrVolumeNotFound, the subvolume is already deleted
|
||||||
// from backend, Hence undo the omap entries and return success
|
// from backend, Hence undo the omap entries and return success
|
||||||
if errors.Is(err, ErrVolumeNotFound) {
|
|
||||||
util.ErrorLog(ctx, "Volume not present")
|
util.ErrorLog(ctx, "Volume not present")
|
||||||
err = undoSnapReservation(ctx, volOpt, *sid, sid.FsSnapshotName, cr)
|
err = undoSnapReservation(ctx, volOpt, *sid, sid.FsSnapshotName, cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -722,9 +719,10 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
|||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
return &csi.DeleteSnapshotResponse{}, nil
|
return &csi.DeleteSnapshotResponse{}, nil
|
||||||
}
|
default:
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
defer volOpt.Destroy()
|
defer volOpt.Destroy()
|
||||||
|
|
||||||
// safeguard against parallel create or delete requests against the same
|
// safeguard against parallel create or delete requests against the same
|
||||||
|
Loading…
Reference in New Issue
Block a user