rbd: enable expand operation for intree volumes

This commit enable the resize operation[1] for in-tree volumes.
new helper has been introduced here to aid the enablement or to
make it clean with existing code base.

[1] https://github.com/ceph/ceph-csi/blob/devel/docs/design/proposals/intree-migrate.md?plain=1#L66

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal 2021-12-22 11:29:09 +05:30 committed by mergify[bot]
parent f3ed883df9
commit b9a8d37c3d
3 changed files with 42 additions and 18 deletions

View File

@ -1447,9 +1447,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
return nil, status.Error(codes.InvalidArgument, err.Error()) return nil, status.Error(codes.InvalidArgument, err.Error())
} }
defer cr.DeleteCredentials() defer cr.DeleteCredentials()
rbdVol, err := genVolFromVolIDWithMigration(ctx, volID, cr, req.GetSecrets())
rbdVol, err := GenVolFromVolID(ctx, volID, cr, req.GetSecrets())
defer rbdVol.Destroy()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, ErrImageNotFound): case errors.Is(err, ErrImageNotFound):
@ -1463,6 +1461,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
return nil, err return nil, err
} }
defer rbdVol.Destroy()
// NodeExpansion is needed for PersistentVolumes with, // NodeExpansion is needed for PersistentVolumes with,
// 1. Filesystem VolumeMode with & without Encryption and // 1. Filesystem VolumeMode with & without Encryption and

View File

@ -77,35 +77,41 @@ func parseMigrationVolID(vh string) (*migrationVolID, error) {
// deleteMigratedVolume 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. // and delete the volume from the cluster, return err if there was an error on the process.
func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID, cr *util.Credentials) error { func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID, cr *util.Credentials) error {
rv, err := genVolFromMigVolID(ctx, parsedMigHandle, cr)
if err != nil {
return err
}
defer rv.Destroy()
err = deleteImage(ctx, rv, cr)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s, err: %v", rv, err)
}
return err
}
// genVolFromMigVolID populate rbdVol struct from the migration volID.
func genVolFromMigVolID(ctx context.Context, migVolID *migrationVolID, cr *util.Credentials) (*rbdVolume, error) {
var err error var err error
rv := &rbdVolume{} rv := &rbdVolume{}
// fill details to rv struct from parsed migration handle // fill details to rv struct from parsed migration handle
rv.RbdImageName = parsedMigHandle.imageName rv.RbdImageName = migVolID.imageName
rv.Pool = parsedMigHandle.poolName rv.Pool = migVolID.poolName
rv.ClusterID = parsedMigHandle.clusterID rv.ClusterID = migVolID.clusterID
rv.Monitors, err = util.Mons(util.CsiConfigFile, rv.ClusterID) rv.Monitors, err = util.Mons(util.CsiConfigFile, rv.ClusterID)
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed to fetch monitors using clusterID: %s, err: %v", rv.ClusterID, err) log.ErrorLog(ctx, "failed to fetch monitors using clusterID: %s, err: %v", rv.ClusterID, err)
return err return nil, err
} }
// connect to the volume. // connect to the volume.
err = rv.Connect(cr) err = rv.Connect(cr)
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed to get connected to the rbd image : %s, err: %v", rv.RbdImageName, err) log.ErrorLog(ctx, "failed to get connected to the rbd image : %s, err: %v", rv.RbdImageName, err)
return err return nil, err
}
defer rv.Destroy()
// if connected , delete it
err = deleteImage(ctx, rv, cr)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image : %s, err: %v", rv.RbdImageName, err)
return err
} }
return nil return rv, nil
} }

View File

@ -2071,3 +2071,22 @@ func strategicActionOnLogFile(ctx context.Context, logStrategy, logFile string)
log.ErrorLog(ctx, "unknown cephLogStrategy option %q: hint: 'remove'|'compress'|'preserve'", logStrategy) log.ErrorLog(ctx, "unknown cephLogStrategy option %q: hint: 'remove'|'compress'|'preserve'", logStrategy)
} }
} }
// genVolFromVolIDWithMigration populate a rbdVol structure based on the volID format.
func genVolFromVolIDWithMigration(
ctx context.Context, volID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
if isMigrationVolID(volID) {
pmVolID, pErr := parseMigrationVolID(volID)
if pErr != nil {
return nil, pErr
}
return genVolFromMigVolID(ctx, pmVolID, cr)
}
rv, err := GenVolFromVolID(ctx, volID, cr, secrets)
if err != nil {
rv.Destroy()
}
return rv, err
}