本文整理汇总了Python中kubernetes.client.V1PersistentVolumeClaim方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1PersistentVolumeClaim方法的具体用法?Python client.V1PersistentVolumeClaim怎么用?Python client.V1PersistentVolumeClaim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1PersistentVolumeClaim方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createKubePVC
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
def _createKubePVC(parser_args,CoreV1Api):
if parser_args.component=="search":
# {tenantName}-{environment}-search-master-gluster-volume
if parser_args.envtype == "auth":
_pvc_name=parser_args.tenant+parser_args.env+"-search-master-"+"volume"
elif parser_args.envtype == "live":
_pvc_name=parser_args.tenant+parser_args.env+"-search-repeater-"+"volume"
# Below config boby still need refine to accept more flexible extension
metadata = {'name': _pvc_name, 'namespace': parser_args.namespace}
requests = {'storage': parser_args.storage_size}
_V1ResourceRequirements=client.V1ResourceRequirements(requests=requests)
_V1PersistentVolumeClaimSpec=client.V1PersistentVolumeClaimSpec(resources=_V1ResourceRequirements,storage_class_name=parser_args.storage_class,access_modes=['ReadWriteMany'])
body = client.V1PersistentVolumeClaim(api_version='v1',kind='PersistentVolumeClaim', metadata=metadata,spec=_V1PersistentVolumeClaimSpec,) # V1PersistentVolumeClaim |
try:
api_response = CoreV1Api.create_namespaced_persistent_volume_claim(parser_args.namespace, body)
print(api_response)
except ApiException as e:
print("Exception when calling CoreV1Api->create_namespaced_persistent_volume_claim: %s\n" % e)
else:
print("Compoennt %s not need to create persistent volume chain on Kubernetes" %(parser_args.component))
示例2: simple_persistentvolumeclaim
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
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'
}
)
)
)
示例3: get_volume_claim_templates
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
def get_volume_claim_templates(self) -> Sequence[V1PersistentVolumeClaim]:
return [
V1PersistentVolumeClaim(
metadata=V1ObjectMeta(name=self.get_persistent_volume_name(volume)),
spec=V1PersistentVolumeClaimSpec(
# must be ReadWriteOnce for EBS
access_modes=["ReadWriteOnce"],
storage_class_name=self.get_storage_class_name(volume),
resources=V1ResourceRequirements(
requests={"storage": f"{volume['size']}Gi"}
),
),
)
for volume in self.get_persistent_volumes()
]
示例4: test_simple_persistentvolumeclaim_ok
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
def test_simple_persistentvolumeclaim_ok(
self,
manifest_dir,
simple_persistentvolumeclaim
):
"""Test loading the simple persistentvolumeclaim successfully."""
obj = manifest.load_type(
client.V1PersistentVolumeClaim,
os.path.join(manifest_dir, 'simple-persistentvolumeclaim.yaml')
)
assert obj == simple_persistentvolumeclaim
示例5: test_basic
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
def test_basic(self):
"""Test basic usage."""
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, [])
kfp.compiler.Compiler()._compile(my_pipeline)
示例6: _AssumeInsideKfp
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
def _AssumeInsideKfp(
self,
namespace='my-namespace',
pod_name='my-pod-name',
pod_uid='my-pod-uid',
pod_service_account_name='my-service-account-name',
with_pvc=False):
pod = k8s_client.V1Pod(
api_version='v1',
kind='Pod',
metadata=k8s_client.V1ObjectMeta(
name=pod_name,
uid=pod_uid,
),
spec=k8s_client.V1PodSpec(
containers=[
k8s_client.V1Container(
name='main',
volume_mounts=[]),
],
volumes=[]))
if with_pvc:
pod.spec.volumes.append(
k8s_client.V1Volume(
name='my-volume',
persistent_volume_claim=k8s_client
.V1PersistentVolumeClaimVolumeSource(
claim_name='my-pvc')))
pod.spec.containers[0].volume_mounts.append(
k8s_client.V1VolumeMount(
name='my-volume',
mount_path=self._base_dir))
mock.patch.object(kube_utils, 'is_inside_kfp', return_value=True).start()
pod.spec.service_account_name = pod_service_account_name
mock.patch.object(kube_utils, 'get_current_kfp_pod',
return_value=pod).start()
mock.patch.object(kube_utils, 'get_kfp_namespace',
return_value=namespace).start()
if with_pvc:
(self._mock_core_v1_api.read_namespaced_persistent_volume_claim
.return_value) = k8s_client.V1PersistentVolumeClaim(
metadata=k8s_client.V1ObjectMeta(
name='my-pvc'),
spec=k8s_client.V1PersistentVolumeClaimSpec(
access_modes=['ReadWriteMany']))
示例7: create_k8s_nfs_resources
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PersistentVolumeClaim [as 别名]
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