@@ -381,7 +381,59 @@ func (cs *controller) ControllerExpandVolume(
381381 req * csi.ControllerExpandVolumeRequest ,
382382) (* csi.ControllerExpandVolumeResponse , error ) {
383383
384- return nil , status .Error (codes .Unimplemented , "" )
384+ volumeID := strings .ToLower (req .GetVolumeId ())
385+ if volumeID == "" {
386+ return nil , status .Errorf (
387+ codes .InvalidArgument ,
388+ "ControllerExpandVolume: no volumeID provided" ,
389+ )
390+ }
391+
392+ /* round off the new size */
393+ updatedSize := getRoundedCapacity (req .GetCapacityRange ().GetRequiredBytes ())
394+
395+ vol , err := lvm .GetLVMVolume (volumeID )
396+ if err != nil {
397+ return nil , status .Errorf (
398+ codes .Internal ,
399+ "ControllerExpandVolumeRequest: failed to get LVMVolume for %s, {%s}" ,
400+ volumeID ,
401+ err .Error (),
402+ )
403+ }
404+
405+ volsize , err := strconv .ParseInt (vol .Spec .Capacity , 10 , 64 )
406+ if err != nil {
407+ return nil , status .Errorf (
408+ codes .Internal ,
409+ "ControllerExpandVolumeRequest: failed to parse volsize in for %s, {%s}" ,
410+ volumeID ,
411+ err .Error (),
412+ )
413+ }
414+ /*
415+ * Controller expand volume must be idempotent. If a volume corresponding
416+ * to the specified volume ID is already larger than or equal to the target
417+ * capacity of the expansion request, the plugin should reply 0 OK.
418+ */
419+ if volsize >= updatedSize {
420+ return csipayload .NewControllerExpandVolumeResponseBuilder ().
421+ WithCapacityBytes (volsize ).
422+ Build (), nil
423+ }
424+
425+ if err := lvm .ResizeVolume (vol , updatedSize ); err != nil {
426+ return nil , status .Errorf (
427+ codes .Internal ,
428+ "failed to handle ControllerExpandVolumeRequest for %s, {%s}" ,
429+ volumeID ,
430+ err .Error (),
431+ )
432+ }
433+ return csipayload .NewControllerExpandVolumeResponseBuilder ().
434+ WithCapacityBytes (updatedSize ).
435+ WithNodeExpansionRequired (true ).
436+ Build (), nil
385437}
386438
387439// CreateSnapshot creates a snapshot for given volume
@@ -530,6 +582,7 @@ func newControllerCapabilities() []*csi.ControllerServiceCapability {
530582 var capabilities []* csi.ControllerServiceCapability
531583 for _ , cap := range []csi.ControllerServiceCapability_RPC_Type {
532584 csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ,
585+ csi .ControllerServiceCapability_RPC_EXPAND_VOLUME ,
533586 } {
534587 capabilities = append (capabilities , fromType (cap ))
535588 }
0 commit comments