diff --git a/IM/connectors/Kubernetes.py b/IM/connectors/Kubernetes.py index 5e500ea8..888951b7 100644 --- a/IM/connectors/Kubernetes.py +++ b/IM/connectors/Kubernetes.py @@ -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('/'): @@ -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: diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index 4db5d267..e6185901 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -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 @@ -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 @@ -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: diff --git a/test/files/tosca_k8s.yml b/test/files/tosca_k8s.yml index 3d84c463..b7d191f0 100644 --- a/test/files/tosca_k8s.yml +++ b/test/files/tosca_k8s.yml @@ -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"