Skip to content

Commit

Permalink
SDK/DSL: Fix PipelineVolume name length (kubeflow#2739)
Browse files Browse the repository at this point in the history
* SDK/DSL: Fix PipelineVolume name length

Volume name must be no more than 63 characters

Signed-off-by: Ilias Katsakioris <elikatsis@arrikto.com>

* Change which part of the hash value we make use of

Signed-off-by: Ilias Katsakioris <elikatsis@arrikto.com>
  • Loading branch information
elikatsis authored and Jeffwan committed Dec 9, 2020
1 parent 3905f80 commit 650f94d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions sdk/python/kfp/dsl/_pipeline_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def __init__(self,
for attr in self.attribute_map.keys()}
else:
if "name" in kwargs:
if len(kwargs["name"]) > 63:
raise ValueError("PipelineVolume name must be no more than"
" 63 characters")
init_volume = {"name": kwargs.pop("name")}
else:
name_provided = False
Expand All @@ -69,9 +72,11 @@ def __init__(self,
init_volume["persistent_volume_claim"] = pvc_volume_source
super().__init__(**init_volume, **kwargs)
if not name_provided:
self.name = "pvolume-%s" % hashlib.sha256(
bytes(json.dumps(self.to_dict(), sort_keys=True), "utf-8")
).hexdigest()
hash_value = hashlib.sha256(bytes(json.dumps(self.to_dict(),
sort_keys=True),
"utf-8")).hexdigest()
name = "pvolume-{}".format(hash_value)
self.name = name[0:63] if len(name) > 63 else name
self.dependent_names = []

def after(self, *ops):
Expand Down
4 changes: 2 additions & 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,8 @@ def test_omitting_name(self):
def my_pipeline(param='foo'):
vol1 = PipelineVolume(pvc="foo")
vol2 = PipelineVolume(name="provided", pvc="foo")
name1 = ("pvolume-127ac63cf2013e9b95c192eb6a2c7d5a023ebeb51f6a114486e3"
"1216e083a563")
name1 = ("pvolume-127ac63cf2013e9b95c192eb6a2c7d5a023ebeb51f6a1144"
"86e3121")
name2 = "provided"
self.assertEqual(vol1.name, name1)
self.assertEqual(vol2.name, name2)
Expand Down

0 comments on commit 650f94d

Please sign in to comment.