Example #1
0
def fake_v1_persistent_volume_claim_error():
    return client.V1PersistentVolumeClaim(
        api_version='v1',
        kind='PersistentVolumeClaim',
        metadata=client.V1ObjectMeta(name='curry-test001',
                                     namespace='curryns'),
        status=client.V1PersistentVolumeClaimStatus(phase='Bound1'))
        def my_pipeline(param):
            resource_metadata = k8s_client.V1ObjectMeta(name="my-resource")
            k8s_resource = k8s_client.V1PersistentVolumeClaim(
                api_version="v1",
                kind="PersistentVolumeClaim",
                metadata=resource_metadata)
            res = ResourceOp(name="resource",
                             k8s_resource=k8s_resource,
                             success_condition=param,
                             attribute_outputs={"test": "attr"})

            self.assertCountEqual([x.name for x in res.inputs], ["param"])
            self.assertEqual(res.name, "resource")
            self.assertEqual(res.resource.success_condition, param)
            self.assertEqual(res.resource.action, "create")
            self.assertEqual(res.resource.failure_condition, None)
            self.assertEqual(res.resource.manifest, None)
            expected_attribute_outputs = {
                "manifest": "{}",
                "name": "{.metadata.name}",
                "test": "attr"
            }
            self.assertEqual(res.attribute_outputs, expected_attribute_outputs)
            expected_outputs = {
                "manifest": PipelineParam(name="manifest", op_name=res.name),
                "name": PipelineParam(name="name", op_name=res.name),
                "test": PipelineParam(name="test", op_name=res.name),
            }
            self.assertEqual(res.outputs, expected_outputs)
            self.assertEqual(res.output,
                             PipelineParam(name="test", op_name=res.name))
            self.assertEqual(res.dependent_names, [])
Example #3
0
 def deploy_volume_claim(
     self,
     labels={},
     name_suffix="",
     ports=None,
     env=None,
 ):
     volume_claim = self.get_volume_claim(labels)
     if not volume_claim:
         self.logger.info("creating volume claim (%s) ..." % name_suffix)
         storage_class_name = None
         if self.environment.storage_class:
             storage_class_name = self.environment.storage_class
         volume_claim = self.core_api.create_namespaced_persistent_volume_claim(
             namespace=self.environment.namespace,
             body=kubernetes_client.V1PersistentVolumeClaim(
                 api_version="v1",
                 kind="PersistentVolumeClaim",
                 metadata=kubernetes_client.V1ObjectMeta(
                     name=self.generate_object_name(name_suffix),
                     namespace=self.environment.namespace,
                     labels=self.generate_object_labels(labels),
                 ),
                 spec=kubernetes_client.V1PersistentVolumeClaimSpec(
                     access_modes=["ReadWriteOnce"],
                     resources=kubernetes_client.V1ResourceRequirements(
                         requests={
                             "storage": "1Gi",
                         }, ),
                     storage_class_name=storage_class_name,
                 ),
             ),
         )
     return volume_claim
def create_volume_claim_template():
    return client.V1PersistentVolumeClaim(
        metadata=client.V1ObjectMeta(name="data"),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=["ReadWriteOnce"],
            resources=client.V1ResourceRequirements(
                requests={"storage": "1Gi"})))
Example #5
0
    def create(self, vc_spec=None):
        """Creates a volume claim on the cluster.

        Args:
            vc_spec: A dictionary of keyword arguments that will be passed to V1PersistentVolumeClaimSpec()

        Returns: A dictionary containing the results of creating the volume claim on the cluster.

        """
        if vc_spec is None:
            vc_spec = self.vc_spec

        # Convert claim name to lower case
        claim_name = str(self.name).lower()
        vc_body = client.V1PersistentVolumeClaim()
        vc_body.metadata = client.V1ObjectMeta(namespace=self.namespace,
                                               name=claim_name)
        resources = client.V1ResourceRequirements(
            requests={'storage': str(self.disk_space) + 'Gi'})
        vc_body.spec = client.V1PersistentVolumeClaimSpec(resources=resources,
                                                          **vc_spec)
        self.creation_response = api_request(
            api.create_namespaced_persistent_volume_claim, self.namespace,
            vc_body)
        return self.creation_response
Example #6
0
def create_clone_pvc(pvc_values, sc_name, pvc_name, from_pvc_name,
                     created_objects):
    api_instance = client.CoreV1Api()
    pvc_metadata = client.V1ObjectMeta(name=pvc_name)
    pvc_resources = client.V1ResourceRequirements(
        requests={"storage": pvc_values["storage"]})
    pvc_data_source = client.V1TypedLocalObjectReference(
        kind="PersistentVolumeClaim", name=from_pvc_name)

    pvc_spec = client.V1PersistentVolumeClaimSpec(
        access_modes=[pvc_values["access_modes"]],
        resources=pvc_resources,
        storage_class_name=sc_name,
        data_source=pvc_data_source)

    pvc_body = client.V1PersistentVolumeClaim(api_version="v1",
                                              kind="PersistentVolumeClaim",
                                              metadata=pvc_metadata,
                                              spec=pvc_spec)

    try:
        LOGGER.info(
            f'PVC Create from Clone : Creating pvc {pvc_name} with parameters {str(pvc_values)} and storageclass {str(sc_name)} from PVC {from_pvc_name}'
        )
        api_response = api_instance.create_namespaced_persistent_volume_claim(
            namespace=namespace_value, body=pvc_body, pretty=True)
        LOGGER.debug(str(api_response))
        created_objects["clone_pvc"].append(pvc_name)
    except ApiException as e:
        LOGGER.info(f'PVC {pvc_name} creation operation has been failed')
        LOGGER.error(
            f"Exception when calling CoreV1Api->create_namespaced_persistent_volume_claim: {e}"
        )
        cleanup.clean_with_created_objects(created_objects)
        assert False
    def create(self, body, namespace, wait=False, timeout=300):
        """ Create PersistentVolumeClaim resource """
        pvc_body = core_sdk.V1PersistentVolumeClaim().to_dict()
        pvc_body.update(copy.deepcopy(body))
        created_pvc = self.__client.create_namespaced_persistent_volume_claim(
            namespace=namespace, body=pvc_body)
        if not wait:
            return created_pvc

        w = watch.Watch()
        for event in w.stream(
                self.__client.list_namespaced_persistent_volume_claim,
                namespace=namespace,
                field_selector='metadata.name=' + pvc_body['metadata']['name'],
                timeout_seconds=timeout):
            entity = event['object']
            metadata = entity.metadata
            if entity.status.phase == 'Bound':
                annotations = metadata.annotations if \
                    metadata.annotations else {}
                IMPORT_STATUS_KEY = 'cdi.kubevirt.io/storage.import.pod.phase'
                import_status = annotations.get(IMPORT_STATUS_KEY)
                labels = metadata.labels if metadata.labels else {}
                if (not _use_cdi(annotations, labels)
                        or import_status == 'Succeeded'):
                    w.stop()
                    return entity
                elif entity.status.phase == 'Failed':
                    w.stop()
                    raise Exception("Failed to import PersistentVolumeClaim")
        raise Exception("Timeout exceed while waiting on result state of the \
                        entity.")
Example #8
0
 def _create_pvc_for_pv(self, vol):
     name = vol.metadata.name
     namespace = self.get_user_namespace()
     pvcname = name
     pvd = client.V1PersistentVolumeClaim(
         spec=client.V1PersistentVolumeClaimSpec(
             volume_name=name,
             access_modes=vol.spec.access_modes,
             resources=client.V1ResourceRequirements(
                 requests=vol.spec.capacity),
             selector=client.V1LabelSelector(match_labels={"name": name}),
             storage_class_name=vol.spec.storage_class_name))
     md = client.V1ObjectMeta(name=pvcname, labels={"name": pvcname})
     pvd.metadata = md
     self.log.info("Creating PVC '%s' in namespace '%s'" %
                   (pvcname, namespace))
     try:
         self.api.create_namespaced_persistent_volume_claim(namespace, pvd)
     except ApiException as e:
         if e.status != 409:
             self.log.exception("Create PVC '%s' " % pvcname +
                                "in namespace '%s' " % namespace +
                                "failed: %s" % str(e))
             raise
         else:
             self.log.info("PVC '%s' " % pvcname +
                           "in namespace '%s' " % namespace +
                           "already exists.")
Example #9
0
    def test_get_name_from_created_pvc(self):
        """Return the name of the PVC, if one is provided."""
        pvc = client.V1PersistentVolumeClaim(
            metadata=client.V1ObjectMeta(name=PVC_NAME), )

        self.assertEqual(volumes.get_volume_name(self.api_volume_new, pvc),
                         PVC_NAME)
Example #10
0
def create_datavol_pvc(body, i):
  # body: Dict (request body)
  pvc_nm = body["vol_name" + i]

  # Create a PVC if its a new Data Volume
  if body["vol_type" + i] == "New":
    size = body["vol_size" + i] + "Gi"
    mode = body["vol_access_modes" + i]

    pvc = client.V1PersistentVolumeClaim(
        metadata=client.V1ObjectMeta(
            name=pvc_nm,
            namespace=body["ns"]
        ),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=[mode],
            resources=client.V1ResourceRequirements(
                requests={
                    "storage": size
                }
            )
        )
    )

    create_pvc(pvc)

  return
Example #11
0
def create_workspace_pvc(body):
    # If the type is New, then create a new PVC, else use an existing one
    # It always deletes the current one and creates a new
    annotations = {
        "rok/creds-secret-name": rok_secret_name(),
        "jupyter-workspace": body["ws_name"],
    }

    if body["ws_type"] == "Existing":
        annotations['rok/origin'] = body["ws_rok_url"]

    labels = {"component": "singleuser-storage"}

    # Create a PVC for the New/Existing Type
    pvc = client.V1PersistentVolumeClaim(
        metadata=client.V1ObjectMeta(
            name=body['ws_name'],
            namespace=body['ns'],
            annotations=annotations,
            labels=labels,
        ),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=['ReadWriteOnce'],
            resources=client.V1ResourceRequirements(
                requests={'storage': body['ws_size'] + 'Gi'})))

    delete_existing_pvc(pvc.metadata.name, pvc.metadata.namespace)
    provision_new_pvc(pvc)
Example #12
0
def create_datavol_pvc(body, i):
    # It always deletes the current one and creates a new
    pvc_nm = body['vol_name' + i]
    size = body['vol_size' + i] + 'Gi'

    annotations = {
        "rok/creds-secret-name": rok_secret_name(),
        "jupyter-dataset": pvc_nm,
    }

    if body["ws_type"] == "Existing":
        annotations['rok/origin'] = body["vol_rok_url" + i]

    labels = {"component": "singleuser-storage"}

    # Create a PVC for the New/Existing Type
    pvc = client.V1PersistentVolumeClaim(
        metadata=client.V1ObjectMeta(
            name=pvc_nm,
            namespace=body['ns'],
            annotations=annotations,
            labels=labels,
        ),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=['ReadWriteOnce'],
            resources=client.V1ResourceRequirements(
                requests={'storage': size})))

    delete_existing_pvc(pvc.metadata.name, pvc.metadata.namespace)
    provision_new_pvc(pvc)
Example #13
0
def fxt_pvc(test_namespace):
    pvc_name = "pvc-test"
    api = client.CoreV1Api()
    pvc_body = client.V1PersistentVolumeClaim(
        api_version="v1",
        kind="PersistentVolumeClaim",
        metadata=client.V1ObjectMeta(name=pvc_name, ),
        spec=client.V1PersistentVolumeClaimSpec(
            storage_class_name="nfss1",
            access_modes=["ReadWriteMany"],
            resources=client.V1ResourceRequirements(
                requests={"storage": "1Gi"}),
        ),
    )

    try:
        response = api.create_namespaced_persistent_volume_claim(
            namespace=test_namespace, body=pvc_body)
    except ApiException as e:
        logging.error("That didn't work: %s" % e)

    pvcs = api.list_namespaced_persistent_volume_claim(
        namespace=test_namespace)
    logging.info(
        f"PVC {pvcs.items[0].metadata.name} currently {pvcs.items[0].status.phase}"
    )
    assert len(pvcs.items) == 1

    yield pvc_name
    logging.info("Destroying PersistentVolumeClaim")
    delete_pvc = api.delete_namespaced_persistent_volume_claim(
        name="pvc-test", namespace=test_namespace)
    assert delete_pvc, "Unable to delete PVC"
Example #14
0
def create_k8s_pvc(namespace: str, name: str, access_modes: tuple,
                   storage_class_name: str, size: str, user):
    """
    Create a Kubernetes persistent volume claim in a namespace in the cluster.
    An existing pvc with this name in this namespace leads to a no-op.

    Returns the new pvc.
    """
    core_v1 = get_user_core_v1(user)
    try:
        k8s_spec = client.V1PersistentVolumeClaimSpec(
            access_modes=access_modes,
            storage_class_name=storage_class_name,
            resources=client.V1ResourceRequirements(
                requests={'storage': size}))
        k8s_pvc = client.V1PersistentVolumeClaim(
            api_version="v1",
            kind="PersistentVolumeClaim",
            metadata=client.V1ObjectMeta(name=name),
            spec=k8s_spec)
        core_v1.create_namespaced_persistent_volume_claim(namespace=namespace,
                                                          body=k8s_pvc)
        logger.info(f"Created Kubernetes pvc '{namespace}:{name}'")
    except client.rest.ApiException as e:
        if e.status == 409:
            logger.warning(
                f"Tried to create already existing Kubernetes pvc '{namespace}:{name}'. Skipping the creation and using the existing one."
            )
        else:
            raise e
    return core_v1.read_namespaced_persistent_volume_claim(namespace=namespace,
                                                           name=name)
Example #15
0
    def create_k8s_nfs_resources(self) -> bool:
        """
        Create NFS resources such as PV and PVC in Kubernetes.
        """
        from kubernetes import client as k8sclient

        pv_name = "nfs-ckpt-pv-{}".format(uuid.uuid4())
        persistent_volume = k8sclient.V1PersistentVolume(
            api_version="v1",
            kind="PersistentVolume",
            metadata=k8sclient.V1ObjectMeta(
                name=pv_name,
                labels={'app': pv_name}
            ),
            spec=k8sclient.V1PersistentVolumeSpec(
                access_modes=["ReadWriteMany"],
                nfs=k8sclient.V1NFSVolumeSource(
                    path=self.params.path,
                    server=self.params.server
                ),
                capacity={'storage': '10Gi'},
                storage_class_name=""
            )
        )
        k8s_api_client = k8sclient.CoreV1Api()
        try:
            k8s_api_client.create_persistent_volume(persistent_volume)
            self.params.pv_name = pv_name
        except k8sclient.rest.ApiException as e:
            print("Got exception: %s\n while creating the NFS PV", e)
            return False

        pvc_name = "nfs-ckpt-pvc-{}".format(uuid.uuid4())
        persistent_volume_claim = k8sclient.V1PersistentVolumeClaim(
            api_version="v1",
            kind="PersistentVolumeClaim",
            metadata=k8sclient.V1ObjectMeta(
                name=pvc_name
            ),
            spec=k8sclient.V1PersistentVolumeClaimSpec(
                access_modes=["ReadWriteMany"],
                resources=k8sclient.V1ResourceRequirements(
                    requests={'storage': '10Gi'}
                ),
                selector=k8sclient.V1LabelSelector(
                    match_labels={'app': self.params.pv_name}
                ),
                storage_class_name=""
            )
        )

        try:
            k8s_api_client.create_namespaced_persistent_volume_claim(self.params.namespace, persistent_volume_claim)
            self.params.pvc_name = pvc_name
        except k8sclient.rest.ApiException as e:
            print("Got exception: %s\n while creating the NFS PVC", e)
            return False

        return True
Example #16
0
def get_persistent_volume_claim(namespace, volume):
    vol_name = constants.VOLUME_CLAIM_NAME.format(vol_name=volume)
    metadata = client.V1ObjectMeta(name=vol_name, labels=get_labels(volume), namespace=namespace)
    spec = get_persistent_volume_claim_spec(volume)
    return client.V1PersistentVolumeClaim(api_version=k8s_constants.K8S_API_VERSION_V1,
                                          kind=k8s_constants.K8S_PERSISTENT_VOLUME_CLAIM_KIND,
                                          metadata=metadata,
                                          spec=spec)
 def k8s_object(self):
     return client.V1PersistentVolumeClaim(
         spec=client.V1PersistentVolumeClaimSpec(
             access_modes=["ReadWriteOnce"],
             resources=client.V1ResourceRequirements(
                 requests={"storage": self.storage})),
         metadata=client.V1ObjectMeta(name=self.name,
                                      namespace=self.namespace))
Example #18
0
 def _load_pvcs(self):
     pvcs = []
     names = ['project-foo', 'project-bar']
     for name in names:
         pvc = client.V1PersistentVolumeClaim()
         pvc.metadata = client.V1ObjectMeta(namespace=self.namespace, name=name)
         pvcs.append(pvc)
     return client.V1PersistentVolumeClaimList(items=pvcs)
Example #19
0
    def create(self, name, spec):
        body = client.V1PersistentVolumeClaim()
        body.spec = spec

        body.metadata = self.create_metadata(name)

        return self.v1api.create_namespaced_persistent_volume_claim(
            self.namespace, body)
Example #20
0
    def _get_pvc_body(self, name, storage, namespace):
        spec = self._get_spec_pvc(name, storage)

        return client.V1PersistentVolumeClaim(api_version="v1",
                                              kind="PersistentVolumeClaim",
                                              metadata=client.V1ObjectMeta(
                                                  name=name,
                                                  namespace=namespace),
                                              spec=spec)
Example #21
0
def simple_persistentvolumeclaim():
    """Return the Kubernetes config matching the simple-persistentvolumeclaim.yaml manifest."""
    return client.V1PersistentVolumeClaim(
        api_version='v1',
        kind='PersistentVolumeClaim',
        metadata=client.V1ObjectMeta(name='my-pvc'),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=['ReadWriteMany'],
            resources=client.V1ResourceRequirements(
                requests={'storage': '16Mi'})))
Example #22
0
 def create_persistent_volume_claim(self, name, storage_size_in_g,
                                    access_modes=["ReadWriteMany"],
                                    storage_class_name="glusterfs-storage"):
     pvc = client.V1PersistentVolumeClaim()
     pvc.metadata = client.V1ObjectMeta(name=name)
     storage_size = "{}Gi".format(storage_size_in_g)
     resources = client.V1ResourceRequirements(requests={"storage": storage_size})
     pvc.spec = client.V1PersistentVolumeClaimSpec(access_modes=access_modes,
                                                   resources=resources,
                                                   storage_class_name=storage_class_name)
     return self.core.create_namespaced_persistent_volume_claim(self.namespace, pvc)
Example #23
0
def post_pvc(namespace):
    body = request.get_json()

    pvc = client.V1PersistentVolumeClaim(
        metadata=client.V1ObjectMeta(name=body['name'], namespace=namespace),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=[body['mode']],
            resources=client.V1ResourceRequirements(
                requests={'storage': body['size'] + 'Gi'})))

    return jsonify(api.post_pvc(pvc))
Example #24
0
def post_pvc(namespace):
    body = request.get_json()

    pvc = client.V1PersistentVolumeClaim(
        metadata=client.V1ObjectMeta(name=body["name"], namespace=namespace),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=[body["mode"]],
            resources=client.V1ResourceRequirements(
                requests={"storage": body["size"] + "Gi"})))

    return jsonify(api.create_pvc(pvc, namespace=namespace))
Example #25
0
def create_pvc(pvc_values, sc_name, pvc_name, config_value=None, pv_name=None):
    """
    creates persistent volume claim

    Args:
        param1: pvc_values - values required for creation of pvc
        param2: sc_name - name of storage class , pvc associated with
                          if "notusingsc" no storage class
        param3: pvc_name - name of pvc to be created
        param4: config_value - configuration file
        param5: pv_name - name of pv , pvc associated with
                          if None , no pv is associated

    Returns:
        None

    Raises:
        Raises an exception on kubernetes client api failure and asserts

    """
    api_instance = client.CoreV1Api()
    pvc_metadata = client.V1ObjectMeta(name=pvc_name)
    pvc_resources = client.V1ResourceRequirements(
        requests={"storage": pvc_values["storage"]})
    if sc_name == "":
        global test
        test = config_value

    pvc_spec = client.V1PersistentVolumeClaimSpec(
        access_modes=[pvc_values["access_modes"]],
        resources=pvc_resources,
        storage_class_name=sc_name,
        volume_name=pv_name)

    pvc_body = client.V1PersistentVolumeClaim(api_version="v1",
                                              kind="PersistentVolumeClaim",
                                              metadata=pvc_metadata,
                                              spec=pvc_spec)

    try:
        LOGGER.info(
            f'Creating pvc {pvc_name} with parameters {str(pvc_values)} and storageclass {str(sc_name)}'
        )
        api_response = api_instance.create_namespaced_persistent_volume_claim(
            namespace=namespace_value, body=pvc_body, pretty=True)
        LOGGER.debug(str(api_response))
        LOGGER.info(f'PVC {pvc_name} has been created successfully')
    except ApiException as e:
        LOGGER.info(f'PVC {pvc_name} creation operation has been failed')
        LOGGER.error(
            f"Exception when calling CoreV1Api->create_namespaced_persistent_volume_claim: {e}"
        )
        assert False
Example #26
0
def simple_persistentvolumeclaim():
    """Return the Kubernetes config matching the simple-persistentvolumeclaim.yaml manifest."""
    return client.V1PersistentVolumeClaim(
        api_version="v1",
        kind="PersistentVolumeClaim",
        metadata=client.V1ObjectMeta(name="my-pvc"),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=["ReadWriteMany"],
            resources=client.V1ResourceRequirements(
                requests={"storage": "16Mi"}),
        ),
    )
Example #27
0
 def persistent_volume_claim(self, name, volume_name, storage, accessModes=["ReadWriteOnce"]):
     """Create a volume claim."""
     claim_vol = client.V1PersistentVolumeClaim(kind="PersistentVolumeClaim", api_version="v1")
     claim_vol.metadata = client.V1ObjectMeta(name=name)
     spec = client.V1PersistentVolumeClaimSpec(volume_name=volume_name, access_modes=accessModes, storage_class_name=volume_name)
     spec.resources = client.V1ResourceRequirements(requests={"storage": storage})
     claim_vol.spec = spec
     try:
         api_core.create_namespaced_persistent_volume_claim(namespace=self._namespace, body=claim_vol)
         LOG.info(f'Volume claim: {name} created.')
     except ApiException as e:
         LOG.error(f'Exception message: {e}')
 def get(self):
     return client.V1PersistentVolumeClaim(
         kind='PersistentVolumeClaim',
         api_version='v1',
         metadata=client.V1ObjectMeta(name='postgres-pvc',
                                      labels={'pvc': 'postgres'}),
         spec=client.V1PersistentVolumeClaimSpec(
             storage_class_name='manual',
             access_modes=['ReadWriteOnce'],
             resources=client.V1ResourceRequirements(
                 requests={'storage': '2Gi'}),
             volume_name='postgres-pv'))
Example #29
0
    def test_use_pvc_name_in_volume_source(self):
        """Use the PVC name and PVC source, when a PVC is provided."""
        pvc = client.V1PersistentVolumeClaim(
            metadata=client.V1ObjectMeta(name=PVC_NAME), )

        v1_volume = volumes.get_pod_volume(self.api_volume_existing, pvc)
        self.assertDictEqual(v1_volume, {
            "name": PVC_NAME,
            "persistentVolumeClaim": {
                "claimName": PVC_NAME,
            },
        })
Example #30
0
def create_pvc_from_snapshot(pvc_values, sc_name, pvc_name, snap_name,
                             created_objects):
    """
    creates persistent volume claim from snapshot

    Args:
        param1: pvc_values - values required for creation of pvc
        param2: sc_name - name of storage class , pvc associated with
        param3: pvc_name - name of pvc to be created
        param4: snap_name - name of snapshot to recover data from

    Returns:
        None

    Raises:
        Raises an exception on kubernetes client api failure and asserts

    """
    api_instance = client.CoreV1Api()
    pvc_metadata = client.V1ObjectMeta(name=pvc_name)
    pvc_resources = client.V1ResourceRequirements(
        requests={"storage": pvc_values["storage"]})
    pvc_data_source = client.V1TypedLocalObjectReference(
        api_group="snapshot.storage.k8s.io",
        kind="VolumeSnapshot",
        name=snap_name)

    pvc_spec = client.V1PersistentVolumeClaimSpec(
        access_modes=[pvc_values["access_modes"]],
        resources=pvc_resources,
        storage_class_name=sc_name,
        data_source=pvc_data_source)

    pvc_body = client.V1PersistentVolumeClaim(api_version="v1",
                                              kind="PersistentVolumeClaim",
                                              metadata=pvc_metadata,
                                              spec=pvc_spec)

    try:
        LOGGER.info(
            f'PVC Create from snapshot : Creating pvc {pvc_name} with parameters {str(pvc_values)} and storageclass {str(sc_name)}'
        )
        api_response = api_instance.create_namespaced_persistent_volume_claim(
            namespace=namespace_value, body=pvc_body, pretty=True)
        LOGGER.debug(str(api_response))
        created_objects["restore_pvc"].append(pvc_name)
    except ApiException as e:
        LOGGER.info(f'PVC {pvc_name} creation operation has been failed')
        LOGGER.error(
            f"Exception when calling CoreV1Api->create_namespaced_persistent_volume_claim: {e}"
        )
        cleanup.clean_with_created_objects(created_objects)
        assert False