forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify volume usage with containerop (kubeflow#783)
change function name to mount_pvc
- Loading branch information
1 parent
11f7d15
commit 8046ee4
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
def mount_pvc(pvc_name='pipeline-claim', volume_name='pipeline', volume_mount_path='/mnt/pipeline'): | ||
""" | ||
Modifier function to apply to a Container Op to simplify volume, volume mount addition and | ||
enable better reuse of volumes, volume claims across container ops. | ||
Usage: | ||
train = train_op(...) | ||
train.apply(mount_pvc('claim-name', 'pipeline', '/mnt/pipeline')) | ||
""" | ||
def _mount_pvc(task): | ||
from kubernetes import client as k8s_client | ||
local_pvc = k8s_client.V1PersistentVolumeClaimVolumeSource(claim_name=pvc_name) | ||
return ( | ||
task | ||
.add_volume( | ||
k8s_client.V1Volume(name=volume_name, persistent_volume_claim=local_pvc) | ||
) | ||
.add_volume_mount( | ||
k8s_client.V1VolumeMount(mount_path=volume_mount_path, name=volume_name) | ||
) | ||
) | ||
return _mount_pvc |