From 69ae19e0cb242c5277cadae4f8a404094d8cb714 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 15 Dec 2021 11:02:13 +0530 Subject: [PATCH] rbd: resize the volume created from snapshot If the requested volume size is greater than the snapshot size, resize the cloned volume after creating a clone from a snapshot. Signed-off-by: Madhu Rajanna --- internal/rbd/controllerserver.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 640079a54..50bb8a4cc 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -389,6 +389,14 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C return nil, err } + // expand the image if the requested size is greater than the current size + err = rbdVol.expand() + if err != nil { + log.ErrorLog(ctx, "failed to resize volume %s: %v", rbdVol, err) + + return nil, err + } + // rbdVol is a clone from parentVol case vcs.GetVolume() != nil: // When cloning into a thick-provisioned volume was happening, @@ -590,6 +598,15 @@ func (cs *ControllerServer) createVolumeFromSnapshot( log.DebugLog(ctx, "create volume %s from snapshot %s", rbdVol.RequestName, rbdSnap.RbdSnapName) + // resize the volume if the size is different + // expand the image if the requested size is greater than the current size + err = rbdVol.expand() + if err != nil { + log.ErrorLog(ctx, "failed to resize volume %s: %v", rbdVol, err) + + return err + } + return nil }