From 06072030d6703b3f06748682771915b2c7d28ae3 Mon Sep 17 00:00:00 2001 From: John Bradley Date: Tue, 12 Mar 2019 14:06:23 -0400 Subject: [PATCH 1/2] add failing test for mount with traiing slash --- tests/test_job.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_job.py b/tests/test_job.py index 619d27d..f98ce90 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -115,6 +115,10 @@ def test_calculates_subpath_with_parent_subpath(self): subpath = KubernetesVolumeBuilder.calculate_subpath('/prefix/1/foo', '/prefix/1', 'basedir') self.assertEqual('basedir/foo', subpath) + def test_calculates_subpath_with_parent_subpath_with_trailing_slash(self): + subpath = KubernetesVolumeBuilder.calculate_subpath('/prefix/1/foo', '/prefix/1/', 'basedir') + self.assertEqual('basedir/foo', subpath) + def test_add_rw_volume_binding(self): self.assertEqual(0, len(self.volume_builder.volumes)) self.volume_builder.add_persistent_volume_entry('/prefix/1', None, 'claim1') From 1ffbbf555c77259f39312d7f877cca322bc81388 Mon Sep 17 00:00:00 2001 From: John Bradley Date: Tue, 12 Mar 2019 14:07:46 -0400 Subject: [PATCH 2/2] change to allow slash or unslashed mount prefix --- calrissian/job.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/calrissian/job.py b/calrissian/job.py index e361ee4..b773018 100644 --- a/calrissian/job.py +++ b/calrissian/job.py @@ -112,7 +112,8 @@ def find_persistent_volume(self, source): @staticmethod def calculate_subpath(source, prefix, parent_sub_path): - source_without_prefix = source[len(prefix) + 1:] + slashed_prefix = os.path.join(prefix, '') # add '/' to end of prefix if it is not there already + source_without_prefix = source[len(slashed_prefix):] if parent_sub_path: return '{}/{}'.format(parent_sub_path, source_without_prefix) else: