mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-28 21:55:48 +00:00
Abstract node side functionality of attachable plugins
- Expand Attacher/Detacher interfaces to break up work more explicitly. - Add arguments to all functions to avoid having implementers store the data needed for operations. - Expand unit tests to check that Attach, Detach, WaitForAttach, WaitForDetach, MountDevice, and UnmountDevice get call where appropriet.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
@@ -137,6 +138,11 @@ type FakeVolumePlugin struct {
|
||||
LastProvisionerOptions VolumeOptions
|
||||
NewAttacherCallCount int
|
||||
NewDetacherCallCount int
|
||||
|
||||
Mounters []*FakeVolume
|
||||
Unmounters []*FakeVolume
|
||||
Attachers []*FakeVolume
|
||||
Detachers []*FakeVolume
|
||||
}
|
||||
|
||||
var _ VolumePlugin = &FakeVolumePlugin{}
|
||||
@@ -145,6 +151,12 @@ var _ DeletableVolumePlugin = &FakeVolumePlugin{}
|
||||
var _ ProvisionableVolumePlugin = &FakeVolumePlugin{}
|
||||
var _ AttachableVolumePlugin = &FakeVolumePlugin{}
|
||||
|
||||
func (plugin *FakeVolumePlugin) getFakeVolume(list *[]*FakeVolume) *FakeVolume {
|
||||
volume := &FakeVolume{}
|
||||
*list = append(*list, volume)
|
||||
return volume
|
||||
}
|
||||
|
||||
func (plugin *FakeVolumePlugin) Init(host VolumeHost) error {
|
||||
plugin.Host = host
|
||||
return nil
|
||||
@@ -160,21 +172,31 @@ func (plugin *FakeVolumePlugin) CanSupport(spec *Spec) bool {
|
||||
}
|
||||
|
||||
func (plugin *FakeVolumePlugin) NewMounter(spec *Spec, pod *api.Pod, opts VolumeOptions) (Mounter, error) {
|
||||
return &FakeVolume{pod.UID, spec.Name(), plugin, MetricsNil{}}, nil
|
||||
volume := plugin.getFakeVolume(&plugin.Mounters)
|
||||
volume.PodUID = pod.UID
|
||||
volume.VolName = spec.Name()
|
||||
volume.Plugin = plugin
|
||||
volume.MetricsNil = MetricsNil{}
|
||||
return volume, nil
|
||||
}
|
||||
|
||||
func (plugin *FakeVolumePlugin) NewUnmounter(volName string, podUID types.UID) (Unmounter, error) {
|
||||
return &FakeVolume{podUID, volName, plugin, MetricsNil{}}, nil
|
||||
volume := plugin.getFakeVolume(&plugin.Unmounters)
|
||||
volume.PodUID = podUID
|
||||
volume.VolName = volName
|
||||
volume.Plugin = plugin
|
||||
volume.MetricsNil = MetricsNil{}
|
||||
return volume, nil
|
||||
}
|
||||
|
||||
func (plugin *FakeVolumePlugin) NewAttacher(spec *Spec) (Attacher, error) {
|
||||
plugin.NewAttacherCallCount = plugin.NewAttacherCallCount + 1
|
||||
return &FakeVolume{}, nil
|
||||
return plugin.getFakeVolume(&plugin.Attachers), nil
|
||||
}
|
||||
|
||||
func (plugin *FakeVolumePlugin) NewDetacher(name string, podUID types.UID) (Detacher, error) {
|
||||
plugin.NewDetacherCallCount = plugin.NewDetacherCallCount + 1
|
||||
return &FakeVolume{}, nil
|
||||
return plugin.getFakeVolume(&plugin.Detachers), nil
|
||||
}
|
||||
|
||||
func (plugin *FakeVolumePlugin) NewRecycler(spec *Spec) (Recycler, error) {
|
||||
@@ -199,6 +221,16 @@ type FakeVolume struct {
|
||||
VolName string
|
||||
Plugin *FakeVolumePlugin
|
||||
MetricsNil
|
||||
|
||||
SetUpCallCount int
|
||||
TearDownCallCount int
|
||||
AttachCallCount int
|
||||
DetachCallCount int
|
||||
WaitForAttachCallCount int
|
||||
WaitForDetachCallCount int
|
||||
MountDeviceCallCount int
|
||||
UnmountDeviceCallCount int
|
||||
GetDeviceMountPathCallCount int
|
||||
}
|
||||
|
||||
func (_ *FakeVolume) GetAttributes() Attributes {
|
||||
@@ -210,6 +242,7 @@ func (_ *FakeVolume) GetAttributes() Attributes {
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) SetUp(fsGroup *int64) error {
|
||||
fv.SetUpCallCount++
|
||||
return fv.SetUpAt(fv.GetPath(), fsGroup)
|
||||
}
|
||||
|
||||
@@ -222,6 +255,7 @@ func (fv *FakeVolume) GetPath() string {
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) TearDown() error {
|
||||
fv.TearDownCallCount++
|
||||
return fv.TearDownAt(fv.GetPath())
|
||||
}
|
||||
|
||||
@@ -229,11 +263,38 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
|
||||
return os.RemoveAll(dir)
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) Attach() error {
|
||||
func (fv *FakeVolume) Attach(spec *Spec, hostName string) error {
|
||||
fv.AttachCallCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) Detach() error {
|
||||
func (fv *FakeVolume) WaitForAttach(spec *Spec, spectimeout time.Duration) (string, error) {
|
||||
fv.WaitForAttachCallCount++
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) GetDeviceMountPath(spec *Spec) string {
|
||||
fv.GetDeviceMountPathCallCount++
|
||||
return ""
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) MountDevice(devicePath string, deviceMountPath string, mounter mount.Interface) error {
|
||||
fv.MountDeviceCallCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) Detach(deviceMountPath string, hostName string) error {
|
||||
fv.DetachCallCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) WaitForDetach(devicePath string, timeout time.Duration) error {
|
||||
fv.WaitForDetachCallCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fv *FakeVolume) UnmountDevice(globalMountPath string, mounter mount.Interface) error {
|
||||
fv.UnmountDeviceCallCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user