Merge pull request #129200 from carlory/remove-GetDeviceNameFromMount

Remove GetDeviceNameFromMount from HostUtils
This commit is contained in:
Kubernetes Prow Robot 2025-01-20 10:00:35 -08:00 committed by GitHub
commit e69a5ed9b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 77 deletions

View File

@ -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

View File

@ -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")