Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKL - DSL - Stabilized the PipelineVolume names #2794

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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