Skip to content

Improve error messages for ControllerExpandVolume / CreateSnapshot of multi-zone PV. #1718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/gce-pd-csi-driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,11 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
return nil, status.Errorf(codes.InvalidArgument, "CreateSnapshot Volume ID is invalid: %v", err.Error())
}

volumeIsMultiZone := isMultiZoneVolKey(volKey)
if gceCS.multiZoneVolumeHandleConfig.Enable && volumeIsMultiZone {
return nil, status.Errorf(codes.InvalidArgument, "Snapshots are not supported with the multi-zone PV volumeHandle feature")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also emit the volumeID here?

}

if acquired := gceCS.volumeLocks.TryAcquire(volumeID); !acquired {
return nil, status.Errorf(codes.Aborted, common.VolumeOperationAlreadyExistsFmt, volumeID)
}
Expand Down Expand Up @@ -1203,6 +1208,7 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Invalid volume key: %v", volKey)
}

// Check if PD snapshot already exists
var snapshot *compute.Snapshot
snapshot, err = gceCS.CloudProvider.GetSnapshot(ctx, project, snapshotName)
Expand Down Expand Up @@ -1482,6 +1488,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
}

func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {

var err error
diskTypeForMetric := metrics.DefaultDiskTypeForMetric
enableConfidentialCompute := metrics.DefaultEnableConfidentialCompute
Expand All @@ -1504,12 +1511,19 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
return nil, status.Errorf(codes.InvalidArgument, "ControllerExpandVolume Volume ID is invalid: %v", err.Error())
}
project, volKey, err = gceCS.CloudProvider.RepairUnderspecifiedVolumeKey(ctx, project, volKey)

if err != nil {
if gce.IsGCENotFoundError(err) {
return nil, status.Errorf(codes.NotFound, "ControllerExpandVolume could not find volume with ID %v: %v", volumeID, err.Error())
}
return nil, common.LoggedError("ControllerExpandVolume error repairing underspecified volume key: ", err)
}

volumeIsMultiZone := isMultiZoneVolKey(volKey)
if gceCS.multiZoneVolumeHandleConfig.Enable && volumeIsMultiZone {
return nil, status.Errorf(codes.InvalidArgument, "ControllerExpandVolume is not supported with the multi-zone PVC volumeHandle feature. Please re-create the volume %v from source if you want a larger size", volumeID)
}

sourceDisk, err := gceCS.CloudProvider.GetDisk(ctx, project, volKey, gce.GCEAPIVersionV1)
diskTypeForMetric, enableConfidentialCompute, enableStoragePools = metrics.GetMetricParameters(sourceDisk)
resizedGb, err := gceCS.CloudProvider.ResizeDisk(ctx, project, volKey, reqBytes)
Expand Down
71 changes: 71 additions & 0 deletions pkg/gce-pd-csi-driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,77 @@ func TestCreateSnapshotArguments(t *testing.T) {
}
}

func TestUnsupporteddMultiZoneCreateSnapshot(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/TestUnsupporteddMultiZoneCreateSnapshot/TestUnsupportedMultiZoneCreateSnapshot

testCase := struct {
name string
req *csi.CreateSnapshotRequest
expErrCode codes.Code
}{
name: "failed create snapshot for multi-zone PV", // Example values
req: &csi.CreateSnapshotRequest{
Name: name,
SourceVolumeId: multiZoneVolumeID,
},
expErrCode: codes.InvalidArgument,
}

t.Logf("test case: %s", testCase.name)

gceDriver := initGCEDriver(t, nil)
gceDriver.cs.multiZoneVolumeHandleConfig = MultiZoneVolumeHandleConfig{
Enable: true,
}

// Start Test
_, err := gceDriver.cs.CreateSnapshot(context.Background(), testCase.req)
if err != nil {
serverError, ok := status.FromError(err)
if !ok {
t.Fatalf("Could not get error status code from err: %v", serverError)
}
if serverError.Code() != testCase.expErrCode {
t.Fatalf("Expected error code: %v, got: %v. err : %v", testCase.expErrCode, serverError.Code(), err)
}
} else {
t.Fatalf("Expected error: %v, got no error", testCase.expErrCode)
}
}

func TestUnsupportedMultiZoneControllerExpandVolume(t *testing.T) {
testCase := struct {
name string
req *csi.ControllerExpandVolumeRequest
expErrCode codes.Code
}{
name: "failed create snapshot for multi-zone PV", // Example values
req: &csi.ControllerExpandVolumeRequest{
VolumeId: multiZoneVolumeID,
},
expErrCode: codes.InvalidArgument,
}

t.Logf("test case: %s", testCase.name)

gceDriver := initGCEDriver(t, nil)
gceDriver.cs.multiZoneVolumeHandleConfig = MultiZoneVolumeHandleConfig{
Enable: true,
}

// Start Test
_, err := gceDriver.cs.ControllerExpandVolume(context.Background(), testCase.req)
if err != nil {
serverError, ok := status.FromError(err)
if !ok {
t.Fatalf("Could not get error status code from err: %v", serverError)
}
if serverError.Code() != testCase.expErrCode {
t.Fatalf("Expected error code: %v, got: %v. err : %v", testCase.expErrCode, serverError.Code(), err)
}
} else {
t.Fatalf("Expected error: %v, got no error", testCase.expErrCode)
}
}

func TestDeleteSnapshot(t *testing.T) {
testCases := []struct {
name string
Expand Down