mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #11735 from thockin/cleanup-volumes-legacy-mode
Remove volumes legacy mode
This commit is contained in:
commit
ce62d35e20
@ -31,21 +31,18 @@ import (
|
|||||||
// This is the primary entrypoint for volume plugins.
|
// This is the primary entrypoint for volume plugins.
|
||||||
func ProbeVolumePlugins() []volume.VolumePlugin {
|
func ProbeVolumePlugins() []volume.VolumePlugin {
|
||||||
return []volume.VolumePlugin{
|
return []volume.VolumePlugin{
|
||||||
&emptyDirPlugin{nil, false},
|
&emptyDirPlugin{nil},
|
||||||
&emptyDirPlugin{nil, true},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type emptyDirPlugin struct {
|
type emptyDirPlugin struct {
|
||||||
host volume.VolumeHost
|
host volume.VolumeHost
|
||||||
legacyMode bool // if set, plugin answers to the legacy name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.VolumePlugin = &emptyDirPlugin{}
|
var _ volume.VolumePlugin = &emptyDirPlugin{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
emptyDirPluginName = "kubernetes.io/empty-dir"
|
emptyDirPluginName = "kubernetes.io/empty-dir"
|
||||||
emptyDirPluginLegacyName = "empty"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) {
|
func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) {
|
||||||
@ -53,18 +50,10 @@ func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *emptyDirPlugin) Name() string {
|
func (plugin *emptyDirPlugin) Name() string {
|
||||||
if plugin.legacyMode {
|
|
||||||
return emptyDirPluginLegacyName
|
|
||||||
}
|
|
||||||
return emptyDirPluginName
|
return emptyDirPluginName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool {
|
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 {
|
if spec.VolumeSource.EmptyDir != nil {
|
||||||
return true
|
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) {
|
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
|
medium := api.StorageMediumDefault
|
||||||
if spec.VolumeSource.EmptyDir != nil { // Support a non-specified source as EmptyDir.
|
if spec.VolumeSource.EmptyDir != nil { // Support a non-specified source as EmptyDir.
|
||||||
medium = spec.VolumeSource.EmptyDir.Medium
|
medium = spec.VolumeSource.EmptyDir.Medium
|
||||||
@ -91,7 +76,6 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod
|
|||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
mountDetector: mountDetector,
|
mountDetector: mountDetector,
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
legacyMode: false,
|
|
||||||
rootContext: opts.RootContext,
|
rootContext: opts.RootContext,
|
||||||
}, nil
|
}, 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) {
|
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{
|
ed := &emptyDir{
|
||||||
podUID: podUID,
|
podUID: podUID,
|
||||||
volName: volName,
|
volName: volName,
|
||||||
@ -113,7 +93,6 @@ func (plugin *emptyDirPlugin) newCleanerInternal(volName string, podUID types.UI
|
|||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
mountDetector: mountDetector,
|
mountDetector: mountDetector,
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
legacyMode: legacy,
|
|
||||||
}
|
}
|
||||||
return ed, nil
|
return ed, nil
|
||||||
}
|
}
|
||||||
@ -144,7 +123,6 @@ type emptyDir struct {
|
|||||||
mounter mount.Interface
|
mounter mount.Interface
|
||||||
mountDetector mountDetector
|
mountDetector mountDetector
|
||||||
plugin *emptyDirPlugin
|
plugin *emptyDirPlugin
|
||||||
legacyMode bool
|
|
||||||
rootContext string
|
rootContext string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,9 +133,6 @@ func (ed *emptyDir) SetUp() error {
|
|||||||
|
|
||||||
// SetUpAt creates new directory.
|
// SetUpAt creates new directory.
|
||||||
func (ed *emptyDir) SetUpAt(dir string) error {
|
func (ed *emptyDir) SetUpAt(dir string) error {
|
||||||
if ed.legacyMode {
|
|
||||||
return fmt.Errorf("legacy mode: can not create new instances")
|
|
||||||
}
|
|
||||||
switch ed.medium {
|
switch ed.medium {
|
||||||
case api.StorageMediumDefault:
|
case api.StorageMediumDefault:
|
||||||
return ed.setupDefault(dir)
|
return ed.setupDefault(dir)
|
||||||
@ -212,9 +187,6 @@ func (ed *emptyDir) getTmpfsMountOptions() []string {
|
|||||||
|
|
||||||
func (ed *emptyDir) GetPath() string {
|
func (ed *emptyDir) GetPath() string {
|
||||||
name := emptyDirPluginName
|
name := emptyDirPluginName
|
||||||
if ed.legacyMode {
|
|
||||||
name = emptyDirPluginLegacyName
|
|
||||||
}
|
|
||||||
return ed.plugin.host.GetPodVolumeDir(ed.podUID, util.EscapeQualifiedNameForDisk(name), ed.volName)
|
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)
|
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package gce_pd
|
package gce_pd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -33,19 +32,17 @@ import (
|
|||||||
|
|
||||||
// This is the primary entrypoint for volume plugins.
|
// This is the primary entrypoint for volume plugins.
|
||||||
func ProbeVolumePlugins() []volume.VolumePlugin {
|
func ProbeVolumePlugins() []volume.VolumePlugin {
|
||||||
return []volume.VolumePlugin{&gcePersistentDiskPlugin{nil, false}, &gcePersistentDiskPlugin{nil, true}}
|
return []volume.VolumePlugin{&gcePersistentDiskPlugin{nil}}
|
||||||
}
|
}
|
||||||
|
|
||||||
type gcePersistentDiskPlugin struct {
|
type gcePersistentDiskPlugin struct {
|
||||||
host volume.VolumeHost
|
host volume.VolumeHost
|
||||||
legacyMode bool // if set, plugin answers to the legacy name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.VolumePlugin = &gcePersistentDiskPlugin{}
|
var _ volume.VolumePlugin = &gcePersistentDiskPlugin{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gcePersistentDiskPluginName = "kubernetes.io/gce-pd"
|
gcePersistentDiskPluginName = "kubernetes.io/gce-pd"
|
||||||
gcePersistentDiskPluginLegacyName = "gce-pd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) {
|
func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) {
|
||||||
@ -53,18 +50,10 @@ func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *gcePersistentDiskPlugin) Name() string {
|
func (plugin *gcePersistentDiskPlugin) Name() string {
|
||||||
if plugin.legacyMode {
|
|
||||||
return gcePersistentDiskPluginLegacyName
|
|
||||||
}
|
|
||||||
return gcePersistentDiskPluginName
|
return gcePersistentDiskPluginName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *gcePersistentDiskPlugin) CanSupport(spec *volume.Spec) bool {
|
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
|
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) {
|
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
|
var gce *api.GCEPersistentDiskVolumeSource
|
||||||
if spec.VolumeSource.GCEPersistentDisk != nil {
|
if spec.VolumeSource.GCEPersistentDisk != nil {
|
||||||
gce = spec.VolumeSource.GCEPersistentDisk
|
gce = spec.VolumeSource.GCEPersistentDisk
|
||||||
@ -112,7 +96,6 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, pod
|
|||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
diskMounter: &gceSafeFormatAndMount{mounter, exec.New()},
|
diskMounter: &gceSafeFormatAndMount{mounter, exec.New()},
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
legacyMode: false,
|
|
||||||
}, nil
|
}, 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) {
|
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{
|
return &gcePersistentDisk{
|
||||||
podUID: podUID,
|
podUID: podUID,
|
||||||
volName: volName,
|
volName: volName,
|
||||||
@ -133,7 +112,6 @@ func (plugin *gcePersistentDiskPlugin) newCleanerInternal(volName string, podUID
|
|||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
diskMounter: &gceSafeFormatAndMount{mounter, exec.New()},
|
diskMounter: &gceSafeFormatAndMount{mounter, exec.New()},
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
legacyMode: legacy,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +143,6 @@ type gcePersistentDisk struct {
|
|||||||
// diskMounter provides the interface that is used to mount the actual block device.
|
// diskMounter provides the interface that is used to mount the actual block device.
|
||||||
diskMounter mount.Interface
|
diskMounter mount.Interface
|
||||||
plugin *gcePersistentDiskPlugin
|
plugin *gcePersistentDiskPlugin
|
||||||
legacyMode bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func detachDiskLogError(pd *gcePersistentDisk) {
|
func detachDiskLogError(pd *gcePersistentDisk) {
|
||||||
@ -182,10 +159,6 @@ func (pd *gcePersistentDisk) SetUp() error {
|
|||||||
|
|
||||||
// SetUpAt attaches the disk and bind mounts to the volume path.
|
// SetUpAt attaches the disk and bind mounts to the volume path.
|
||||||
func (pd *gcePersistentDisk) SetUpAt(dir string) error {
|
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.
|
// TODO: handle failed mounts here.
|
||||||
mountpoint, err := pd.mounter.IsMountPoint(dir)
|
mountpoint, err := pd.mounter.IsMountPoint(dir)
|
||||||
glog.V(4).Infof("PersistentDisk set up: %s %v %v", dir, mountpoint, err)
|
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 {
|
func (pd *gcePersistentDisk) GetPath() string {
|
||||||
name := gcePersistentDiskPluginName
|
name := gcePersistentDiskPluginName
|
||||||
if pd.legacyMode {
|
|
||||||
name = gcePersistentDiskPluginLegacyName
|
|
||||||
}
|
|
||||||
return pd.plugin.host.GetPodVolumeDir(pd.podUID, util.EscapeQualifiedNameForDisk(name), pd.volName)
|
return pd.plugin.host.GetPodVolumeDir(pd.podUID, util.EscapeQualifiedNameForDisk(name), pd.volName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,35 +170,4 @@ func TestPlugin(t *testing.T) {
|
|||||||
if !fakeManager.detachCalled {
|
if !fakeManager.detachCalled {
|
||||||
t.Errorf("Detach watch not called")
|
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -32,19 +32,17 @@ import (
|
|||||||
|
|
||||||
// This is the primary entrypoint for volume plugins.
|
// This is the primary entrypoint for volume plugins.
|
||||||
func ProbeVolumePlugins() []volume.VolumePlugin {
|
func ProbeVolumePlugins() []volume.VolumePlugin {
|
||||||
return []volume.VolumePlugin{&gitRepoPlugin{nil, false}, &gitRepoPlugin{nil, true}}
|
return []volume.VolumePlugin{&gitRepoPlugin{nil}}
|
||||||
}
|
}
|
||||||
|
|
||||||
type gitRepoPlugin struct {
|
type gitRepoPlugin struct {
|
||||||
host volume.VolumeHost
|
host volume.VolumeHost
|
||||||
legacyMode bool // if set, plugin answers to the legacy name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.VolumePlugin = &gitRepoPlugin{}
|
var _ volume.VolumePlugin = &gitRepoPlugin{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gitRepoPluginName = "kubernetes.io/git-repo"
|
gitRepoPluginName = "kubernetes.io/git-repo"
|
||||||
gitRepoPluginLegacyName = "git"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) {
|
func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) {
|
||||||
@ -52,65 +50,46 @@ func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *gitRepoPlugin) Name() string {
|
func (plugin *gitRepoPlugin) Name() string {
|
||||||
if plugin.legacyMode {
|
|
||||||
return gitRepoPluginLegacyName
|
|
||||||
}
|
|
||||||
return gitRepoPluginName
|
return gitRepoPluginName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool {
|
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
|
return spec.VolumeSource.GitRepo != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *gitRepoPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
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{
|
return &gitRepo{
|
||||||
pod: *pod,
|
pod: *pod,
|
||||||
volName: spec.Name,
|
volName: spec.Name,
|
||||||
source: spec.VolumeSource.GitRepo.Repository,
|
source: spec.VolumeSource.GitRepo.Repository,
|
||||||
revision: spec.VolumeSource.GitRepo.Revision,
|
revision: spec.VolumeSource.GitRepo.Revision,
|
||||||
exec: exec.New(),
|
exec: exec.New(),
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
legacyMode: false,
|
opts: opts,
|
||||||
opts: opts,
|
mounter: mounter,
|
||||||
mounter: mounter,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *gitRepoPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
|
func (plugin *gitRepoPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
|
||||||
legacy := false
|
|
||||||
if plugin.legacyMode {
|
|
||||||
legacy = true
|
|
||||||
}
|
|
||||||
return &gitRepo{
|
return &gitRepo{
|
||||||
pod: api.Pod{ObjectMeta: api.ObjectMeta{UID: podUID}},
|
pod: api.Pod{ObjectMeta: api.ObjectMeta{UID: podUID}},
|
||||||
volName: volName,
|
volName: volName,
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
legacyMode: legacy,
|
mounter: mounter,
|
||||||
mounter: mounter,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// gitRepo volumes are directories which are pre-filled from a git repository.
|
// gitRepo volumes are directories which are pre-filled from a git repository.
|
||||||
// These do not persist beyond the lifetime of a pod.
|
// These do not persist beyond the lifetime of a pod.
|
||||||
type gitRepo struct {
|
type gitRepo struct {
|
||||||
volName string
|
volName string
|
||||||
pod api.Pod
|
pod api.Pod
|
||||||
source string
|
source string
|
||||||
revision string
|
revision string
|
||||||
exec exec.Interface
|
exec exec.Interface
|
||||||
plugin *gitRepoPlugin
|
plugin *gitRepoPlugin
|
||||||
legacyMode bool
|
opts volume.VolumeOptions
|
||||||
opts volume.VolumeOptions
|
mounter mount.Interface
|
||||||
mounter mount.Interface
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUp creates new directory and clones a git repo.
|
// 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()) {
|
if volumeutil.IsReady(gr.getMetaDir()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if gr.legacyMode {
|
|
||||||
return fmt.Errorf("legacy mode: can not create new instances")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap EmptyDir, let it do the setup.
|
// Wrap EmptyDir, let it do the setup.
|
||||||
wrapped, err := gr.plugin.host.NewWrapperBuilder(wrappedVolumeSpec, &gr.pod, gr.opts, gr.mounter)
|
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 {
|
func (gr *gitRepo) GetPath() string {
|
||||||
name := gitRepoPluginName
|
name := gitRepoPluginName
|
||||||
if gr.legacyMode {
|
|
||||||
name = gitRepoPluginLegacyName
|
|
||||||
}
|
|
||||||
return gr.plugin.host.GetPodVolumeDir(gr.pod.UID, util.EscapeQualifiedNameForDisk(name), gr.volName)
|
return gr.plugin.host.GetPodVolumeDir(gr.pod.UID, util.EscapeQualifiedNameForDisk(name), gr.volName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,33 +159,3 @@ func TestPlugin(t *testing.T) {
|
|||||||
t.Errorf("SetUp() failed: %v", err)
|
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user