Inject mounter into volume plugins
This commit is contained in:
@@ -30,21 +30,14 @@ import (
|
||||
|
||||
// This is the primary entrypoint for volume plugins.
|
||||
func ProbeVolumePlugins() []volume.VolumePlugin {
|
||||
return ProbeVolumePluginsWithMounter(mount.New())
|
||||
}
|
||||
|
||||
// ProbePluginsWithMounter is a convenience for testing other plugins which wrap this one.
|
||||
//FIXME: alternative: pass mount.Interface to all ProbeVolumePlugins() functions? Opinions?
|
||||
func ProbeVolumePluginsWithMounter(mounter mount.Interface) []volume.VolumePlugin {
|
||||
return []volume.VolumePlugin{
|
||||
&emptyDirPlugin{nil, mounter, false},
|
||||
&emptyDirPlugin{nil, mounter, true},
|
||||
&emptyDirPlugin{nil, false},
|
||||
&emptyDirPlugin{nil, true},
|
||||
}
|
||||
}
|
||||
|
||||
type emptyDirPlugin struct {
|
||||
host volume.VolumeHost
|
||||
mounter mount.Interface
|
||||
legacyMode bool // if set, plugin answers to the legacy name
|
||||
}
|
||||
|
||||
@@ -78,9 +71,8 @@ func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (plugin *emptyDirPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, opts volume.VolumeOptions) (volume.Builder, error) {
|
||||
// Inject real implementations here, test through the internal function.
|
||||
return plugin.newBuilderInternal(spec, podRef, plugin.mounter, &realMountDetector{plugin.mounter}, opts)
|
||||
func (plugin *emptyDirPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
return plugin.newBuilderInternal(spec, podRef, mounter, &realMountDetector{mounter}, opts)
|
||||
}
|
||||
|
||||
func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, podRef *api.ObjectReference, mounter mount.Interface, mountDetector mountDetector, opts volume.VolumeOptions) (volume.Builder, error) {
|
||||
@@ -104,9 +96,9 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, podRef *api.
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (plugin *emptyDirPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) {
|
||||
func (plugin *emptyDirPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
|
||||
// Inject real implementations here, test through the internal function.
|
||||
return plugin.newCleanerInternal(volName, podUID, plugin.mounter, &realMountDetector{plugin.mounter})
|
||||
return plugin.newCleanerInternal(volName, podUID, mounter, &realMountDetector{mounter})
|
||||
}
|
||||
|
||||
func (plugin *emptyDirPlugin) newCleanerInternal(volName string, podUID types.UID, mounter mount.Interface, mountDetector mountDetector) (volume.Cleaner, error) {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
@@ -21,6 +23,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// Defined by Linux - the type number for tmpfs mounts.
|
||||
@@ -32,6 +35,7 @@ type realMountDetector struct {
|
||||
}
|
||||
|
||||
func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, error) {
|
||||
glog.V(5).Infof("Determining mount medium of %v", path)
|
||||
isMnt, err := m.mounter.IsMountPoint(path)
|
||||
if err != nil {
|
||||
return 0, false, fmt.Errorf("IsMountPoint(%q): %v", path, err)
|
||||
@@ -40,6 +44,8 @@ func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, er
|
||||
if err := syscall.Statfs(path, &buf); err != nil {
|
||||
return 0, false, fmt.Errorf("statfs(%q): %v", path, err)
|
||||
}
|
||||
|
||||
glog.V(5).Info("Statfs_t of %v: %+v", path, buf)
|
||||
if buf.Type == linuxTmpfsMagic {
|
||||
return mediumMemory, isMnt, nil
|
||||
}
|
||||
|
@@ -197,7 +197,7 @@ func TestPluginBackCompat(t *testing.T) {
|
||||
spec := &api.Volume{
|
||||
Name: "vol1",
|
||||
}
|
||||
builder, err := plug.NewBuilder(volume.NewSpecFromVolume(spec), &api.ObjectReference{UID: types.UID("poduid")}, volume.VolumeOptions{""})
|
||||
builder, err := plug.NewBuilder(volume.NewSpecFromVolume(spec), &api.ObjectReference{UID: types.UID("poduid")}, volume.VolumeOptions{""}, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Builder: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user