diff --git a/pkg/volume/empty_dir/empty_dir.go b/pkg/volume/empty_dir/empty_dir.go index 7951e7ab7d6..8bcf325e13e 100644 --- a/pkg/volume/empty_dir/empty_dir.go +++ b/pkg/volume/empty_dir/empty_dir.go @@ -31,21 +31,18 @@ import ( // This is the primary entrypoint for volume plugins. func ProbeVolumePlugins() []volume.VolumePlugin { return []volume.VolumePlugin{ - &emptyDirPlugin{nil, false}, - &emptyDirPlugin{nil, true}, + &emptyDirPlugin{nil}, } } type emptyDirPlugin struct { - host volume.VolumeHost - legacyMode bool // if set, plugin answers to the legacy name + host volume.VolumeHost } var _ volume.VolumePlugin = &emptyDirPlugin{} const ( - emptyDirPluginName = "kubernetes.io/empty-dir" - emptyDirPluginLegacyName = "empty" + emptyDirPluginName = "kubernetes.io/empty-dir" ) func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) { @@ -53,18 +50,10 @@ func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) { } func (plugin *emptyDirPlugin) Name() string { - if plugin.legacyMode { - return emptyDirPluginLegacyName - } return emptyDirPluginName } func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool { - if plugin.legacyMode { - // Legacy mode instances can be cleaned up but not created anew. - return false - } - if spec.VolumeSource.EmptyDir != nil { return true } @@ -76,10 +65,6 @@ func (plugin *emptyDirPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts v } func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mounter mount.Interface, mountDetector mountDetector, opts volume.VolumeOptions) (volume.Builder, error) { - if plugin.legacyMode { - // Legacy mode instances can be cleaned up but not created anew. - return nil, fmt.Errorf("legacy mode: can not create new instances") - } medium := api.StorageMediumDefault if spec.VolumeSource.EmptyDir != nil { // Support a non-specified source as EmptyDir. medium = spec.VolumeSource.EmptyDir.Medium @@ -91,7 +76,6 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod mounter: mounter, mountDetector: mountDetector, plugin: plugin, - legacyMode: false, rootContext: opts.RootContext, }, nil } @@ -102,10 +86,6 @@ func (plugin *emptyDirPlugin) NewCleaner(volName string, podUID types.UID, mount } func (plugin *emptyDirPlugin) newCleanerInternal(volName string, podUID types.UID, mounter mount.Interface, mountDetector mountDetector) (volume.Cleaner, error) { - legacy := false - if plugin.legacyMode { - legacy = true - } ed := &emptyDir{ podUID: podUID, volName: volName, @@ -113,7 +93,6 @@ func (plugin *emptyDirPlugin) newCleanerInternal(volName string, podUID types.UI mounter: mounter, mountDetector: mountDetector, plugin: plugin, - legacyMode: legacy, } return ed, nil } @@ -144,7 +123,6 @@ type emptyDir struct { mounter mount.Interface mountDetector mountDetector plugin *emptyDirPlugin - legacyMode bool rootContext string } @@ -155,9 +133,6 @@ func (ed *emptyDir) SetUp() error { // SetUpAt creates new directory. func (ed *emptyDir) SetUpAt(dir string) error { - if ed.legacyMode { - return fmt.Errorf("legacy mode: can not create new instances") - } switch ed.medium { case api.StorageMediumDefault: return ed.setupDefault(dir) @@ -212,9 +187,6 @@ func (ed *emptyDir) getTmpfsMountOptions() []string { func (ed *emptyDir) GetPath() string { name := emptyDirPluginName - if ed.legacyMode { - name = emptyDirPluginLegacyName - } return ed.plugin.host.GetPodVolumeDir(ed.podUID, util.EscapeQualifiedNameForDisk(name), ed.volName) } diff --git a/pkg/volume/empty_dir/empty_dir_test.go b/pkg/volume/empty_dir/empty_dir_test.go index c813142bef0..e61e61baffa 100644 --- a/pkg/volume/empty_dir/empty_dir_test.go +++ b/pkg/volume/empty_dir/empty_dir_test.go @@ -213,28 +213,3 @@ func TestPluginBackCompat(t *testing.T) { t.Errorf("Got unexpected path: %s", volPath) } } - -func TestPluginLegacy(t *testing.T) { - plug := makePluginUnderTest(t, "empty") - - if plug.Name() != "empty" { - t.Errorf("Wrong name: %s", plug.Name()) - } - if plug.CanSupport(&volume.Spec{Name: "foo", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}) { - t.Errorf("Expected false") - } - - spec := api.Volume{VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}} - pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}} - if _, err := plug.(*emptyDirPlugin).newBuilderInternal(volume.NewSpecFromVolume(&spec), pod, &mount.FakeMounter{}, &fakeMountDetector{}, volume.VolumeOptions{""}); err == nil { - t.Errorf("Expected failiure") - } - - cleaner, err := plug.(*emptyDirPlugin).newCleanerInternal("vol1", types.UID("poduid"), &mount.FakeMounter{}, &fakeMountDetector{}) - if err != nil { - t.Errorf("Failed to make a new Cleaner: %v", err) - } - if cleaner == nil { - t.Errorf("Got a nil Cleaner") - } -} diff --git a/pkg/volume/gce_pd/gce_pd.go b/pkg/volume/gce_pd/gce_pd.go index be2d6b97acb..489ba87c7e6 100644 --- a/pkg/volume/gce_pd/gce_pd.go +++ b/pkg/volume/gce_pd/gce_pd.go @@ -17,7 +17,6 @@ limitations under the License. package gce_pd import ( - "fmt" "os" "path" "strconv" @@ -33,19 +32,17 @@ import ( // This is the primary entrypoint for volume plugins. func ProbeVolumePlugins() []volume.VolumePlugin { - return []volume.VolumePlugin{&gcePersistentDiskPlugin{nil, false}, &gcePersistentDiskPlugin{nil, true}} + return []volume.VolumePlugin{&gcePersistentDiskPlugin{nil}} } type gcePersistentDiskPlugin struct { - host volume.VolumeHost - legacyMode bool // if set, plugin answers to the legacy name + host volume.VolumeHost } var _ volume.VolumePlugin = &gcePersistentDiskPlugin{} const ( - gcePersistentDiskPluginName = "kubernetes.io/gce-pd" - gcePersistentDiskPluginLegacyName = "gce-pd" + gcePersistentDiskPluginName = "kubernetes.io/gce-pd" ) func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) { @@ -53,18 +50,10 @@ func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) { } func (plugin *gcePersistentDiskPlugin) Name() string { - if plugin.legacyMode { - return gcePersistentDiskPluginLegacyName - } return gcePersistentDiskPluginName } func (plugin *gcePersistentDiskPlugin) CanSupport(spec *volume.Spec) bool { - if plugin.legacyMode { - // Legacy mode instances can be cleaned up but not created anew. - return false - } - return spec.VolumeSource.GCEPersistentDisk != nil || spec.PersistentVolumeSource.GCEPersistentDisk != nil } @@ -81,11 +70,6 @@ func (plugin *gcePersistentDiskPlugin) NewBuilder(spec *volume.Spec, pod *api.Po } func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID, manager pdManager, mounter mount.Interface) (volume.Builder, error) { - if plugin.legacyMode { - // Legacy mode instances can be cleaned up but not created anew. - return nil, fmt.Errorf("legacy mode: can not create new instances") - } - var gce *api.GCEPersistentDiskVolumeSource if spec.VolumeSource.GCEPersistentDisk != nil { gce = spec.VolumeSource.GCEPersistentDisk @@ -112,7 +96,6 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, pod mounter: mounter, diskMounter: &gceSafeFormatAndMount{mounter, exec.New()}, plugin: plugin, - legacyMode: false, }, nil } @@ -122,10 +105,6 @@ func (plugin *gcePersistentDiskPlugin) NewCleaner(volName string, podUID types.U } func (plugin *gcePersistentDiskPlugin) newCleanerInternal(volName string, podUID types.UID, manager pdManager, mounter mount.Interface) (volume.Cleaner, error) { - legacy := false - if plugin.legacyMode { - legacy = true - } return &gcePersistentDisk{ podUID: podUID, volName: volName, @@ -133,7 +112,6 @@ func (plugin *gcePersistentDiskPlugin) newCleanerInternal(volName string, podUID mounter: mounter, diskMounter: &gceSafeFormatAndMount{mounter, exec.New()}, plugin: plugin, - legacyMode: legacy, }, nil } @@ -165,7 +143,6 @@ type gcePersistentDisk struct { // diskMounter provides the interface that is used to mount the actual block device. diskMounter mount.Interface plugin *gcePersistentDiskPlugin - legacyMode bool } func detachDiskLogError(pd *gcePersistentDisk) { @@ -182,10 +159,6 @@ func (pd *gcePersistentDisk) SetUp() error { // SetUpAt attaches the disk and bind mounts to the volume path. func (pd *gcePersistentDisk) SetUpAt(dir string) error { - if pd.legacyMode { - return fmt.Errorf("legacy mode: can not create new instances") - } - // TODO: handle failed mounts here. mountpoint, err := pd.mounter.IsMountPoint(dir) glog.V(4).Infof("PersistentDisk set up: %s %v %v", dir, mountpoint, err) @@ -250,9 +223,6 @@ func makeGlobalPDName(host volume.VolumeHost, devName string) string { func (pd *gcePersistentDisk) GetPath() string { name := gcePersistentDiskPluginName - if pd.legacyMode { - name = gcePersistentDiskPluginLegacyName - } return pd.plugin.host.GetPodVolumeDir(pd.podUID, util.EscapeQualifiedNameForDisk(name), pd.volName) } diff --git a/pkg/volume/gce_pd/gce_pd_test.go b/pkg/volume/gce_pd/gce_pd_test.go index 5e6e9330ad2..b8f561cad3d 100644 --- a/pkg/volume/gce_pd/gce_pd_test.go +++ b/pkg/volume/gce_pd/gce_pd_test.go @@ -170,35 +170,4 @@ func TestPlugin(t *testing.T) { if !fakeManager.detachCalled { t.Errorf("Detach watch not called") } - -} - -func TestPluginLegacy(t *testing.T) { - plugMgr := volume.VolumePluginMgr{} - plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil)) - - plug, err := plugMgr.FindPluginByName("gce-pd") - if err != nil { - t.Errorf("Can't find the plugin by name") - } - if plug.Name() != "gce-pd" { - t.Errorf("Wrong name: %s", plug.Name()) - } - if plug.CanSupport(&volume.Spec{Name: "foo", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}) { - t.Errorf("Expected false") - } - - spec := &api.Volume{VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}} - pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}} - if _, err := plug.NewBuilder(volume.NewSpecFromVolume(spec), pod, volume.VolumeOptions{""}, nil); err == nil { - t.Errorf("Expected failiure") - } - - cleaner, err := plug.NewCleaner("vol1", types.UID("poduid"), nil) - if err != nil { - t.Errorf("Failed to make a new Cleaner: %v", err) - } - if cleaner == nil { - t.Errorf("Got a nil Cleaner") - } } diff --git a/pkg/volume/git_repo/git_repo.go b/pkg/volume/git_repo/git_repo.go index eb9a8f1c905..3500bdcc17f 100644 --- a/pkg/volume/git_repo/git_repo.go +++ b/pkg/volume/git_repo/git_repo.go @@ -32,19 +32,17 @@ import ( // This is the primary entrypoint for volume plugins. func ProbeVolumePlugins() []volume.VolumePlugin { - return []volume.VolumePlugin{&gitRepoPlugin{nil, false}, &gitRepoPlugin{nil, true}} + return []volume.VolumePlugin{&gitRepoPlugin{nil}} } type gitRepoPlugin struct { - host volume.VolumeHost - legacyMode bool // if set, plugin answers to the legacy name + host volume.VolumeHost } var _ volume.VolumePlugin = &gitRepoPlugin{} const ( - gitRepoPluginName = "kubernetes.io/git-repo" - gitRepoPluginLegacyName = "git" + gitRepoPluginName = "kubernetes.io/git-repo" ) func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) { @@ -52,65 +50,46 @@ func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) { } func (plugin *gitRepoPlugin) Name() string { - if plugin.legacyMode { - return gitRepoPluginLegacyName - } return gitRepoPluginName } func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool { - if plugin.legacyMode { - // Legacy mode instances can be cleaned up but not created anew. - return false - } - return spec.VolumeSource.GitRepo != nil } func (plugin *gitRepoPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) { - if plugin.legacyMode { - // Legacy mode instances can be cleaned up but not created anew. - return nil, fmt.Errorf("legacy mode: can not create new instances") - } return &gitRepo{ - pod: *pod, - volName: spec.Name, - source: spec.VolumeSource.GitRepo.Repository, - revision: spec.VolumeSource.GitRepo.Revision, - exec: exec.New(), - plugin: plugin, - legacyMode: false, - opts: opts, - mounter: mounter, + pod: *pod, + volName: spec.Name, + source: spec.VolumeSource.GitRepo.Repository, + revision: spec.VolumeSource.GitRepo.Revision, + exec: exec.New(), + plugin: plugin, + opts: opts, + mounter: mounter, }, nil } func (plugin *gitRepoPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) { - legacy := false - if plugin.legacyMode { - legacy = true - } return &gitRepo{ - pod: api.Pod{ObjectMeta: api.ObjectMeta{UID: podUID}}, - volName: volName, - plugin: plugin, - legacyMode: legacy, - mounter: mounter, + pod: api.Pod{ObjectMeta: api.ObjectMeta{UID: podUID}}, + volName: volName, + plugin: plugin, + mounter: mounter, }, nil } // gitRepo volumes are directories which are pre-filled from a git repository. // These do not persist beyond the lifetime of a pod. type gitRepo struct { - volName string - pod api.Pod - source string - revision string - exec exec.Interface - plugin *gitRepoPlugin - legacyMode bool - opts volume.VolumeOptions - mounter mount.Interface + volName string + pod api.Pod + source string + revision string + exec exec.Interface + plugin *gitRepoPlugin + opts volume.VolumeOptions + mounter mount.Interface } // SetUp creates new directory and clones a git repo. @@ -129,9 +108,6 @@ func (gr *gitRepo) SetUpAt(dir string) error { if volumeutil.IsReady(gr.getMetaDir()) { return nil } - if gr.legacyMode { - return fmt.Errorf("legacy mode: can not create new instances") - } // Wrap EmptyDir, let it do the setup. wrapped, err := gr.plugin.host.NewWrapperBuilder(wrappedVolumeSpec, &gr.pod, gr.opts, gr.mounter) @@ -183,9 +159,6 @@ func (gr *gitRepo) execCommand(command string, args []string, dir string) ([]byt func (gr *gitRepo) GetPath() string { name := gitRepoPluginName - if gr.legacyMode { - name = gitRepoPluginLegacyName - } return gr.plugin.host.GetPodVolumeDir(gr.pod.UID, util.EscapeQualifiedNameForDisk(name), gr.volName) } diff --git a/pkg/volume/git_repo/git_repo_test.go b/pkg/volume/git_repo/git_repo_test.go index a5f3eef36c5..d0af90b038c 100644 --- a/pkg/volume/git_repo/git_repo_test.go +++ b/pkg/volume/git_repo/git_repo_test.go @@ -159,33 +159,3 @@ func TestPlugin(t *testing.T) { t.Errorf("SetUp() failed: %v", err) } } - -func TestPluginLegacy(t *testing.T) { - plugMgr := volume.VolumePluginMgr{} - plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t)) - - plug, err := plugMgr.FindPluginByName("git") - if err != nil { - t.Errorf("Can't find the plugin by name") - } - if plug.Name() != "git" { - t.Errorf("Wrong name: %s", plug.Name()) - } - if plug.CanSupport(&volume.Spec{Name: "foo", VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}) { - t.Errorf("Expected false") - } - - spec := &api.Volume{VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}} - pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}} - if _, err := plug.NewBuilder(volume.NewSpecFromVolume(spec), pod, volume.VolumeOptions{""}, nil); err == nil { - t.Errorf("Expected failiure") - } - - cleaner, err := plug.NewCleaner("vol1", types.UID("poduid"), nil) - if err != nil { - t.Errorf("Failed to make a new Cleaner: %v", err) - } - if cleaner == nil { - t.Errorf("Got a nil Cleaner") - } -}