mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-23 23:00:19 +00:00
cleanup: split repairExistingVolume() from CreateVolume()
Move the repairing of a volume/snapshot from CreateVolume to its own
function. This reduces the complexity of the code, and makes the
procedure easier to understand. Further enhancements to repairing an
exsiting volume can be done in the new function.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
(cherry picked from commit 96a8ea3e88
)
This commit is contained in:
parent
a884b99c6e
commit
58d606ab8d
@ -257,23 +257,8 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
|||||||
found, err := rbdVol.Exists(ctx, parentVol)
|
found, err := rbdVol.Exists(ctx, parentVol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, getGRPCErrorForCreateVolume(err)
|
return nil, getGRPCErrorForCreateVolume(err)
|
||||||
}
|
} else if found {
|
||||||
|
return cs.repairExistingVolume(ctx, req, cr, rbdVol, rbdSnap)
|
||||||
if found {
|
|
||||||
if rbdSnap != nil {
|
|
||||||
// check if image depth is reached limit and requires flatten
|
|
||||||
err = checkFlatten(ctx, rbdVol, cr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = rbdSnap.repairEncryptionConfig(&rbdVol.rbdImage)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildCreateVolumeResponse(req, rbdVol), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = validateRequestedVolumeSize(rbdVol, parentVol, rbdSnap, cr)
|
err = validateRequestedVolumeSize(rbdVol, parentVol, rbdSnap, cr)
|
||||||
@ -332,6 +317,27 @@ func flattenParentImage(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// repairExistingVolume checks the existing volume or snapshot and makes sure
|
||||||
|
// that the state is corrected to what was requested. It is needed to call this
|
||||||
|
// when the process of creating a volume was interrupted.
|
||||||
|
func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.CreateVolumeRequest,
|
||||||
|
cr *util.Credentials, rbdVol *rbdVolume, rbdSnap *rbdSnapshot) (*csi.CreateVolumeResponse, error) {
|
||||||
|
if rbdSnap != nil {
|
||||||
|
// check if image depth is reached limit and requires flatten
|
||||||
|
err := checkFlatten(ctx, rbdVol, cr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = rbdSnap.repairEncryptionConfig(&rbdVol.rbdImage)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildCreateVolumeResponse(req, rbdVol), nil
|
||||||
|
}
|
||||||
|
|
||||||
// check snapshots on the rbd image, as we have limit from krbd that an image
|
// check snapshots on the rbd image, as we have limit from krbd that an image
|
||||||
// cannot have more than 510 snapshot at a given point of time. If the
|
// cannot have more than 510 snapshot at a given point of time. If the
|
||||||
// snapshots are more than the `maxSnapshotsOnImage` Add a task to flatten all
|
// snapshots are more than the `maxSnapshotsOnImage` Add a task to flatten all
|
||||||
|
Loading…
Reference in New Issue
Block a user