cleanup: refractor checkCloneImage to reducing nesting if

This commit refractors checkCloneImage function to
address nestif linter issue.

Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 859d696279)
This commit is contained in:
Rakshith R 2021-07-14 14:41:50 +05:30 committed by mergify[bot]
parent 32faed322a
commit 33234c1b51

View File

@ -75,11 +75,28 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
} }
return true, nil return true, nil
case !errors.Is(err, ErrImageNotFound):
// any error other than image not found return error case errors.Is(err, ErrImageNotFound):
// as the temp clone does not exist,check snapshot exists on parent volume
// snapshot name is same as temporary clone image
snap.RbdImageName = tempClone.RbdImageName
err = parentVol.checkSnapExists(snap)
if err == nil {
// the temp clone exists, delete it lets reserve a new ID and
// create new resources for a cleaner approach
err = parentVol.deleteSnapshot(ctx, snap)
}
if errors.Is(err, ErrSnapNotFound) {
return false, nil
}
return false, err
default:
// any error other than the above return error
return false, err return false, err
} }
} else { }
// snap will be create after we flatten the temporary cloned image,no // snap will be create after we flatten the temporary cloned image,no
// need to check for flatten here. // need to check for flatten here.
// as the snap exists,create clone image and delete temporary snapshot // as the snap exists,create clone image and delete temporary snapshot
@ -104,21 +121,6 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
} }
return true, nil return true, nil
}
// as the temp clone does not exist,check snapshot exists on parent volume
// snapshot name is same as temporary clone image
snap.RbdImageName = tempClone.RbdImageName
err = parentVol.checkSnapExists(snap)
if err == nil {
// the temp clone exists, delete it lets reserve a new ID and
// create new resources for a cleaner approach
err = parentVol.deleteSnapshot(ctx, snap)
}
if errors.Is(err, ErrSnapNotFound) {
return false, nil
}
return false, err
} }
func (rv *rbdVolume) generateTempClone() *rbdVolume { func (rv *rbdVolume) generateTempClone() *rbdVolume {