Return error in mount_unsupported for unsupported platforms

This commit is contained in:
Ian Chakeres 2018-03-29 14:17:07 -07:00
parent cad4385cb0
commit 3fc5601e35
2 changed files with 26 additions and 18 deletions

View File

@ -21,12 +21,16 @@ package mount
import ( import (
"errors" "errors"
"os" "os"
"github.com/golang/glog"
) )
type Mounter struct { type Mounter struct {
mounterPath string mounterPath string
} }
var unsupportedErr = errors.New("util/mount on this platform is not supported")
// New returns a mount.Interface for the current system. // New returns a mount.Interface for the current system.
// It provides options to override the default mounter behavior. // It provides options to override the default mounter behavior.
// mounterPath allows using an alternative to `/bin/mount` for mounting. // 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 { func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error {
return nil return unsupportedErr
} }
func (mounter *Mounter) Unmount(target string) error { func (mounter *Mounter) Unmount(target string) error {
return nil return unsupportedErr
} }
// GetMountRefs finds all other references to the device referenced // GetMountRefs finds all other references to the device referenced
// by mountPath; returns a list of paths. // by mountPath; returns a list of paths.
func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { func GetMountRefs(mounter Interface, mountPath string) ([]string, error) {
return []string{}, nil return []string{}, unsupportedErr
} }
func (mounter *Mounter) List() ([]MountPoint, error) { func (mounter *Mounter) List() ([]MountPoint, error) {
return []MountPoint{}, nil return []MountPoint{}, unsupportedErr
} }
func (mounter *Mounter) IsMountPointMatch(mp MountPoint, dir string) bool { 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) { func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, nil return true, unsupportedErr
} }
func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) {
return "", nil return "", unsupportedErr
} }
func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) {
return "", nil return "", unsupportedErr
} }
func (mounter *Mounter) DeviceOpened(pathname string) (bool, error) { func (mounter *Mounter) DeviceOpened(pathname string) (bool, error) {
return false, nil return false, unsupportedErr
} }
func (mounter *Mounter) PathIsDevice(pathname string) (bool, error) { func (mounter *Mounter) PathIsDevice(pathname string) (bool, error) {
return true, nil return true, unsupportedErr
} }
func (mounter *Mounter) MakeRShared(path string) error { func (mounter *Mounter) MakeRShared(path string) error {
return nil return unsupportedErr
} }
func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, fstype string, options []string) error { 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) { func (mounter *SafeFormatAndMount) diskLooksUnformatted(disk string) (bool, error) {
return true, nil return true, unsupportedErr
} }
func (mounter *Mounter) GetFileType(pathname string) (FileType, error) { 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 { func (mounter *Mounter) MakeDir(pathname string) error {
return nil return unsupportedErr
} }
func (mounter *Mounter) MakeFile(pathname string) error { func (mounter *Mounter) MakeFile(pathname string) error {
return nil return unsupportedErr
} }
func (mounter *Mounter) ExistsPath(pathname string) bool { func (mounter *Mounter) ExistsPath(pathname string) bool {
glog.Errorf("%s", unsupportedErr)
return true return true
} }
func (mounter *Mounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { 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 { 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 { func (mounter *Mounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error {
return nil return unsupportedErr
} }

View File

@ -441,7 +441,10 @@ func Test_ConstructVolumeSpec(t *testing.T) {
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~fc/fc-in-pod2", "/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~fc/fc-in-pod2",
} }
for _, path := range mountPaths { 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 var globalPDPath string
for _, ref := range refs { for _, ref := range refs {
if strings.Contains(ref, "kubernetes.io/fc") { if strings.Contains(ref, "kubernetes.io/fc") {