Skip to content

Commit

Permalink
Bug 1882983: check PV access mode
Browse files Browse the repository at this point in the history
Currently we support attaching volumes only to the single node and
therefore ROX and RWX modes are not possible. Check access mode before
creating PV and fail PV creation if user requests multi node access.
  • Loading branch information
vjuranek committed Jan 10, 2022
1 parent 75d5266 commit d0360a5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/service/controller.go
Expand Up @@ -51,6 +51,13 @@ func (c *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
"failed to parse storage class field %s, expected 'true' or 'false' but got %s",
ParameterThinProvisioning, req.Parameters[ParameterThinProvisioning])
}
// Check access mode
for _, cap := range req.GetVolumeCapabilities() {
if cap.AccessMode.Mode != csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY &&
cap.AccessMode.Mode != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
return nil, fmt.Errorf("unsupported access mode %s, currently only RWO is supported", cap.AccessMode.Mode)
}
}
requiredSize := req.CapacityRange.GetRequiredBytes()
// Check if a disk with the same name already exist
disks, err := c.ovirtClient.ListDisksByAlias(diskName, ovirtclient.ContextStrategy(ctx))
Expand Down
33 changes: 33 additions & 0 deletions pkg/service/controller_test.go
Expand Up @@ -33,6 +33,39 @@ func TestVolumeCreation(t *testing.T) {
}
}

func TestCreateRWXVolumeFails(t *testing.T) {
helper := getMockHelper(t)
controller := service.NewOvirtCSIDriver(helper.GetClient(), "test")
testStorageDomain, err := helper.GetClient().GetStorageDomain(helper.GetStorageDomainID())
if err != nil {
t.Fatalf("failed to get stoarge domain %s", helper.GetStorageDomainID())
}

_, err = controller.CreateVolume(context.Background(), &csi.CreateVolumeRequest{
Name: "test",
CapacityRange: &csi.CapacityRange{
RequiredBytes: 4096,
LimitBytes: 4096,
},
Parameters: map[string]string{
"storageClass": "ovirt-test-domain",
"storageDomainName": testStorageDomain.Name(),
"thinProvisioning": "true",
},
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
},
},
})

if err == nil {
t.Fatalf("publishing RWX volume which shouldn't be possible")
}
}

func TestDeleteVolume(t *testing.T) {
helper := getMockHelper(t)
controller := service.NewOvirtCSIDriver(helper.GetClient(), "test")
Expand Down

0 comments on commit d0360a5

Please sign in to comment.