rbd: split the parsing and deletion logic to its own functions.

parseAndDeleteMigratedVolume() prviously clubbed the logic of
parsing of migration volume handle and then continued with the
deletion of the volume. however this commit split this
logic into two, ie parsing has been done in parseMigrationVolID()
and DeleteMigratedVolume() deletes the backend volume.

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal 2021-10-25 14:47:12 +05:30 committed by mergify[bot]
parent ff0911fb6a
commit 5621f2cfca
2 changed files with 11 additions and 12 deletions

View File

@ -851,11 +851,15 @@ func (cs *ControllerServer) DeleteVolume(
}
defer cs.OperationLocks.ReleaseDeleteLock(volumeID)
// if this is a migration request volID, delete the volume in backend
if isMigrationVolID(volumeID) {
log.DebugLog(ctx, "migration volume ID : %s", volumeID)
err = parseAndDeleteMigratedVolume(ctx, volumeID, cr)
if err != nil && !errors.Is(err, ErrImageNotFound) {
return nil, status.Error(codes.Internal, err.Error())
pmVolID, pErr := parseMigrationVolID(volumeID)
if pErr != nil {
return nil, status.Error(codes.InvalidArgument, pErr.Error())
}
pErr = deleteMigratedVolume(ctx, pmVolID, cr)
if pErr != nil && !errors.Is(pErr, ErrImageNotFound) {
return nil, status.Error(codes.Internal, pErr.Error())
}
return &csi.DeleteVolumeResponse{}, nil

View File

@ -74,15 +74,10 @@ func parseMigrationVolID(vh string) (*migrationVolID, error) {
return mh, nil
}
// parseAndDeleteMigratedVolume get rbd volume details from the migration volID
// deleteMigratedVolume get rbd volume details from the migration volID
// and delete the volume from the cluster, return err if there was an error on the process.
func parseAndDeleteMigratedVolume(ctx context.Context, volumeID string, cr *util.Credentials) error {
parsedMigHandle, err := parseMigrationVolID(volumeID)
if err != nil {
log.ErrorLog(ctx, "failed to parse migration volumeID: %s , err: %v", volumeID, err)
return err
}
func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID, cr *util.Credentials) error {
var err error
rv := &rbdVolume{}
// fill details to rv struct from parsed migration handle