From b7df449573386134dda8985b4f1533aaefc0b837 Mon Sep 17 00:00:00 2001 From: Cheng Xing Date: Mon, 10 Dec 2018 13:44:19 -0800 Subject: [PATCH] Fail CreateVolume() when Block volume capability is requested --- pkg/gce-pd-csi-driver/controller.go | 8 ++++- pkg/gce-pd-csi-driver/controller_test.go | 44 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/pkg/gce-pd-csi-driver/controller.go b/pkg/gce-pd-csi-driver/controller.go index 604bb861a..060a1e199 100644 --- a/pkg/gce-pd-csi-driver/controller.go +++ b/pkg/gce-pd-csi-driver/controller.go @@ -81,7 +81,13 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("CreateVolume Request Capacity is invalid: %v", err)) } - // TODO(#94): Validate volume capabilities + // TODO(#94): Validate AccessModes in VolumeCapabilities + for _, capability := range volumeCapabilities { + if blk := capability.GetBlock(); blk != nil { + // TODO(#64): Block volume support + return nil, status.Error(codes.Unimplemented, fmt.Sprintf("Block volume support is not yet implemented")) + } + } // Apply Parameters (case-insensitive). We leave validation of // the values to the cloud provider. diff --git a/pkg/gce-pd-csi-driver/controller_test.go b/pkg/gce-pd-csi-driver/controller_test.go index ca7adb0ad..acdce5ec3 100644 --- a/pkg/gce-pd-csi-driver/controller_test.go +++ b/pkg/gce-pd-csi-driver/controller_test.go @@ -602,6 +602,50 @@ func TestCreateVolumeArguments(t *testing.T) { }, }, }, + { + name: "fail with block volume capability", + req: &csi.CreateVolumeRequest{ + Name: name, + CapacityRange: stdCapRange, + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Block{ + Block: &csi.VolumeCapability_BlockVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }, + }, + expErrCode: codes.Unimplemented, + }, + { + name: "fail with both mount and block volume capability", + req: &csi.CreateVolumeRequest{ + Name: name, + CapacityRange: stdCapRange, + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + { + AccessType: &csi.VolumeCapability_Block{ + Block: &csi.VolumeCapability_BlockVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }, + }, + expErrCode: codes.Unimplemented, // once block support is implemented, this error should be InvalidArgument + }, } // Run test cases