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

Update Attacher/Detacher interfaces. #25325

Merged
merged 1 commit into from May 11, 2016
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
10 changes: 5 additions & 5 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

// TODO(swagiaal): This will block until the sync loop until device is attached
// so all of this should be moved to a mount/unmount manager which does it asynchronously
if err = detacher.WaitForDetach(devicePath, maxWaitForVolumeOps); err != nil {
glog.Errorf("Error while waiting for detach: %v", err)
}
go func() {
if err = detacher.WaitForDetach(devicePath, maxWaitForVolumeOps); err != nil {
glog.Errorf("Error while waiting for detach: %v", err)
}
}()
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,6 @@ func TestCleanupOrphanedVolumes(t *testing.T) {
if detacher.DetachCallCount != 1 {
t.Errorf("Expected Detach to be called")
}
if detacher.WaitForDetachCallCount != 1 {
t.Errorf("Expected WaitForDetach to be called")
}
if detacher.UnmountDeviceCallCount != 1 {
t.Errorf("Expected UnmountDevice to be called")
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/kubelet/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
return nil, err
}

deviceMountPath := attacher.GetDeviceMountPath(volSpec)
if err = attacher.MountDevice(devicePath, deviceMountPath, kl.mounter); err != nil {
deviceMountPath := attacher.GetDeviceMountPath(&volumeHost{kl}, volSpec)
if err = attacher.MountDevice(volSpec, devicePath, deviceMountPath, kl.mounter); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -303,7 +303,7 @@ func (kl *Kubelet) newVolumeAttacherFromPlugins(spec *volume.Spec, pod *api.Pod,
return nil, nil
}

attacher, err := plugin.NewAttacher(spec)
attacher, err := plugin.NewAttacher()
if err != nil {
return nil, fmt.Errorf("failed to instantiate volume attacher for %s: %v", spec.Name(), err)
}
Expand Down Expand Up @@ -348,10 +348,9 @@ func (kl *Kubelet) newVolumeDetacherFromPlugins(kind string, name string, podUID
return nil, nil
}

detacher, err := plugin.NewDetacher(name, podUID)
detacher, err := plugin.NewDetacher()
if err != nil {
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
}
4 changes: 2 additions & 2 deletions pkg/volume/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ type ProvisionableVolumePlugin interface {
// to a node before mounting.
type AttachableVolumePlugin interface {
VolumePlugin
NewAttacher(spec *Spec) (Attacher, error)
NewDetacher(name string, podUID types.UID) (Detacher, error)
NewAttacher() (Attacher, error)
NewDetacher() (Detacher, error)
}

// VolumeHost is an interface that plugins can use to access the kubelet.
Expand Down
8 changes: 4 additions & 4 deletions pkg/volume/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ func (plugin *FakeVolumePlugin) NewUnmounter(volName string, podUID types.UID) (
return volume, nil
}

func (plugin *FakeVolumePlugin) NewAttacher(spec *Spec) (Attacher, error) {
func (plugin *FakeVolumePlugin) NewAttacher() (Attacher, error) {
plugin.NewAttacherCallCount = plugin.NewAttacherCallCount + 1
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
return plugin.getFakeVolume(&plugin.Detachers), nil
}
Expand Down Expand Up @@ -273,12 +273,12 @@ func (fv *FakeVolume) WaitForAttach(spec *Spec, spectimeout time.Duration) (stri
return "", nil
}

func (fv *FakeVolume) GetDeviceMountPath(spec *Spec) string {
func (fv *FakeVolume) GetDeviceMountPath(host VolumeHost, spec *Spec) string {
fv.GetDeviceMountPathCallCount++
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++
return nil
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ type Deleter interface {

// Attacher can attach a volume to a node.
type Attacher interface {
Volume

// Attach the volume specified by the given spec to the given host
Attach(spec *Spec, hostName string) error

Expand All @@ -145,11 +143,11 @@ type Attacher interface {
// GetDeviceMountPath returns a path where the device should
// be mounted after it is attached. This is a global mount
// 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
// 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.
Expand All @@ -159,14 +157,14 @@ type Detacher interface {
Detach(deviceMountPath string, hostName string) error

// 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.
WaitForDetach(devicePath string, timout time.Duration) error
WaitForDetach(devicePath string, timeout time.Duration) error

// UnmountDevice unmounts the global mount of the disk. This
// should only be called once all bind mounts have been
// unmounted.
UnmountDevice(globalMountPath string, mounter mount.Interface) error
UnmountDevice(deviceMountPath string, mounter mount.Interface) error
}

func RenameDirectory(oldPath, newName string) (string, error) {
Expand Down