mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
Resize CephFS Volumes
This feature enables CephFS Volume expansion on demand based on the CO resizer request. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
parent
d590434374
commit
b721accaf5
@ -292,3 +292,39 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(
|
|||||||
},
|
},
|
||||||
}, nil
|
}, 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
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -134,6 +134,7 @@ func (fs *Driver) Run(conf *util.Config, cachePersister util.CachePersister) {
|
|||||||
if conf.IsControllerServer || !conf.IsNodeServer {
|
if conf.IsControllerServer || !conf.IsNodeServer {
|
||||||
fs.cd.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{
|
fs.cd.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{
|
||||||
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
|
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
|
||||||
|
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
|
||||||
})
|
})
|
||||||
|
|
||||||
fs.cd.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{
|
fs.cd.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{
|
||||||
|
@ -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
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -114,3 +114,21 @@ func (cs *ControllerServer) validateDeleteVolumeRequest() error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user