diff --git a/pkg/util/mount/BUILD b/pkg/util/mount/BUILD index 75a91b324b0..a30c6992e22 100644 --- a/pkg/util/mount/BUILD +++ b/pkg/util/mount/BUILD @@ -22,6 +22,7 @@ go_library( tags = ["automanaged"], deps = [ "//pkg/util/exec:go_default_library", + "//pkg/util/sets:go_default_library", "//vendor:github.com/golang/glog", ], ) diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index f6919f0acd0..1e261e13e69 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -30,7 +30,7 @@ import ( const ( // Default mount command if mounter path is not specified - mount = "mount" + defaultMountCommand = "mount" ) type Interface interface { @@ -105,7 +105,7 @@ func New() Interface { func NewCustomMounter(mounterPath, mounterRootfsPath string) Interface { // If mounter-path flag is not set, use default mount path if mounterPath == "" { - mounterPath = mount + mounterPath = defaultMountCommand } if mounterRootfsPath == "" { mounterRootfsPath = "/" diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index 2c7f12d6aed..ec424159207 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -25,13 +25,13 @@ import ( "io" "os" "os/exec" - "path" "strconv" "strings" "syscall" "github.com/golang/glog" utilExec "k8s.io/kubernetes/pkg/util/exec" + "k8s.io/kubernetes/pkg/util/sets" ) const ( @@ -63,18 +63,24 @@ type Mounter struct { // type, where kernel handles fs type for you. The mount 'options' is a list of options, // currently come from mount(8), e.g. "ro", "remount", "bind", etc. If no more option is // required, call Mount with an empty string list or nil. -// Update source path to include a root filesystem override to make a containerized mounter (specified via `mounterPath`) work. func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error { + // Path to mounter binary. Set to mount accessible via $PATH by default. + // All Linux distros are expected to be shipped with a mount utility that an support bind mounts. + mounterPath := defaultMountCommand bind, bindRemountOpts := isBind(options) if bind { - err := doMount(mounter.mounterPath, path.Join(mounter.mounterRootfsPath, source), path.Join(mounter.mounterRootfsPath, target), fstype, []string{"bind"}) + err := doMount(mounterPath, source, target, fstype, []string{"bind"}) if err != nil { return err } - return doMount(mounter.mounterPath, path.Join(mounter.mounterRootfsPath, source), path.Join(mounter.mounterRootfsPath, target), fstype, bindRemountOpts) - } else { - return doMount(mounter.mounterPath, source, path.Join(mounter.mounterRootfsPath, target), fstype, options) + return doMount(mounterPath, source, target, fstype, bindRemountOpts) } + // These filesystem types are expected to be supported by the mount utility on the host across all Linux distros. + var defaultMounterFsTypes = sets.NewString("tmpfs", "ext4", "ext3", "ext2") + if !defaultMounterFsTypes.Has(fstype) { + mounterPath = mounter.mounterPath + } + return doMount(mounterPath, source, target, fstype, options) } // isBind detects whether a bind mount is being requested and makes the remount options to