Skip to content

Commit

Permalink
Merge pull request #83 from Madhan-SWE/repair_volume_v1
Browse files Browse the repository at this point in the history
Verify volume details added
  • Loading branch information
Power Cloud Robot authored Jan 11, 2022
2 parents 9bae029 + 237a44c commit 510fd82
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
diskDetails, _ := d.cloud.GetDiskByName(volName)
if diskDetails != nil {
// wait for volume to be available as the volume already exists
err := d.cloud.WaitForVolumeState(diskDetails.VolumeID, cloud.VolumeAvailableState)
err := verifyVolumeDetails(opts, diskDetails)
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")
}
Expand Down Expand Up @@ -421,3 +425,17 @@ func getVolSizeBytes(req *csi.CreateVolumeRequest) (int64, error) {
}
return volSizeBytes, nil
}

func verifyVolumeDetails(payload *cloud.DiskOptions, diskDetails *cloud.Disk) error {
if payload.Shareable != diskDetails.Shareable {
return status.Errorf(codes.Internal, "shareable in payload and shareable in disk details don't match")
}
if payload.VolumeType != diskDetails.DiskType {
return status.Errorf(codes.Internal, "TYPE in payload and disktype in disk details don't match")
}
capacityGIB := util.BytesToGiB(payload.CapacityBytes)
if capacityGIB != diskDetails.CapacityGiB {
return status.Errorf(codes.Internal, "capacityBytes in payload and capacityGIB in disk details don't match")
}
return nil
}

0 comments on commit 510fd82

Please sign in to comment.