@@ -419,7 +419,44 @@ func (cs *controllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacit
419419}
420420
421421func (cs * controllerServer ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
422- return nil , status .Error (codes .Unimplemented , fmt .Sprintf ("ControllerExpandVolume is not yet implemented" ))
422+ klog .V (4 ).Infof ("ControllerExpandVolume: called with args %+v" , * req )
423+
424+ volumeID := req .GetVolumeId ()
425+ if len (volumeID ) == 0 {
426+ return nil , status .Error (codes .InvalidArgument , "Volume ID not provided" )
427+ }
428+ cap := req .GetCapacityRange ()
429+ if cap == nil {
430+ return nil , status .Error (codes .InvalidArgument , "Capacity range not provided" )
431+ }
432+
433+ volSizeBytes := int64 (req .GetCapacityRange ().GetRequiredBytes ())
434+ volSizeGB := int (util .RoundUpSize (volSizeBytes , 1024 * 1024 * 1024 ))
435+ maxVolSize := cap .GetLimitBytes ()
436+
437+ if maxVolSize > 0 && maxVolSize < volSizeBytes {
438+ return nil , status .Error (codes .OutOfRange , "After round-up, volume size exceeds the limit specified" )
439+ }
440+
441+ _ , err := cs .Cloud .GetVolume (volumeID )
442+ if err != nil {
443+ if cpoerrors .IsNotFound (err ) {
444+ return nil , status .Error (codes .NotFound , "Volume not found" )
445+ }
446+ return nil , status .Error (codes .Internal , fmt .Sprintf ("GetVolume failed with error %v" , err ))
447+ }
448+
449+ err = cs .Cloud .ExpandVolume (volumeID , volSizeGB )
450+ if err != nil {
451+ return nil , status .Errorf (codes .Internal , fmt .Sprintf ("Could not resize volume %q to size %v: %v" , volumeID , volSizeGB , err ))
452+ }
453+
454+ klog .V (4 ).Infof ("ControllerExpandVolume resized volume %v to size %v" , volumeID , volSizeGB )
455+
456+ return & csi.ControllerExpandVolumeResponse {
457+ CapacityBytes : volSizeBytes ,
458+ NodeExpansionRequired : true ,
459+ }, nil
423460}
424461
425462func getAZFromTopology (requirement * csi.TopologyRequirement ) string {
0 commit comments