mirror of https://github.com/k3s-io/k3s
Update Attacher/Detacher interfaces.
- Expand arguments for Attach/Detach interfaces - Run waitForDetach asynchronouslypull/6/head
parent
fe135fc251
commit
5258392e6a
|
@ -2026,11 +2026,11 @@ func (kl *Kubelet) cleanupOrphanedVolumes(pods []*api.Pod, runningPods []*kubeco
|
||||||
glog.Errorf("Could not detach volume %q at %q: %v", name, volumePath, err)
|
glog.Errorf("Could not detach volume %q at %q: %v", name, volumePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(swagiaal): This will block until the sync loop until device is attached
|
go func() {
|
||||||
// so all of this should be moved to a mount/unmount manager which does it asynchronously
|
if err = detacher.WaitForDetach(devicePath, maxWaitForVolumeOps); err != nil {
|
||||||
if err = detacher.WaitForDetach(devicePath, maxWaitForVolumeOps); err != nil {
|
glog.Errorf("Error while waiting for detach: %v", err)
|
||||||
glog.Errorf("Error while waiting for detach: %v", err)
|
}
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -558,9 +558,6 @@ func TestCleanupOrphanedVolumes(t *testing.T) {
|
||||||
if detacher.DetachCallCount != 1 {
|
if detacher.DetachCallCount != 1 {
|
||||||
t.Errorf("Expected Detach to be called")
|
t.Errorf("Expected Detach to be called")
|
||||||
}
|
}
|
||||||
if detacher.WaitForDetachCallCount != 1 {
|
|
||||||
t.Errorf("Expected WaitForDetach to be called")
|
|
||||||
}
|
|
||||||
if detacher.UnmountDeviceCallCount != 1 {
|
if detacher.UnmountDeviceCallCount != 1 {
|
||||||
t.Errorf("Expected UnmountDevice to be called")
|
t.Errorf("Expected UnmountDevice to be called")
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,8 +153,8 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceMountPath := attacher.GetDeviceMountPath(volSpec)
|
deviceMountPath := attacher.GetDeviceMountPath(&volumeHost{kl}, volSpec)
|
||||||
if err = attacher.MountDevice(devicePath, deviceMountPath, kl.mounter); err != nil {
|
if err = attacher.MountDevice(volSpec, devicePath, deviceMountPath, kl.mounter); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ func (kl *Kubelet) newVolumeAttacherFromPlugins(spec *volume.Spec, pod *api.Pod,
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
attacher, err := plugin.NewAttacher(spec)
|
attacher, err := plugin.NewAttacher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to instantiate volume attacher for %s: %v", spec.Name(), err)
|
return nil, fmt.Errorf("failed to instantiate volume attacher for %s: %v", spec.Name(), err)
|
||||||
}
|
}
|
||||||
|
@ -348,10 +348,9 @@ func (kl *Kubelet) newVolumeDetacherFromPlugins(kind string, name string, podUID
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
detacher, err := plugin.NewDetacher(name, podUID)
|
detacher, err := plugin.NewDetacher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to instantiate volume plugin for %s/%s: %v", podUID, kind, err)
|
return nil, fmt.Errorf("failed to instantiate volume plugin for %s/%s: %v", podUID, kind, err)
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("Used volume plugin %q to detach %s/%s", plugin.Name(), podUID, kind)
|
|
||||||
return detacher, nil
|
return detacher, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,8 @@ type ProvisionableVolumePlugin interface {
|
||||||
// to a node before mounting.
|
// to a node before mounting.
|
||||||
type AttachableVolumePlugin interface {
|
type AttachableVolumePlugin interface {
|
||||||
VolumePlugin
|
VolumePlugin
|
||||||
NewAttacher(spec *Spec) (Attacher, error)
|
NewAttacher() (Attacher, error)
|
||||||
NewDetacher(name string, podUID types.UID) (Detacher, error)
|
NewDetacher() (Detacher, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VolumeHost is an interface that plugins can use to access the kubelet.
|
// VolumeHost is an interface that plugins can use to access the kubelet.
|
||||||
|
|
|
@ -189,12 +189,12 @@ func (plugin *FakeVolumePlugin) NewUnmounter(volName string, podUID types.UID) (
|
||||||
return volume, nil
|
return volume, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *FakeVolumePlugin) NewAttacher(spec *Spec) (Attacher, error) {
|
func (plugin *FakeVolumePlugin) NewAttacher() (Attacher, error) {
|
||||||
plugin.NewAttacherCallCount = plugin.NewAttacherCallCount + 1
|
plugin.NewAttacherCallCount = plugin.NewAttacherCallCount + 1
|
||||||
return plugin.getFakeVolume(&plugin.Attachers), nil
|
return plugin.getFakeVolume(&plugin.Attachers), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *FakeVolumePlugin) NewDetacher(name string, podUID types.UID) (Detacher, error) {
|
func (plugin *FakeVolumePlugin) NewDetacher() (Detacher, error) {
|
||||||
plugin.NewDetacherCallCount = plugin.NewDetacherCallCount + 1
|
plugin.NewDetacherCallCount = plugin.NewDetacherCallCount + 1
|
||||||
return plugin.getFakeVolume(&plugin.Detachers), nil
|
return plugin.getFakeVolume(&plugin.Detachers), nil
|
||||||
}
|
}
|
||||||
|
@ -273,12 +273,12 @@ func (fv *FakeVolume) WaitForAttach(spec *Spec, spectimeout time.Duration) (stri
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fv *FakeVolume) GetDeviceMountPath(spec *Spec) string {
|
func (fv *FakeVolume) GetDeviceMountPath(host VolumeHost, spec *Spec) string {
|
||||||
fv.GetDeviceMountPathCallCount++
|
fv.GetDeviceMountPathCallCount++
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fv *FakeVolume) MountDevice(devicePath string, deviceMountPath string, mounter mount.Interface) error {
|
func (fv *FakeVolume) MountDevice(spec *Spec, devicePath string, deviceMountPath string, mounter mount.Interface) error {
|
||||||
fv.MountDeviceCallCount++
|
fv.MountDeviceCallCount++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,6 @@ type Deleter interface {
|
||||||
|
|
||||||
// Attacher can attach a volume to a node.
|
// Attacher can attach a volume to a node.
|
||||||
type Attacher interface {
|
type Attacher interface {
|
||||||
Volume
|
|
||||||
|
|
||||||
// Attach the volume specified by the given spec to the given host
|
// Attach the volume specified by the given spec to the given host
|
||||||
Attach(spec *Spec, hostName string) error
|
Attach(spec *Spec, hostName string) error
|
||||||
|
|
||||||
|
@ -145,11 +143,11 @@ type Attacher interface {
|
||||||
// GetDeviceMountPath returns a path where the device should
|
// GetDeviceMountPath returns a path where the device should
|
||||||
// be mounted after it is attached. This is a global mount
|
// be mounted after it is attached. This is a global mount
|
||||||
// point which should be bind mounted for individual volumes.
|
// point which should be bind mounted for individual volumes.
|
||||||
GetDeviceMountPath(spec *Spec) string
|
GetDeviceMountPath(host VolumeHost, spec *Spec) string
|
||||||
|
|
||||||
// MountDevice mounts the disk to a global path which
|
// MountDevice mounts the disk to a global path which
|
||||||
// individual pods can then bind mount
|
// individual pods can then bind mount
|
||||||
MountDevice(devicePath string, deviceMountPath string, mounter mount.Interface) error
|
MountDevice(spec *Spec, devicePath string, deviceMountPath string, mounter mount.Interface) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detacher can detach a volume from a node.
|
// Detacher can detach a volume from a node.
|
||||||
|
@ -159,14 +157,14 @@ type Detacher interface {
|
||||||
Detach(deviceMountPath string, hostName string) error
|
Detach(deviceMountPath string, hostName string) error
|
||||||
|
|
||||||
// WaitForDetach blocks until the device is detached from this
|
// WaitForDetach blocks until the device is detached from this
|
||||||
// node. If the device does not detach within the given timout
|
// node. If the device does not detach within the given timeout
|
||||||
// period an error is returned.
|
// period an error is returned.
|
||||||
WaitForDetach(devicePath string, timout time.Duration) error
|
WaitForDetach(devicePath string, timeout time.Duration) error
|
||||||
|
|
||||||
// UnmountDevice unmounts the global mount of the disk. This
|
// UnmountDevice unmounts the global mount of the disk. This
|
||||||
// should only be called once all bind mounts have been
|
// should only be called once all bind mounts have been
|
||||||
// unmounted.
|
// unmounted.
|
||||||
UnmountDevice(globalMountPath string, mounter mount.Interface) error
|
UnmountDevice(deviceMountPath string, mounter mount.Interface) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenameDirectory(oldPath, newName string) (string, error) {
|
func RenameDirectory(oldPath, newName string) (string, error) {
|
||||||
|
|
Loading…
Reference in New Issue