Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1590 from surian/remove_constraint…
Browse files Browse the repository at this point in the history
…_io1_volume

remove condition on iopspergb key being mandatory for io1 volumes
  • Loading branch information
k8s-ci-robot authored May 19, 2023
2 parents 9b7b951 + 0f78b72 commit 771e745
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 47 deletions.
6 changes: 0 additions & 6 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,6 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
}
}

if volumeType == cloud.VolumeTypeIO1 {
if iopsPerGB == 0 {
return nil, status.Errorf(codes.InvalidArgument, "The parameter IOPSPerGB must be specified for io1 volumes")
}
}

if blockExpress && volumeType != cloud.VolumeTypeIO2 {
return nil, status.Errorf(codes.InvalidArgument, "Block Express is only supported on io2 volumes")
}
Expand Down
127 changes: 86 additions & 41 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ func TestCreateVolume(t *testing.T) {
},
},
{
name: "success with volume type io1",
name: "success with volume type io1 using iopsPerGB",
testFunc: func(t *testing.T) {
req := &csi.CreateVolumeRequest{
Name: "vol-test",
Expand Down Expand Up @@ -839,7 +839,49 @@ func TestCreateVolume(t *testing.T) {
},
},
{
name: "success with volume type io2",
name: "success with volume type io1 using iops",
testFunc: func(t *testing.T) {
req := &csi.CreateVolumeRequest{
Name: "vol-test",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: map[string]string{
VolumeTypeKey: cloud.VolumeTypeIO1,
IopsKey: "5",
},
}

ctx := context.Background()

mockDisk := &cloud.Disk{
VolumeID: req.Name,
AvailabilityZone: expZone,
CapacityGiB: util.BytesToGiB(stdVolSize),
}

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()

mockCloud := cloud.NewMockCloud(mockCtl)
mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.Name), gomock.Any()).Return(mockDisk, nil)

awsDriver := controllerService{
cloud: mockCloud,
inFlight: internal.NewInFlight(),
driverOptions: &DriverOptions{},
}

if _, err := awsDriver.CreateVolume(ctx, req); err != nil {
srvErr, ok := status.FromError(err)
if !ok {
t.Fatalf("Could not get error status code from error: %v", srvErr)
}
t.Fatalf("Unexpected error: %v", srvErr.Code())
}
},
},
{
name: "success with volume type io2 using iopsPerGB",
testFunc: func(t *testing.T) {
req := &csi.CreateVolumeRequest{
Name: "vol-test",
Expand Down Expand Up @@ -880,6 +922,48 @@ func TestCreateVolume(t *testing.T) {
}
},
},
{
name: "success with volume type io2 using iops",
testFunc: func(t *testing.T) {
req := &csi.CreateVolumeRequest{
Name: "vol-test",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: map[string]string{
VolumeTypeKey: cloud.VolumeTypeIO2,
IopsKey: "5",
},
}

ctx := context.Background()

mockDisk := &cloud.Disk{
VolumeID: req.Name,
AvailabilityZone: expZone,
CapacityGiB: util.BytesToGiB(stdVolSize),
}

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()

mockCloud := cloud.NewMockCloud(mockCtl)
mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.Name), gomock.Any()).Return(mockDisk, nil)

awsDriver := controllerService{
cloud: mockCloud,
inFlight: internal.NewInFlight(),
driverOptions: &DriverOptions{},
}

if _, err := awsDriver.CreateVolume(ctx, req); err != nil {
srvErr, ok := status.FromError(err)
if !ok {
t.Fatalf("Could not get error status code from error: %v", srvErr)
}
t.Fatalf("Unexpected error: %v", srvErr.Code())
}
},
},
{
name: "success with volume type sc1",
testFunc: func(t *testing.T) {
Expand Down Expand Up @@ -1521,45 +1605,6 @@ func TestCreateVolume(t *testing.T) {
checkExpectedErrorCode(t, err, codes.Aborted)
},
},
{
name: "fail with missing iopsPerGB parameter",
testFunc: func(t *testing.T) {
req := &csi.CreateVolumeRequest{
Name: "vol-test",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: map[string]string{
VolumeTypeKey: cloud.VolumeTypeIO1,
},
}

ctx := context.Background()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()

mockCloud := cloud.NewMockCloud(mockCtl)

awsDriver := controllerService{
cloud: mockCloud,
inFlight: internal.NewInFlight(),
driverOptions: &DriverOptions{},
}

_, err := awsDriver.CreateVolume(ctx, req)
if err == nil {
t.Fatalf("Expected CreateVolume to fail but got no error")
}

srvErr, ok := status.FromError(err)
if !ok {
t.Fatalf("Could not get error status code from error: %v", srvErr)
}
if srvErr.Code() != codes.InvalidArgument {
t.Fatalf("Expect InvalidArgument but got: %s", srvErr.Code())
}
},
},
{
name: "Fail with IdempotentParameterMismatch error",
testFunc: func(t *testing.T) {
Expand Down

0 comments on commit 771e745

Please sign in to comment.