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

Only call Detacher after the final unmount #21499

Merged
merged 1 commit into from Feb 27, 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
9 changes: 7 additions & 2 deletions pkg/kubelet/kubelet.go
Expand Up @@ -1926,14 +1926,19 @@ func (kl *Kubelet) cleanupOrphanedVolumes(pods []*api.Pod, runningPods []*kubeco
glog.Warningf("Orphaned volume %q found, tearing down volume", name)
// TODO(yifan): Refactor this hacky string manipulation.
kl.volumeManager.DeleteVolumes(types.UID(parts[0]))
// Get path reference count
refs, err := mount.GetMountRefs(kl.mounter, cleanerTuple.Cleaner.GetPath())
if err != nil {
return fmt.Errorf("Could not get mount path references %v", err)
}
//TODO (jonesdl) This should not block other kubelet synchronization procedures
err := cleanerTuple.Cleaner.TearDown()
err = cleanerTuple.Cleaner.TearDown()
if err != nil {
glog.Errorf("Could not tear down volume %q: %v", name, err)
}

// volume is unmounted. some volumes also require detachment from the node.
if cleanerTuple.Detacher != nil {
if cleanerTuple.Detacher != nil && len(refs) == 1 {
detacher := *cleanerTuple.Detacher
err = detacher.Detach()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/kubelet/kubelet_test.go
Expand Up @@ -59,6 +59,7 @@ import (
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/bandwidth"
"k8s.io/kubernetes/pkg/util/mount"
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/wait"
Expand Down Expand Up @@ -93,6 +94,7 @@ type TestKubelet struct {
fakeKubeClient *fake.Clientset
fakeMirrorClient *kubepod.FakeMirrorClient
fakeClock *util.FakeClock
mounter mount.Interface
}

func newTestKubelet(t *testing.T) *TestKubelet {
Expand Down Expand Up @@ -192,7 +194,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet.pleg = pleg.NewGenericPLEG(fakeRuntime, 100, time.Hour, nil)
kubelet.clock = fakeClock
kubelet.setNodeStatusFuncs = kubelet.defaultNodeStatusFuncs()
return &TestKubelet{kubelet, fakeRuntime, mockCadvisor, fakeKubeClient, fakeMirrorClient, fakeClock}
return &TestKubelet{kubelet, fakeRuntime, mockCadvisor, fakeKubeClient, fakeMirrorClient, fakeClock, nil}
}

func newTestPods(count int) []*api.Pod {
Expand Down Expand Up @@ -564,6 +566,7 @@ func TestGetPodVolumesFromDisk(t *testing.T) {
func TestCleanupOrphanedVolumes(t *testing.T) {
testKubelet := newTestKubelet(t)
kubelet := testKubelet.kubelet
kubelet.mounter = &mount.FakeMounter{}
kubeClient := testKubelet.fakeKubeClient
plug := &volume.FakeVolumePlugin{PluginName: "fake", Host: nil}
kubelet.volumePluginMgr.InitPlugins([]volume.VolumePlugin{plug}, &volumeHost{kubelet})
Expand Down