@@ -127,6 +127,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
127127 return nil , status .Error (codes .InvalidArgument , err .Error ())
128128 }
129129
130+ // If creating from snapshot, get the snapshot size
131+ var snapshotSizeGiB int64
130132 if snapshotID != "" {
131133 logger .Info ("Creating volume from snapshot" , "snapshotID" , snapshotID )
132134 // Call the cloud connector's CreateVolumeFromSnapshot if implemented
@@ -138,17 +140,19 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
138140 // Error with CloudStack
139141 return nil , status .Errorf (codes .Internal , "Error %v" , err )
140142 }
141- logger .Info ("Disk offering ID" , "diskOfferingID: " , diskOfferingID )
142- logger .Info ("Zone ID" , "ZoneID" , snapshot .ZoneID )
143- logger .Info ("Name" , "name" , name )
144- logger .Info ("Domain ID" , "DomainID" , snapshot .DomainID )
145- logger .Info ("Project ID" , "ProjectID" , snapshot .ProjectID )
146- logger .Info ("Snapshot ID" , "snapshotID" , snapshotID )
147- logger .Info ("Volume size" , "Size" , sizeInGB )
143+
144+ logger .Info ("PVC created with" , "size" , sizeInGB )
145+ snapshotSizeGiB = util .RoundUpBytesToGB (snapshot .Size )
146+ if snapshotSizeGiB > sizeInGB {
147+ logger .Info ("Snapshot size is greater than the request PVC, creating volume from snapshot of size" , "snapshot size:" , snapshotSizeGiB )
148+ sizeInGB = snapshotSizeGiB
149+ }
150+
148151 volFromSnapshot , err := cs .connector .CreateVolumeFromSnapshot (ctx , snapshot .ZoneID , name , snapshot .DomainID , snapshot .ProjectID , snapshotID , sizeInGB )
149152 if err != nil {
150153 return nil , status .Errorf (codes .Internal , "Cannot create volume from snapshot %s: %v" , snapshotID , err .Error ())
151154 }
155+
152156 resp := & csi.CreateVolumeResponse {
153157 Volume : & csi.Volume {
154158 VolumeId : volFromSnapshot .ID ,
0 commit comments