Fixes getNestedMountpoints grouping

Currently, getNestedMountpoints sorts using sort.Strings, which would
sort the following strings in this exact order:

/dir/nested, /dir/nested-vol, /dir/nested.vol, /dir/nested/double, /dir/nested2

Because of this, "nested/double" is returned as well, even though it shouldn't
have been. This issue is worse on Windows, where the path separator is typically
the backslash.

This commit addresses this issue by checking if a nested mount point has been
previously seen or not.
This commit is contained in:
Claudiu Belu
2022-09-09 04:20:28 -07:00
parent 127f33f63d
commit 6e9f428547
2 changed files with 22 additions and 5 deletions

View File

@@ -89,7 +89,7 @@ func TestGetNestedMountpoints(t *testing.T) {
{
name: "Unsorted Nested Pod",
err: false,
expected: sets.NewString("nested", "nested2"),
expected: sets.NewString("nested", "nested2", "nested-vol", "nested.vol"),
volname: "vol1",
pod: v1.Pod{
ObjectMeta: metav1.ObjectMeta{
@@ -105,6 +105,9 @@ func TestGetNestedMountpoints(t *testing.T) {
{MountPath: "/dir/nested", Name: "vol2"},
{MountPath: "/ignore2", Name: "vol5"},
{MountPath: "/dir", Name: "vol1"},
{MountPath: "/dir/nested-vol", Name: "vol6"},
{MountPath: "/dir/nested.vol", Name: "vol7"},
{MountPath: "/dir/nested2/double", Name: "vol8"},
{MountPath: "/dir/nested2", Name: "vol3"},
},
},