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:
Sami Wagiaalla
2016-04-29 15:29:59 -04:00
parent ad86986c87
commit 71e7dba845
6 changed files with 190 additions and 17 deletions

View File

@@ -141,6 +141,9 @@ const (
ContainerGCPeriod = time.Minute
// Period for performing image garbage collection.
ImageGCPeriod = 5 * time.Minute
// Maximum period to wait for pod volume setup operations
maxWaitForVolumeOps = 20 * time.Minute
)
// SyncHandler is an interface implemented by Kubelet, for testability
@@ -2108,11 +2111,27 @@ func (kl *Kubelet) cleanupOrphanedVolumes(pods []*api.Pod, runningPods []*kubeco
// volume is unmounted. some volumes also require detachment from the node.
if cleaner.Detacher != nil && len(refs) == 1 {
detacher := *cleaner.Detacher
err = detacher.Detach()
devicePath, _, err := mount.GetDeviceNameFromMount(kl.mounter, refs[0])
if err != nil {
glog.Errorf("Could not find device path %v", err)
}
if err = detacher.UnmountDevice(refs[0], kl.mounter); err != nil {
glog.Errorf("Could not unmount the global mount for %q: %v", name, err)
}
err = detacher.Detach(refs[0], kl.hostname)
if err != nil {
glog.Errorf("Could not detach volume %q: %v", name, 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)
}
}
}
}