Skip to content

Commit

Permalink
Simplify volume usage with containerop
Browse files Browse the repository at this point in the history
  • Loading branch information
swiftdiaries committed Feb 5, 2019
1 parent 9651a86 commit e4ecf7e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sdk/python/kfp/onprem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

def use_local_volume(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(use_local_volume('claim-name', 'pipeline', '/mnt/pipeline'))
"""
def _use_local_volume(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 _use_local_volume

0 comments on commit e4ecf7e

Please sign in to comment.