|
13 | 13 | from kadalulib import CommandException, logf, send_analytics_tracker, execute
|
14 | 14 | from volumeutils import (HOSTVOL_MOUNTDIR, PV_TYPE_SUBVOL, PV_TYPE_VIRTBLOCK,
|
15 | 15 | check_external_volume, create_subdir_volume,
|
16 |
| - create_virtblock_volume, delete_volume, expand_volume, |
| 16 | + create_block_volume, delete_volume, expand_volume, |
17 | 17 | get_pv_hosting_volumes, is_hosting_volume_free,
|
18 | 18 | mount_and_select_hosting_volume, search_volume,
|
19 | 19 | unmount_glusterfs, update_free_size,
|
@@ -70,6 +70,12 @@ def execute_gluster_quota_command(privkey, user, host, gvolname, path, size):
|
70 | 70 | return None
|
71 | 71 |
|
72 | 72 |
|
| 73 | +def pvc_access_mode(request): |
| 74 | + """Fetch Access modes from Volume capabilities""" |
| 75 | + for vol_capability in request.volume_capabilities: |
| 76 | + return vol_capability.access_mode.mode |
| 77 | + |
| 78 | + |
73 | 79 | class ControllerServer(csi_pb2_grpc.ControllerServicer):
|
74 | 80 | """
|
75 | 81 | ControllerServer object is responsible for handling host
|
@@ -112,17 +118,24 @@ def CreateVolume(self, request, context):
|
112 | 118 | pvsize = request.capacity_range.required_bytes
|
113 | 119 |
|
114 | 120 | pvtype = PV_TYPE_SUBVOL
|
115 |
| - # 'latest' finds a place here, because only till 0.5.0 version |
116 |
| - # we had 'latest' as a separate version. After that, 'latest' is |
117 |
| - # just a link to latest version. |
118 |
| - if KADALU_VERSION in ["0.5.0", "0.4.0", "0.3.0"]: |
119 |
| - for vol_capability in request.volume_capabilities: |
120 |
| - # using getattr to avoid Pylint error |
121 |
| - single_node_writer = getattr(csi_pb2.VolumeCapability.AccessMode, |
122 |
| - "SINGLE_NODE_WRITER") |
123 |
| - |
124 |
| - if vol_capability.access_mode.mode == single_node_writer: |
125 |
| - pvtype = PV_TYPE_VIRTBLOCK |
| 121 | + |
| 122 | + # Mounted BlockVolume is requested via Storage Class. |
| 123 | + # GlusterFS File Volume may not be useful for some workloads |
| 124 | + # they can request for the Virtual Block formated and mounted |
| 125 | + # as default MountVolume. |
| 126 | + if request.parameters.get("pv_type", "").lower() == "block": |
| 127 | + pvtype = PV_TYPE_VIRTBLOCK |
| 128 | + |
| 129 | + single_node_writer = getattr(csi_pb2.VolumeCapability.AccessMode, |
| 130 | + "SINGLE_NODE_WRITER") |
| 131 | + |
| 132 | + # Multi node writer is not allowed for PV_TYPE_VIRTBLOCK |
| 133 | + if pvc_access_mode(request) != single_node_writer: |
| 134 | + errmsg = "Only SINGLE_NODE_WRITER is allowed for block Volume" |
| 135 | + logging.error(errmsg) |
| 136 | + context.set_details(errmsg) |
| 137 | + context.set_code(grpc.StatusCode.INVALID_ARGUMENT) |
| 138 | + return csi_pb2.CreateVolumeResponse() |
126 | 139 |
|
127 | 140 | logging.debug(logf(
|
128 | 141 | "Found PV type",
|
@@ -235,8 +248,8 @@ def CreateVolume(self, request, context):
|
235 | 248 | return csi_pb2.CreateVolumeResponse()
|
236 | 249 |
|
237 | 250 | if pvtype == PV_TYPE_VIRTBLOCK:
|
238 |
| - vol = create_virtblock_volume( |
239 |
| - mntdir, request.name, pvsize) |
| 251 | + vol = create_block_volume( |
| 252 | + pvtype, mntdir, request.name, pvsize) |
240 | 253 | else:
|
241 | 254 | use_gluster_quota = False
|
242 | 255 | if (os.path.isfile("/etc/secret-volume/ssh-privatekey") \
|
@@ -335,8 +348,8 @@ def CreateVolume(self, request, context):
|
335 | 348 |
|
336 | 349 | mntdir = os.path.join(HOSTVOL_MOUNTDIR, hostvol)
|
337 | 350 | if pvtype == PV_TYPE_VIRTBLOCK:
|
338 |
| - vol = create_virtblock_volume( |
339 |
| - mntdir, request.name, pvsize) |
| 351 | + vol = create_block_volume( |
| 352 | + pvtype, mntdir, request.name, pvsize) |
340 | 353 | else:
|
341 | 354 | use_gluster_quota = False
|
342 | 355 | vol = create_subdir_volume(
|
|
0 commit comments