Remove volumes legacy mode
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
@@ -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")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user