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: 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')