Skip to content

Commit

Permalink
fix3
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar committed Nov 10, 2022
1 parent f0b5af5 commit acfe73c
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package driver

import (
"context"
"strconv"
"strings"

csi "github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -148,20 +147,11 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
case *csi.VolumeContentSource_Volume:
diskDetails, _ := d.cloud.GetDiskByNamePrefix("clone-" + volName)
if diskDetails != nil {
err := verifyVolumeDetails(opts, diskDetails, true)
err := verifyVolumeDetails(opts, diskDetails, false)
if err != nil {
return nil, err
}
err = d.cloud.WaitForVolumeState(diskDetails.VolumeID, cloud.VolumeAvailableState)
if err != nil {
return nil, status.Errorf(codes.Internal, "Disk already exists and not in expected state")
}
resp := newCreateVolumeResponse(diskDetails, req.VolumeContentSource)
if util.GiBToBytes(diskDetails.CapacityGiB) < volSizeBytes {
resp.Volume.VolumeContext["resizeRequired"] = strconv.FormatBool(true)
resp.Volume.VolumeContext["requestedsizegib"] = strconv.Itoa(int(util.BytesToGiB(volSizeBytes)))
}
return resp, nil
return newCreateVolumeResponse(diskDetails, req.VolumeContentSource), nil
}
if srcVolume := volumeSource.GetVolume(); srcVolume != nil {
srcVolumeID := srcVolume.GetVolumeId()
Expand All @@ -177,16 +167,25 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not create volume %q: %v", volName, err)
}
if util.GiBToBytes(diskDetails.CapacityGiB) < volSizeBytes {
capRange := req.GetCapacityRange()
if capRange == nil {
return nil, status.Error(codes.InvalidArgument, "Capacity range not provided")
}
maxVolSize := capRange.GetLimitBytes()
if maxVolSize > 0 && maxVolSize < volSizeBytes {
return nil, status.Error(codes.InvalidArgument, "After round-up, volume size exceeds the limit specified")
}
_, err := d.cloud.ResizeDisk(diskFromSourceVolume.VolumeID, volSizeBytes)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not resize volume %q: %v", diskFromSourceVolume.VolumeID, err)
}
}
cloneDiskDetails, err := d.cloud.GetDiskByID(diskFromSourceVolume.VolumeID)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not create volume %q: %v", volName, err)
}
resp := newCreateVolumeResponse(cloneDiskDetails, req.VolumeContentSource)
if util.GiBToBytes(cloneDiskDetails.CapacityGiB) < volSizeBytes {
resp.Volume.VolumeContext["resizeRequired"] = strconv.FormatBool(true)
resp.Volume.VolumeContext["requestedsizegib"] = strconv.Itoa(int(util.BytesToGiB(volSizeBytes)))
}
return resp, nil
return newCreateVolumeResponse(cloneDiskDetails, req.VolumeContentSource), nil
}
default:
return nil, status.Errorf(codes.InvalidArgument, "%v not a proper volume source", volumeSource)
Expand Down

0 comments on commit acfe73c

Please sign in to comment.