From b721accaf53f84c7cdb1572b8a1446a69b2917da Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Mon, 7 Oct 2019 12:11:33 +0530 Subject: [PATCH] Resize CephFS Volumes This feature enables CephFS Volume expansion on demand based on the CO resizer request. Signed-off-by: Humble Chirammal --- pkg/cephfs/controllerserver.go | 36 ++++++++++++++++++++++++++++++++++ pkg/cephfs/driver.go | 1 + pkg/cephfs/identityserver.go | 7 +++++++ pkg/cephfs/util.go | 18 +++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/pkg/cephfs/controllerserver.go b/pkg/cephfs/controllerserver.go index b8f45ffbf..776c322b6 100644 --- a/pkg/cephfs/controllerserver.go +++ b/pkg/cephfs/controllerserver.go @@ -292,3 +292,39 @@ func (cs *ControllerServer) ValidateVolumeCapabilities( }, }, nil } + +// ExpandVolume expand CephFS Volumes on demand based on resizer request +func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { + + if err := cs.validateExpandVolumeRequest(req); err != nil { + klog.Errorf("ControllerExpandVolumeRequest validation failed: %v", err) + return nil, err + } + + volID := req.GetVolumeId() + secret := req.GetSecrets() + + cr, err := util.NewAdminCredentials(secret) + if err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + defer cr.DeleteCredentials() + + volOptions, volIdentifier, err := newVolumeOptionsFromVolID(ctx, volID, nil, secret) + + if err != nil { + klog.Errorf("validation and extraction of volume options failed: %v", err) + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if err = createVolume(ctx, volOptions, cr, volumeID(volIdentifier.FsSubvolName), req.GetCapacityRange().GetRequiredBytes()); err != nil { + klog.Errorf("failed to expand volume %s: %v", volumeID(volIdentifier.FsSubvolName), err) + return nil, status.Error(codes.Internal, err.Error()) + } + + return &csi.ControllerExpandVolumeResponse{ + CapacityBytes: req.GetCapacityRange().GetRequiredBytes(), + NodeExpansionRequired: false, + }, nil + +} diff --git a/pkg/cephfs/driver.go b/pkg/cephfs/driver.go index 260c49a96..e16d7013e 100644 --- a/pkg/cephfs/driver.go +++ b/pkg/cephfs/driver.go @@ -134,6 +134,7 @@ func (fs *Driver) Run(conf *util.Config, cachePersister util.CachePersister) { if conf.IsControllerServer || !conf.IsNodeServer { fs.cd.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{ csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME, + csi.ControllerServiceCapability_RPC_EXPAND_VOLUME, }) fs.cd.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{ diff --git a/pkg/cephfs/identityserver.go b/pkg/cephfs/identityserver.go index 6a929c29d..3ee357350 100644 --- a/pkg/cephfs/identityserver.go +++ b/pkg/cephfs/identityserver.go @@ -41,6 +41,13 @@ func (is *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.Ge }, }, }, + { + Type: &csi.PluginCapability_VolumeExpansion_{ + VolumeExpansion: &csi.PluginCapability_VolumeExpansion{ + Type: csi.PluginCapability_VolumeExpansion_ONLINE, + }, + }, + }, }, }, nil } diff --git a/pkg/cephfs/util.go b/pkg/cephfs/util.go index c3453402b..da4136e86 100644 --- a/pkg/cephfs/util.go +++ b/pkg/cephfs/util.go @@ -114,3 +114,21 @@ func (cs *ControllerServer) validateDeleteVolumeRequest() error { return nil } + +// Controller expand volume request validation +func (cs *ControllerServer) validateExpandVolumeRequest(req *csi.ControllerExpandVolumeRequest) error { + if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME); err != nil { + return fmt.Errorf("invalid ExpandVolumeRequest: %v", err) + } + + if req.GetVolumeId() == "" { + return status.Error(codes.InvalidArgument, "Volume ID cannot be empty") + } + + capRange := req.GetCapacityRange() + if capRange == nil { + return status.Error(codes.InvalidArgument, "CapacityRange cannot be empty") + } + + return nil +}