diff --git a/pkg/volume/util/hostutil/hostutil.go b/pkg/volume/util/hostutil/hostutil.go index 4539afd7086..0e57821d3df 100644 --- a/pkg/volume/util/hostutil/hostutil.go +++ b/pkg/volume/util/hostutil/hostutil.go @@ -19,8 +19,6 @@ package hostutil import ( "fmt" "os" - - "k8s.io/mount-utils" ) // FileType enumerates the known set of possible file types. @@ -52,10 +50,6 @@ type HostUtils interface { DeviceOpened(pathname string) (bool, error) // PathIsDevice determines if a path is a device. PathIsDevice(pathname string) (bool, error) - // GetDeviceNameFromMount finds the device name by checking the mount path - // to get the global mount path within its plugin directory. - // TODO: Remove this method once the rbd and vsphere plugins are removed from in-tree. - GetDeviceNameFromMount(mounter mount.Interface, mountPath, pluginMountDir string) (string, error) // MakeRShared checks that given path is on a mount with 'rshared' mount // propagation. If not, it bind-mounts the path as rshared. MakeRShared(path string) error diff --git a/pkg/volume/util/hostutil/hostutil_test.go b/pkg/volume/util/hostutil/hostutil_test.go index 4e68c6f1a9a..c9a3beb95ac 100644 --- a/pkg/volume/util/hostutil/hostutil_test.go +++ b/pkg/volume/util/hostutil/hostutil_test.go @@ -17,7 +17,6 @@ limitations under the License. package hostutil import ( - "errors" "fmt" "net" "os" @@ -26,79 +25,9 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "k8s.io/mount-utils" "k8s.io/utils/exec" ) -// fakeMounter implements mount.Interface for tests. -type fakeMounter struct { - mount.FakeMounter - mountRefs []string - raiseError bool -} - -// GetMountRefs finds all mount references to the path, returns a -// list of paths. -func (f *fakeMounter) GetMountRefs(pathname string) ([]string, error) { - if f.raiseError { - return nil, errors.New("Expected error.") - } - - return f.mountRefs, nil -} - -func TestDeviceNameFromMount(t *testing.T) { - hu := NewHostUtil() - path := "/tmp/foo" - if goruntime.GOOS == "windows" { - path = "C:" + path - } - - testCases := map[string]struct { - mountRefs []string - expectedPath string - raiseError bool - expectedError string - }{ - "GetMountRefs error": { - raiseError: true, - expectedError: "Expected error.", - }, - "No Refs error": { - expectedError: fmt.Sprintf("directory %s is not mounted", path), - }, - "No Matching refs": { - mountRefs: []string{filepath.Join("foo", "lish")}, - expectedPath: filepath.Base(path), - }, - "Matched ref": { - mountRefs: []string{filepath.Join(path, "lish")}, - expectedPath: "lish", - }, - } - - for name, tc := range testCases { - t.Run(name, func(t *testing.T) { - mounter := &fakeMounter{ - mountRefs: tc.mountRefs, - raiseError: tc.raiseError, - } - - path, err := hu.GetDeviceNameFromMount(mounter, path, path) - if tc.expectedError != "" { - if err == nil || err.Error() != tc.expectedError { - t.Fatalf("expected error message `%s` but got `%v`", tc.expectedError, err) - } - return - } - - expectedPath := filepath.FromSlash(tc.expectedPath) - assert.Equal(t, expectedPath, path) - }) - } -} - func createSocketFile(socketDir string) (string, error) { testSocketFile := filepath.Join(socketDir, "mt.sock")