Skip to content

Commit

Permalink
Add volume_id
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Feb 14, 2024
1 parent a497a7b commit 9f9de0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion IM/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ def _create_volume_claim(self, claim_data, auth_data):
def _create_volumes(self, namespace, system, pod_name, auth_data, persistent=False):
res = []
cont = 1
while (system.getValue("disk." + str(cont) + ".size") and
while ((system.getValue("disk." + str(cont) + ".size") or
system.getValue("disk." + str(cont) + ".image.url")) and
system.getValue("disk." + str(cont) + ".mount_path")):
volume_id = system.getValue("disk." + str(cont) + ".image.url")
disk_mount_path = system.getValue("disk." + str(cont) + ".mount_path")
disk_size = system.getFeature("disk." + str(cont) + ".size").getValue('B')
if not disk_mount_path.startswith('/'):
Expand All @@ -205,6 +207,10 @@ def _create_volumes(self, namespace, system, pod_name, auth_data, persistent=Fal
claim_data['spec'] = {'accessModes': ['ReadWriteOnce'], 'resources': {
'requests': {'storage': disk_size}}}

if volume_id:
claim_data['spec']['storageClassName'] = ""
claim_data['spec']['volumeName'] = volume_id

self.log_debug("Creating PVC: %s/%s" % (namespace, name))
success = self._create_volume_claim(claim_data, auth_data)
if success:
Expand Down
9 changes: 7 additions & 2 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,8 @@ def _gen_k8s_volumes(self, node, nodetemplates, value):
cont = 1
# volume format should be "volume_name:mount_path"
for vol in value:
size = None
volume_id = None
vol_parts = vol.split(":")
volume = vol_parts[0]
mount_path = None
Expand All @@ -2134,12 +2136,13 @@ def _gen_k8s_volumes(self, node, nodetemplates, value):
root_type = Tosca._get_root_parent_type(node).type
if root_type == "tosca.nodes.BlockStorage" and node.name == volume:
size = self._final_function_result(node.get_property_value('size'), node)
volume_id = self._final_function_result(node.get_property_value('volume_id'), node)

if size:
if not size.endswith("B"):
size += "B"
size = int(ScalarUnit_Size(size).get_num_from_scalar_unit('B'))
volumes.append((cont, size, mount_path))
volumes.append((cont, size, mount_path, volume_id))
cont += 1
return volumes

Expand Down Expand Up @@ -2192,7 +2195,9 @@ def _gen_k8s_system(self, node, nodetemplates):
value = int(ScalarUnit_Size(value).get_num_from_scalar_unit('B'))
res.setValue("memory.size", value, 'B')
elif prop.name == 'volumes':
for num, size, mount_path in self._gen_k8s_volumes(node, nodetemplates, value):
for num, size, mount_path, volume_id in self._gen_k8s_volumes(node, nodetemplates, value):
if volume_id:
res.setValue('disk.%d.image.url' % num, volume_id)
if size:
res.setValue('disk.%d.size' % num, size, 'B')
if mount_path:
Expand Down
2 changes: 2 additions & 0 deletions test/files/tosca_k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ topology_template:
type: tosca.nodes.BlockStorage
properties:
size: 10 GB
# Set the PV name in this field
# volume_id: "PV name"

0 comments on commit 9f9de0c

Please sign in to comment.