mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
cleanup: move copyEncryptionConfig() from CreateVolume to Exists()
The rbdVolume that needs its encryption configured is constructed in the Exists() method. It is suitable to move the copyEncryptionConfig() call there as well, so that the object is completely constructed in a single place. Golang-ci:gocyclo complained about the increased complexity of the Exists() function. Moving the repairing of the ImageID into its own helper function makes the code a little easier to understand. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
596410ae60
commit
52433841b4
@ -269,14 +269,6 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
||||
}
|
||||
}
|
||||
|
||||
if parentVol != nil && parentVol.isEncrypted() {
|
||||
err = parentVol.copyEncryptionConfig(&rbdVol.rbdImage)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return buildCreateVolumeResponse(req, rbdVol), nil
|
||||
}
|
||||
|
||||
|
@ -300,17 +300,9 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er
|
||||
return false, err
|
||||
}
|
||||
|
||||
if rv.ImageID == "" {
|
||||
err = rv.getImageID()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get image id %s: %v", rv, err)
|
||||
return false, err
|
||||
}
|
||||
err = j.StoreImageID(ctx, rv.JournalPool, rv.ReservedID, rv.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume id %s: %v", rv, err)
|
||||
return false, err
|
||||
}
|
||||
err = rv.repairImageID(ctx, j)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// size checks
|
||||
@ -327,12 +319,42 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er
|
||||
return false, err
|
||||
}
|
||||
|
||||
if parentVol != nil && parentVol.isEncrypted() {
|
||||
err = parentVol.copyEncryptionConfig(&rv.rbdImage)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
util.DebugLog(ctx, "found existing volume (%s) with image name (%s) for request (%s)",
|
||||
rv.VolID, rv.RbdImageName, rv.RequestName)
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// repairImageID checks if rv.ImageID is already available (if so, it was
|
||||
// fetched from the journal), in case it is missing, the imageID is obtained
|
||||
// and stored in the journal.
|
||||
func (rv *rbdVolume) repairImageID(ctx context.Context, j *journal.Connection) error {
|
||||
if rv.ImageID != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := rv.getImageID()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get image id %s: %v", rv, err)
|
||||
return err
|
||||
}
|
||||
err = j.StoreImageID(ctx, rv.JournalPool, rv.ReservedID, rv.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume id %s: %v", rv, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// reserveSnap is a helper routine to request a rbdSnapshot name reservation and generate the
|
||||
// volume ID for the generated name.
|
||||
func reserveSnap(ctx context.Context, rbdSnap *rbdSnapshot, rbdVol *rbdVolume, cr *util.Credentials) error {
|
||||
|
Loading…
Reference in New Issue
Block a user