Skip to content

Commit

Permalink
SDL - DSL - Stabilized the PipelineVolume names (#2794)
Browse files Browse the repository at this point in the history
The name no longer depends on unset parameters or the version of the Kubernetes package.
Needed for #2780
Fixes  https://travis-ci.com/kubeflow/pipelines/jobs/270786161
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Jan 4, 2020
1 parent cb7342c commit f39cbdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 10 additions & 1 deletion sdk/python/kfp/dsl/_pipeline_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
from . import _pipeline


def prune_none_dict_values(d: dict) -> dict:
return {
k: prune_none_dict_values(v) if isinstance(v, dict) else v
for k, v in d.items()
if v is not None
}


class PipelineVolume(V1Volume):
"""Representing a volume that is passed between pipeline operators and is
to be mounted by a ContainerOp or its inherited type.
Expand Down Expand Up @@ -72,7 +80,8 @@ def __init__(self,
init_volume["persistent_volume_claim"] = pvc_volume_source
super().__init__(**init_volume, **kwargs)
if not name_provided:
hash_value = hashlib.sha256(bytes(json.dumps(self.to_dict(),
volume_dict = prune_none_dict_values(self.to_dict())
hash_value = hashlib.sha256(bytes(json.dumps(volume_dict,
sort_keys=True),
"utf-8")).hexdigest()
name = "pvolume-{}".format(hash_value)
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/tests/dsl/pipeline_volume_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def test_omitting_name(self):
def my_pipeline(param='foo'):
vol1 = PipelineVolume(pvc="foo")
vol2 = PipelineVolume(name="provided", pvc="foo")
name1 = ("pvolume-127ac63cf2013e9b95c192eb6a2c7d5a023ebeb51f6a1144"
"86e3121")
name1 = ("pvolume-4cf668b8c7be134cfcbd7758d1eef9643d1bd7ed9925a98e707635b")
name2 = "provided"
self.assertEqual(vol1.name, name1)
self.assertEqual(vol2.name, name2)
Expand Down

0 comments on commit f39cbdc

Please sign in to comment.