Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove volumes legacy mode #11735

Merged
merged 1 commit into from
Jul 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 3 additions & 31 deletions pkg/volume/empty_dir/empty_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,29 @@ 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) {
plugin.host = host
}

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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -102,18 +86,13 @@ 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,
medium: api.StorageMediumDefault, // might be changed later
mounter: mounter,
mountDetector: mountDetector,
plugin: plugin,
legacyMode: legacy,
}
return ed, nil
}
Expand Down Expand Up @@ -144,7 +123,6 @@ type emptyDir struct {
mounter mount.Interface
mountDetector mountDetector
plugin *emptyDirPlugin
legacyMode bool
rootContext string
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
25 changes: 0 additions & 25 deletions pkg/volume/empty_dir/empty_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
36 changes: 3 additions & 33 deletions pkg/volume/gce_pd/gce_pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package gce_pd

import (
"fmt"
"os"
"path"
"strconv"
Expand All @@ -33,38 +32,28 @@ 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) {
plugin.host = host
}

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
}

Expand All @@ -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
Expand All @@ -112,7 +96,6 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, pod
mounter: mounter,
diskMounter: &gceSafeFormatAndMount{mounter, exec.New()},
plugin: plugin,
legacyMode: false,
}, nil
}

Expand All @@ -122,18 +105,13 @@ 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,
manager: manager,
mounter: mounter,
diskMounter: &gceSafeFormatAndMount{mounter, exec.New()},
plugin: plugin,
legacyMode: legacy,
}, nil
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
31 changes: 0 additions & 31 deletions pkg/volume/gce_pd/gce_pd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}