mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
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:
parent
f3ed883df9
commit
b9a8d37c3d
@ -1447,9 +1447,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
defer cr.DeleteCredentials()
|
||||
|
||||
rbdVol, err := GenVolFromVolID(ctx, volID, cr, req.GetSecrets())
|
||||
defer rbdVol.Destroy()
|
||||
rbdVol, err := genVolFromVolIDWithMigration(ctx, volID, cr, req.GetSecrets())
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, ErrImageNotFound):
|
||||
@ -1463,6 +1461,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
|
||||
return nil, err
|
||||
}
|
||||
defer rbdVol.Destroy()
|
||||
|
||||
// NodeExpansion is needed for PersistentVolumes with,
|
||||
// 1. Filesystem VolumeMode with & without Encryption and
|
||||
|
@ -77,35 +77,41 @@ func parseMigrationVolID(vh string) (*migrationVolID, error) {
|
||||
// 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 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
|
||||
rv := &rbdVolume{}
|
||||
|
||||
// fill details to rv struct from parsed migration handle
|
||||
rv.RbdImageName = parsedMigHandle.imageName
|
||||
rv.Pool = parsedMigHandle.poolName
|
||||
rv.ClusterID = parsedMigHandle.clusterID
|
||||
rv.RbdImageName = migVolID.imageName
|
||||
rv.Pool = migVolID.poolName
|
||||
rv.ClusterID = migVolID.clusterID
|
||||
rv.Monitors, err = util.Mons(util.CsiConfigFile, rv.ClusterID)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to fetch monitors using clusterID: %s, err: %v", rv.ClusterID, err)
|
||||
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// connect to the volume.
|
||||
err = rv.Connect(cr)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to get connected to the rbd image : %s, err: %v", rv.RbdImageName, err)
|
||||
|
||||
return 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, err
|
||||
}
|
||||
|
||||
return nil
|
||||
return rv, nil
|
||||
}
|
||||
|
@ -2071,3 +2071,22 @@ func strategicActionOnLogFile(ctx context.Context, logStrategy, logFile string)
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user