Promote volume plugins, prep for persistent vols

Move pkg/kubelet/volume/... to pkg/volume/...
Some renames to make the soon-to-come persistent volumes work clearer.
This commit is contained in:
Tim Hockin 2015-03-18 22:18:31 -07:00
parent d11ec2933f
commit bfadae77e0
27 changed files with 135 additions and 134 deletions

View File

@ -44,13 +44,13 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/empty_dir"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/master"
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe" "github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
"github.com/GoogleCloudPlatform/kubernetes/pkg/service" "github.com/GoogleCloudPlatform/kubernetes/pkg/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/empty_dir"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit" "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler" "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider" _ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider"

View File

@ -24,18 +24,18 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network/exec" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network/exec"
// Volume plugins // Volume plugins
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/empty_dir" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/empty_dir"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/gce_pd" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/gce_pd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/git_repo" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/git_repo"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/host_path" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/host_path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/nfs" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/nfs"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/secret" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/secret"
) )
// ProbeVolumePlugins collects all volume plugins into an easy to use list. // ProbeVolumePlugins collects all volume plugins into an easy to use list.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
allPlugins := []volume.Plugin{} allPlugins := []volume.VolumePlugin{}
// The list of plugins to probe is decided by the kubelet binary, not // The list of plugins to probe is decided by the kubelet binary, not
// by dynamic linking or other "magic". Plugins will be analyzed and // by dynamic linking or other "magic". Plugins will be analyzed and
@ -44,8 +44,8 @@ func ProbeVolumePlugins() []volume.Plugin {
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...) allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, git_repo.ProbeVolumePlugins()...) allPlugins = append(allPlugins, git_repo.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, host_path.ProbeVolumePlugins()...) allPlugins = append(allPlugins, host_path.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, secret.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins()...) allPlugins = append(allPlugins, nfs.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, secret.ProbeVolumePlugins()...)
return allPlugins return allPlugins
} }

View File

@ -34,9 +34,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" "github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -267,7 +267,7 @@ func SimpleRunKubelet(client *client.Client,
hostname, rootDir, manifestURL, address string, hostname, rootDir, manifestURL, address string,
port uint, port uint,
masterServiceNamespace string, masterServiceNamespace string,
volumePlugins []volume.Plugin, volumePlugins []volume.VolumePlugin,
tlsOptions *kubelet.TLSOptions, tlsOptions *kubelet.TLSOptions,
cadvisorInterface cadvisor.Interface, cadvisorInterface cadvisor.Interface,
configFilePath string) { configFilePath string) {
@ -402,7 +402,7 @@ type KubeletConfig struct {
Port uint Port uint
Runonce bool Runonce bool
MasterServiceNamespace string MasterServiceNamespace string
VolumePlugins []volume.Plugin VolumePlugins []volume.VolumePlugin
NetworkPlugins []network.NetworkPlugin NetworkPlugins []network.NetworkPlugin
NetworkPluginName string NetworkPluginName string
StreamingConnectionIdleTimeout time.Duration StreamingConnectionIdleTimeout time.Duration

View File

@ -43,7 +43,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe" "github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@ -51,6 +50,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
utilErrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors" utilErrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/fsouza/go-dockerclient" "github.com/fsouza/go-dockerclient"
"github.com/golang/glog" "github.com/golang/glog"
@ -101,7 +101,7 @@ type SyncHandler interface {
type SourcesReadyFn func() bool type SourcesReadyFn func() bool
type volumeMap map[string]volume.Interface type volumeMap map[string]volume.Volume
// New creates a new Kubelet for use in main // New creates a new Kubelet for use in main
func NewMainKubelet( func NewMainKubelet(
@ -118,7 +118,7 @@ func NewMainKubelet(
clusterDomain string, clusterDomain string,
clusterDNS net.IP, clusterDNS net.IP,
masterServiceNamespace string, masterServiceNamespace string,
volumePlugins []volume.Plugin, volumePlugins []volume.VolumePlugin,
networkPlugins []network.NetworkPlugin, networkPlugins []network.NetworkPlugin,
networkPluginName string, networkPluginName string,
streamingConnectionIdleTimeout time.Duration, streamingConnectionIdleTimeout time.Duration,
@ -308,7 +308,7 @@ type Kubelet struct {
serviceLister serviceLister serviceLister serviceLister
// Volume plugins. // Volume plugins.
volumePluginMgr volume.PluginMgr volumePluginMgr volume.VolumePluginMgr
// Network plugin // Network plugin
networkPlugin network.NetworkPlugin networkPlugin network.NetworkPlugin

View File

@ -40,10 +40,10 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/host_path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/host_path"
"github.com/fsouza/go-dockerclient" "github.com/fsouza/go-dockerclient"
cadvisorApi "github.com/google/cadvisor/info/v1" cadvisorApi "github.com/google/cadvisor/info/v1"
) )
@ -1022,7 +1022,7 @@ func TestSyncPodUnhealthy(t *testing.T) {
func TestMountExternalVolumes(t *testing.T) { func TestMountExternalVolumes(t *testing.T) {
testKubelet := newTestKubelet(t) testKubelet := newTestKubelet(t)
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
kubelet.volumePluginMgr.InitPlugins([]volume.Plugin{&volume.FakePlugin{"fake", nil}}, &volumeHost{kubelet}) kubelet.volumePluginMgr.InitPlugins([]volume.VolumePlugin{&volume.FakeVolumePlugin{"fake", nil}}, &volumeHost{kubelet})
pod := api.Pod{ pod := api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
@ -1057,8 +1057,8 @@ func TestMountExternalVolumes(t *testing.T) {
func TestGetPodVolumesFromDisk(t *testing.T) { func TestGetPodVolumesFromDisk(t *testing.T) {
testKubelet := newTestKubelet(t) testKubelet := newTestKubelet(t)
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
plug := &volume.FakePlugin{"fake", nil} plug := &volume.FakeVolumePlugin{"fake", nil}
kubelet.volumePluginMgr.InitPlugins([]volume.Plugin{plug}, &volumeHost{kubelet}) kubelet.volumePluginMgr.InitPlugins([]volume.VolumePlugin{plug}, &volumeHost{kubelet})
volsOnDisk := []struct { volsOnDisk := []struct {
podUID types.UID podUID types.UID

View File

@ -23,8 +23,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/golang/glog" "github.com/golang/glog"
) )

View File

@ -21,40 +21,40 @@ import (
"os" "os"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
return ProbeVolumePluginsWithMounter(mount.New()) return ProbeVolumePluginsWithMounter(mount.New())
} }
// ProbePluginsWithMounter is a convenience for testing other plugins which wrap this one. // ProbePluginsWithMounter is a convenience for testing other plugins which wrap this one.
//FIXME: alternative: pass mount.Interface to all ProbeVolumePlugins() functions? Opinions? //FIXME: alternative: pass mount.Interface to all ProbeVolumePlugins() functions? Opinions?
func ProbeVolumePluginsWithMounter(mounter mount.Interface) []volume.Plugin { func ProbeVolumePluginsWithMounter(mounter mount.Interface) []volume.VolumePlugin {
return []volume.Plugin{ return []volume.VolumePlugin{
&emptyDirPlugin{nil, mounter, false}, &emptyDirPlugin{nil, mounter, false},
&emptyDirPlugin{nil, mounter, true}, &emptyDirPlugin{nil, mounter, true},
} }
} }
type emptyDirPlugin struct { type emptyDirPlugin struct {
host volume.Host host volume.VolumeHost
mounter mount.Interface mounter mount.Interface
legacyMode bool // if set, plugin answers to the legacy name legacyMode bool // if set, plugin answers to the legacy name
} }
var _ volume.Plugin = &emptyDirPlugin{} var _ volume.VolumePlugin = &emptyDirPlugin{}
const ( const (
emptyDirPluginName = "kubernetes.io/empty-dir" emptyDirPluginName = "kubernetes.io/empty-dir"
emptyDirPluginLegacyName = "empty" emptyDirPluginLegacyName = "empty"
) )
func (plugin *emptyDirPlugin) Init(host volume.Host) { func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) {
plugin.host = host plugin.host = host
} }

View File

@ -22,18 +22,18 @@ import (
"testing" "testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
) )
// The dir where volumes will be stored. // The dir where volumes will be stored.
const basePath = "/tmp/fake" const basePath = "/tmp/fake"
// Construct an instance of a plugin, by name. // Construct an instance of a plugin, by name.
func makePluginUnderTest(t *testing.T, plugName string) volume.Plugin { func makePluginUnderTest(t *testing.T, plugName string) volume.VolumePlugin {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost(basePath, nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(basePath, nil, nil))
plug, err := plugMgr.FindPluginByName(plugName) plug, err := plugMgr.FindPluginByName(plugName)
if err != nil { if err != nil {

View File

@ -23,31 +23,31 @@ import (
"strconv" "strconv"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/golang/glog" "github.com/golang/glog"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.Plugin{&gcePersistentDiskPlugin{nil, false}, &gcePersistentDiskPlugin{nil, true}} return []volume.VolumePlugin{&gcePersistentDiskPlugin{nil, false}, &gcePersistentDiskPlugin{nil, true}}
} }
type gcePersistentDiskPlugin struct { type gcePersistentDiskPlugin struct {
host volume.Host host volume.VolumeHost
legacyMode bool // if set, plugin answers to the legacy name legacyMode bool // if set, plugin answers to the legacy name
} }
var _ volume.Plugin = &gcePersistentDiskPlugin{} var _ volume.VolumePlugin = &gcePersistentDiskPlugin{}
const ( const (
gcePersistentDiskPluginName = "kubernetes.io/gce-pd" gcePersistentDiskPluginName = "kubernetes.io/gce-pd"
gcePersistentDiskPluginLegacyName = "gce-pd" gcePersistentDiskPluginLegacyName = "gce-pd"
) )
func (plugin *gcePersistentDiskPlugin) Init(host volume.Host) { func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) {
plugin.host = host plugin.host = host
} }
@ -233,7 +233,7 @@ func (pd *gcePersistentDisk) SetUpAt(dir string) error {
return nil return nil
} }
func makeGlobalPDName(host volume.Host, devName string) string { func makeGlobalPDName(host volume.VolumeHost, devName string) string {
return path.Join(host.GetPluginDir(gcePersistentDiskPluginName), "mounts", devName) return path.Join(host.GetPluginDir(gcePersistentDiskPluginName), "mounts", devName)
} }

View File

@ -21,14 +21,14 @@ import (
"testing" "testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
) )
func TestCanSupport(t *testing.T) { func TestCanSupport(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("/tmp/fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd") plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd")
if err != nil { if err != nil {
@ -65,8 +65,8 @@ func (fake *fakePDManager) DetachDisk(pd *gcePersistentDisk) error {
} }
func TestPlugin(t *testing.T) { func TestPlugin(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("/tmp/fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd") plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd")
if err != nil { if err != nil {
@ -131,8 +131,8 @@ func TestPlugin(t *testing.T) {
} }
func TestPluginLegacy(t *testing.T) { func TestPluginLegacy(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("/tmp/fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plug, err := plugMgr.FindPluginByName("gce-pd") plug, err := plugMgr.FindPluginByName("gce-pd")
if err != nil { if err != nil {

View File

@ -23,30 +23,30 @@ import (
"path" "path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/golang/glog" "github.com/golang/glog"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.Plugin{&gitRepoPlugin{nil, false}, &gitRepoPlugin{nil, true}} return []volume.VolumePlugin{&gitRepoPlugin{nil, false}, &gitRepoPlugin{nil, true}}
} }
type gitRepoPlugin struct { type gitRepoPlugin struct {
host volume.Host host volume.VolumeHost
legacyMode bool // if set, plugin answers to the legacy name legacyMode bool // if set, plugin answers to the legacy name
} }
var _ volume.Plugin = &gitRepoPlugin{} var _ volume.VolumePlugin = &gitRepoPlugin{}
const ( const (
gitRepoPluginName = "kubernetes.io/git-repo" gitRepoPluginName = "kubernetes.io/git-repo"
gitRepoPluginLegacyName = "git" gitRepoPluginLegacyName = "git"
) )
func (plugin *gitRepoPlugin) Init(host volume.Host) { func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) {
plugin.host = host plugin.host = host
} }

View File

@ -25,22 +25,22 @@ import (
"testing" "testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/empty_dir"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/empty_dir"
) )
func newTestHost(t *testing.T) volume.Host { func newTestHost(t *testing.T) volume.VolumeHost {
tempDir, err := ioutil.TempDir("/tmp", "git_repo_test.") tempDir, err := ioutil.TempDir("/tmp", "git_repo_test.")
if err != nil { if err != nil {
t.Fatalf("can't make a temp rootdir: %v", err) t.Fatalf("can't make a temp rootdir: %v", err)
} }
return volume.NewFakeHost(tempDir, nil, empty_dir.ProbeVolumePlugins()) return volume.NewFakeVolumeHost(tempDir, nil, empty_dir.ProbeVolumePlugins())
} }
func TestCanSupport(t *testing.T) { func TestCanSupport(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t)) plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t))
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo") plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
@ -55,7 +55,7 @@ func TestCanSupport(t *testing.T) {
} }
} }
func testSetUp(plug volume.Plugin, builder volume.Builder, t *testing.T) { func testSetUp(plug volume.VolumePlugin, builder volume.Builder, t *testing.T) {
var fcmd exec.FakeCmd var fcmd exec.FakeCmd
fcmd = exec.FakeCmd{ fcmd = exec.FakeCmd{
CombinedOutputScript: []exec.FakeCombinedOutputAction{ CombinedOutputScript: []exec.FakeCombinedOutputAction{
@ -102,7 +102,7 @@ func testSetUp(plug volume.Plugin, builder volume.Builder, t *testing.T) {
} }
func TestPlugin(t *testing.T) { func TestPlugin(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t)) plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t))
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo") plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
@ -159,7 +159,7 @@ func TestPlugin(t *testing.T) {
} }
func TestPluginLegacy(t *testing.T) { func TestPluginLegacy(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t)) plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t))
plug, err := plugMgr.FindPluginByName("git") plug, err := plugMgr.FindPluginByName("git")

View File

@ -20,26 +20,26 @@ import (
"fmt" "fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.Plugin{&hostPathPlugin{nil}} return []volume.VolumePlugin{&hostPathPlugin{nil}}
} }
type hostPathPlugin struct { type hostPathPlugin struct {
host volume.Host host volume.VolumeHost
} }
var _ volume.Plugin = &hostPathPlugin{} var _ volume.VolumePlugin = &hostPathPlugin{}
const ( const (
hostPathPluginName = "kubernetes.io/host-path" hostPathPluginName = "kubernetes.io/host-path"
) )
func (plugin *hostPathPlugin) Init(host volume.Host) { func (plugin *hostPathPlugin) Init(host volume.VolumeHost) {
plugin.host = host plugin.host = host
} }

View File

@ -20,13 +20,13 @@ import (
"testing" "testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
) )
func TestCanSupport(t *testing.T) { func TestCanSupport(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("fake", nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path") plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path")
if err != nil { if err != nil {
@ -44,8 +44,8 @@ func TestCanSupport(t *testing.T) {
} }
func TestPlugin(t *testing.T) { func TestPlugin(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("fake", nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path") plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path")
if err != nil { if err != nil {

View File

@ -20,28 +20,28 @@ import (
"os" "os"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/golang/glog" "github.com/golang/glog"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.Plugin{&nfsPlugin{nil, newNFSMounter()}} return []volume.VolumePlugin{&nfsPlugin{nil, newNFSMounter()}}
} }
type nfsPlugin struct { type nfsPlugin struct {
host volume.Host host volume.VolumeHost
mounter nfsMountInterface mounter nfsMountInterface
} }
var _ volume.Plugin = &nfsPlugin{} var _ volume.VolumePlugin = &nfsPlugin{}
const ( const (
nfsPluginName = "kubernetes.io/nfs" nfsPluginName = "kubernetes.io/nfs"
) )
func (plugin *nfsPlugin) Init(host volume.Host) { func (plugin *nfsPlugin) Init(host volume.VolumeHost) {
plugin.host = host plugin.host = host
} }

View File

@ -22,14 +22,14 @@ import (
"testing" "testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
) )
func TestCanSupport(t *testing.T) { func TestCanSupport(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("fake", nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs") plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
if err != nil { if err != nil {
t.Errorf("Can't find the plugin by name") t.Errorf("Can't find the plugin by name")
@ -75,8 +75,8 @@ func (fake *fakeNFSMounter) IsMountPoint(dir string) (bool, error) {
} }
func TestPlugin(t *testing.T) { func TestPlugin(t *testing.T) {
plugMgr := volume.PluginMgr{} plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeHost("/tmp/fake", nil, nil)) plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs") plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
if err != nil { if err != nil {
t.Errorf("Can't find the plugin by name") t.Errorf("Can't find the plugin by name")

View File

@ -29,19 +29,20 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
) )
// Plugin is an interface to volume plugins. // VolumePlugin is an interface to volume plugins that can be used on a
type Plugin interface { // kubernetes node (e.g. by kubelet) to instantiate and manage volumes.
type VolumePlugin interface {
// Init initializes the plugin. This will be called exactly once // Init initializes the plugin. This will be called exactly once
// before any New* calls are made - implementations of plugins may // before any New* calls are made - implementations of plugins may
// depend on this. // depend on this.
Init(host Host) Init(host VolumeHost)
// Name returns the plugin's name. Plugins should use namespaced names // Name returns the plugin's name. Plugins should use namespaced names
// such as "example.com/volume". The "kubernetes.io" namespace is // such as "example.com/volume". The "kubernetes.io" namespace is
// reserved for plugins which are bundled with kubernetes. // reserved for plugins which are bundled with kubernetes.
Name() string Name() string
// CanSupport tests whether the Plugin supports a given volume // CanSupport tests whether the plugin supports a given volume
// specification from the API. The spec pointer should be considered // specification from the API. The spec pointer should be considered
// const. // const.
CanSupport(spec *api.Volume) bool CanSupport(spec *api.Volume) bool
@ -58,8 +59,8 @@ type Plugin interface {
NewCleaner(name string, podUID types.UID) (Cleaner, error) NewCleaner(name string, podUID types.UID) (Cleaner, error)
} }
// Host is an interface that plugins can use to access the kubelet. // VolumeHost is an interface that plugins can use to access the kubelet.
type Host interface { type VolumeHost interface {
// GetPluginDir returns the absolute path to a directory under which // GetPluginDir returns the absolute path to a directory under which
// a given plugin may store data. This directory might not actually // a given plugin may store data. This directory might not actually
// exist on disk yet. For plugin data that is per-pod, see // exist on disk yet. For plugin data that is per-pod, see
@ -93,21 +94,21 @@ type Host interface {
NewWrapperCleaner(spec *api.Volume, podUID types.UID) (Cleaner, error) NewWrapperCleaner(spec *api.Volume, podUID types.UID) (Cleaner, error)
} }
// PluginMgr tracks registered plugins. // VolumePluginMgr tracks registered plugins.
type PluginMgr struct { type VolumePluginMgr struct {
mutex sync.Mutex mutex sync.Mutex
plugins map[string]Plugin plugins map[string]VolumePlugin
} }
// InitPlugins initializes each plugin. All plugins must have unique names. // InitPlugins initializes each plugin. All plugins must have unique names.
// This must be called exactly once before any New* methods are called on any // This must be called exactly once before any New* methods are called on any
// plugins. // plugins.
func (pm *PluginMgr) InitPlugins(plugins []Plugin, host Host) error { func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost) error {
pm.mutex.Lock() pm.mutex.Lock()
defer pm.mutex.Unlock() defer pm.mutex.Unlock()
if pm.plugins == nil { if pm.plugins == nil {
pm.plugins = map[string]Plugin{} pm.plugins = map[string]VolumePlugin{}
} }
allErrs := []error{} allErrs := []error{}
@ -132,7 +133,7 @@ func (pm *PluginMgr) InitPlugins(plugins []Plugin, host Host) error {
// FindPluginBySpec looks for a plugin that can support a given volume // FindPluginBySpec looks for a plugin that can support a given volume
// specification. If no plugins can support or more than one plugin can // specification. If no plugins can support or more than one plugin can
// support it, return error. // support it, return error.
func (pm *PluginMgr) FindPluginBySpec(spec *api.Volume) (Plugin, error) { func (pm *VolumePluginMgr) FindPluginBySpec(spec *api.Volume) (VolumePlugin, error) {
pm.mutex.Lock() pm.mutex.Lock()
defer pm.mutex.Unlock() defer pm.mutex.Unlock()
@ -153,7 +154,7 @@ func (pm *PluginMgr) FindPluginBySpec(spec *api.Volume) (Plugin, error) {
// FindPluginByName fetches a plugin by name or by legacy name. If no plugin // FindPluginByName fetches a plugin by name or by legacy name. If no plugin
// is found, returns error. // is found, returns error.
func (pm *PluginMgr) FindPluginByName(name string) (Plugin, error) { func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
pm.mutex.Lock() pm.mutex.Lock()
defer pm.mutex.Unlock() defer pm.mutex.Unlock()

View File

@ -22,14 +22,14 @@ import (
"path" "path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/golang/glog" "github.com/golang/glog"
) )
// ProbeVolumePlugin is the entry point for plugin detection in a package. // ProbeVolumePlugin is the entry point for plugin detection in a package.
func ProbeVolumePlugins() []volume.Plugin { func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.Plugin{&secretPlugin{}} return []volume.VolumePlugin{&secretPlugin{}}
} }
const ( const (
@ -38,10 +38,10 @@ const (
// secretPlugin implements the VolumePlugin interface. // secretPlugin implements the VolumePlugin interface.
type secretPlugin struct { type secretPlugin struct {
host volume.Host host volume.VolumeHost
} }
func (plugin *secretPlugin) Init(host volume.Host) { func (plugin *secretPlugin) Init(host volume.VolumeHost) {
plugin.host = host plugin.host = host
} }

View File

@ -26,23 +26,23 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/empty_dir"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/empty_dir"
) )
func newTestHost(t *testing.T, client client.Interface) volume.Host { func newTestHost(t *testing.T, client client.Interface) volume.VolumeHost {
tempDir, err := ioutil.TempDir("/tmp", "secret_volume_test.") tempDir, err := ioutil.TempDir("/tmp", "secret_volume_test.")
if err != nil { if err != nil {
t.Fatalf("can't make a temp rootdir: %v", err) t.Fatalf("can't make a temp rootdir: %v", err)
} }
return volume.NewFakeHost(tempDir, client, empty_dir.ProbeVolumePluginsWithMounter(&mount.FakeMounter{})) return volume.NewFakeVolumeHost(tempDir, client, empty_dir.ProbeVolumePluginsWithMounter(&mount.FakeMounter{}))
} }
func TestCanSupport(t *testing.T) { func TestCanSupport(t *testing.T) {
pluginMgr := volume.PluginMgr{} pluginMgr := volume.VolumePluginMgr{}
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, nil)) pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, nil))
plugin, err := pluginMgr.FindPluginByName(secretPluginName) plugin, err := pluginMgr.FindPluginByName(secretPluginName)
@ -93,7 +93,7 @@ func TestPlugin(t *testing.T) {
Secret: secret, Secret: secret,
} }
pluginMgr := volume.PluginMgr{} pluginMgr := volume.VolumePluginMgr{}
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, client)) pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, client))
plugin, err := pluginMgr.FindPluginByName(secretPluginName) plugin, err := pluginMgr.FindPluginByName(secretPluginName)

View File

@ -25,36 +25,36 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/types"
) )
// fakeHost is useful for testing volume plugins. // fakeVolumeHost is useful for testing volume plugins.
type fakeHost struct { type fakeVolumeHost struct {
rootDir string rootDir string
kubeClient client.Interface kubeClient client.Interface
pluginMgr PluginMgr pluginMgr VolumePluginMgr
} }
func NewFakeHost(rootDir string, kubeClient client.Interface, plugins []Plugin) *fakeHost { func NewFakeVolumeHost(rootDir string, kubeClient client.Interface, plugins []VolumePlugin) *fakeVolumeHost {
host := &fakeHost{rootDir: rootDir, kubeClient: kubeClient} host := &fakeVolumeHost{rootDir: rootDir, kubeClient: kubeClient}
host.pluginMgr.InitPlugins(plugins, host) host.pluginMgr.InitPlugins(plugins, host)
return host return host
} }
func (f *fakeHost) GetPluginDir(podUID string) string { func (f *fakeVolumeHost) GetPluginDir(podUID string) string {
return path.Join(f.rootDir, "plugins", podUID) return path.Join(f.rootDir, "plugins", podUID)
} }
func (f *fakeHost) GetPodVolumeDir(podUID types.UID, pluginName, volumeName string) string { func (f *fakeVolumeHost) GetPodVolumeDir(podUID types.UID, pluginName, volumeName string) string {
return path.Join(f.rootDir, "pods", string(podUID), "volumes", pluginName, volumeName) return path.Join(f.rootDir, "pods", string(podUID), "volumes", pluginName, volumeName)
} }
func (f *fakeHost) GetPodPluginDir(podUID types.UID, pluginName string) string { func (f *fakeVolumeHost) GetPodPluginDir(podUID types.UID, pluginName string) string {
return path.Join(f.rootDir, "pods", string(podUID), "plugins", pluginName) return path.Join(f.rootDir, "pods", string(podUID), "plugins", pluginName)
} }
func (f *fakeHost) GetKubeClient() client.Interface { func (f *fakeVolumeHost) GetKubeClient() client.Interface {
return f.kubeClient return f.kubeClient
} }
func (f *fakeHost) NewWrapperBuilder(spec *api.Volume, podRef *api.ObjectReference) (Builder, error) { func (f *fakeVolumeHost) NewWrapperBuilder(spec *api.Volume, podRef *api.ObjectReference) (Builder, error) {
plug, err := f.pluginMgr.FindPluginBySpec(spec) plug, err := f.pluginMgr.FindPluginBySpec(spec)
if err != nil { if err != nil {
return nil, err return nil, err
@ -62,7 +62,7 @@ func (f *fakeHost) NewWrapperBuilder(spec *api.Volume, podRef *api.ObjectReferen
return plug.NewBuilder(spec, podRef) return plug.NewBuilder(spec, podRef)
} }
func (f *fakeHost) NewWrapperCleaner(spec *api.Volume, podUID types.UID) (Cleaner, error) { func (f *fakeVolumeHost) NewWrapperCleaner(spec *api.Volume, podUID types.UID) (Cleaner, error) {
plug, err := f.pluginMgr.FindPluginBySpec(spec) plug, err := f.pluginMgr.FindPluginBySpec(spec)
if err != nil { if err != nil {
return nil, err return nil, err
@ -70,42 +70,42 @@ func (f *fakeHost) NewWrapperCleaner(spec *api.Volume, podUID types.UID) (Cleane
return plug.NewCleaner(spec.Name, podUID) return plug.NewCleaner(spec.Name, podUID)
} }
// FakePlugin is useful for for testing. It tries to be a fully compliant // FakeVolumePlugin is useful for for testing. It tries to be a fully compliant
// plugin, but all it does is make empty directories. // plugin, but all it does is make empty directories.
// Use as: // Use as:
// volume.RegisterPlugin(&FakePlugin{"fake-name"}) // volume.RegisterPlugin(&FakePlugin{"fake-name"})
type FakePlugin struct { type FakeVolumePlugin struct {
PluginName string PluginName string
Host Host Host VolumeHost
} }
var _ Plugin = &FakePlugin{} var _ VolumePlugin = &FakeVolumePlugin{}
func (plugin *FakePlugin) Init(host Host) { func (plugin *FakeVolumePlugin) Init(host VolumeHost) {
plugin.Host = host plugin.Host = host
} }
func (plugin *FakePlugin) Name() string { func (plugin *FakeVolumePlugin) Name() string {
return plugin.PluginName return plugin.PluginName
} }
func (plugin *FakePlugin) CanSupport(spec *api.Volume) bool { func (plugin *FakeVolumePlugin) CanSupport(spec *api.Volume) bool {
// TODO: maybe pattern-match on spec.Name to decide? // TODO: maybe pattern-match on spec.Name to decide?
return true return true
} }
func (plugin *FakePlugin) NewBuilder(spec *api.Volume, podRef *api.ObjectReference) (Builder, error) { func (plugin *FakeVolumePlugin) NewBuilder(spec *api.Volume, podRef *api.ObjectReference) (Builder, error) {
return &FakeVolume{podRef.UID, spec.Name, plugin}, nil return &FakeVolume{podRef.UID, spec.Name, plugin}, nil
} }
func (plugin *FakePlugin) NewCleaner(volName string, podUID types.UID) (Cleaner, error) { func (plugin *FakeVolumePlugin) NewCleaner(volName string, podUID types.UID) (Cleaner, error) {
return &FakeVolume{podUID, volName, plugin}, nil return &FakeVolume{podUID, volName, plugin}, nil
} }
type FakeVolume struct { type FakeVolume struct {
PodUID types.UID PodUID types.UID
VolName string VolName string
Plugin *FakePlugin Plugin *FakeVolumePlugin
} }
func (fv *FakeVolume) SetUp() error { func (fv *FakeVolume) SetUp() error {

View File

@ -22,9 +22,9 @@ import (
"path" "path"
) )
// Interface is a directory used by pods or hosts. // Volume represents a directory used by pods or hosts on a node.
// All method implementations of methods in the volume interface must be idempotent. // All method implementations of methods in the volume interface must be idempotent.
type Interface interface { type Volume interface {
// GetPath returns the directory path the volume is mounted to. // GetPath returns the directory path the volume is mounted to.
GetPath() string GetPath() string
} }
@ -32,7 +32,7 @@ type Interface interface {
// Builder interface provides method to set up/mount the volume. // Builder interface provides method to set up/mount the volume.
type Builder interface { type Builder interface {
// Uses Interface to provide the path for Docker binds. // Uses Interface to provide the path for Docker binds.
Interface Volume
// SetUp prepares and mounts/unpacks the volume to a self-determined // SetUp prepares and mounts/unpacks the volume to a self-determined
// directory path. This may be called more than once, so // directory path. This may be called more than once, so
// implementations must be idempotent. // implementations must be idempotent.
@ -45,7 +45,7 @@ type Builder interface {
// Cleaner interface provides method to cleanup/unmount the volumes. // Cleaner interface provides method to cleanup/unmount the volumes.
type Cleaner interface { type Cleaner interface {
Interface Volume
// TearDown unmounts the volume from a self-determined directory and // TearDown unmounts the volume from a self-determined directory and
// removes traces of the SetUp procedure. // removes traces of the SetUp procedure.
TearDown() error TearDown() error