From 3fc5601e35d9232cc339a2b6a77ea86b14d3459b Mon Sep 17 00:00:00 2001 From: Ian Chakeres Date: Thu, 29 Mar 2018 14:17:07 -0700 Subject: [PATCH] Return error in mount_unsupported for unsupported platforms --- pkg/util/mount/mount_unsupported.go | 39 ++++++++++++++++------------- pkg/volume/fc/fc_test.go | 5 +++- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/pkg/util/mount/mount_unsupported.go b/pkg/util/mount/mount_unsupported.go index acad6eae03..9a2f8418e7 100644 --- a/pkg/util/mount/mount_unsupported.go +++ b/pkg/util/mount/mount_unsupported.go @@ -21,12 +21,16 @@ package mount import ( "errors" "os" + + "github.com/golang/glog" ) type Mounter struct { mounterPath string } +var unsupportedErr = errors.New("util/mount on this platform is not supported") + // New returns a mount.Interface for the current system. // It provides options to override the default mounter behavior. // mounterPath allows using an alternative to `/bin/mount` for mounting. @@ -37,21 +41,21 @@ func New(mounterPath string) Interface { } func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error { - return nil + return unsupportedErr } func (mounter *Mounter) Unmount(target string) error { - return nil + return unsupportedErr } // GetMountRefs finds all other references to the device referenced // by mountPath; returns a list of paths. func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { - return []string{}, nil + return []string{}, unsupportedErr } func (mounter *Mounter) List() ([]MountPoint, error) { - return []MountPoint{}, nil + return []MountPoint{}, unsupportedErr } func (mounter *Mounter) IsMountPointMatch(mp MountPoint, dir string) bool { @@ -63,27 +67,27 @@ func (mounter *Mounter) IsNotMountPoint(dir string) (bool, error) { } func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) { - return true, nil + return true, unsupportedErr } func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return "", nil + return "", unsupportedErr } func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { - return "", nil + return "", unsupportedErr } func (mounter *Mounter) DeviceOpened(pathname string) (bool, error) { - return false, nil + return false, unsupportedErr } func (mounter *Mounter) PathIsDevice(pathname string) (bool, error) { - return true, nil + return true, unsupportedErr } func (mounter *Mounter) MakeRShared(path string) error { - return nil + return unsupportedErr } func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, fstype string, options []string) error { @@ -91,33 +95,34 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, } func (mounter *SafeFormatAndMount) diskLooksUnformatted(disk string) (bool, error) { - return true, nil + return true, unsupportedErr } func (mounter *Mounter) GetFileType(pathname string) (FileType, error) { - return FileType("fake"), errors.New("not implemented") + return FileType("fake"), unsupportedErr } func (mounter *Mounter) MakeDir(pathname string) error { - return nil + return unsupportedErr } func (mounter *Mounter) MakeFile(pathname string) error { - return nil + return unsupportedErr } func (mounter *Mounter) ExistsPath(pathname string) bool { + glog.Errorf("%s", unsupportedErr) return true } func (mounter *Mounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { - return subPath.Path, nil, nil + return subPath.Path, nil, unsupportedErr } func (mounter *Mounter) CleanSubPaths(podDir string, volumeName string) error { - return nil + return unsupportedErr } func (mounter *Mounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error { - return nil + return unsupportedErr } diff --git a/pkg/volume/fc/fc_test.go b/pkg/volume/fc/fc_test.go index 80e3cd6392..ecc4155c7f 100644 --- a/pkg/volume/fc/fc_test.go +++ b/pkg/volume/fc/fc_test.go @@ -441,7 +441,10 @@ func Test_ConstructVolumeSpec(t *testing.T) { "/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~fc/fc-in-pod2", } for _, path := range mountPaths { - refs, _ := mount.GetMountRefs(fm, path) + refs, err := mount.GetMountRefs(fm, path) + if err != nil { + t.Errorf("couldn't get mountrefs. err: %v", err) + } var globalPDPath string for _, ref := range refs { if strings.Contains(ref, "kubernetes.io/fc") {