Skip to content

Commit

Permalink
introduced func to get recyclable plugins, fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
markturansky committed May 26, 2015
1 parent f65a51b commit e024dc9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/volume/host_path/host_path.go
Expand Up @@ -33,6 +33,10 @@ func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.VolumePlugin{&hostPathPlugin{nil, newRecycler}}
}

func ProbeRecyclableVolumePlugins(recyclerFunc func(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error)) []volume.VolumePlugin {
return []volume.VolumePlugin{&hostPathPlugin{nil, recyclerFunc}}
}

type hostPathPlugin struct {
host volume.VolumeHost
// decouple creating recyclers by deferring to a function. Allows for easier testing.
Expand Down
7 changes: 2 additions & 5 deletions pkg/volume/util.go
Expand Up @@ -68,7 +68,7 @@ func ScrubPodVolumeAndWatchUntilCompletion(pod *api.Pod, client client.Interface
}

// the binder will eventually catch up and set status on Claims
watch := newPodWatch(client, pod.Namespace, pod.Name, 5)
watch := newPodWatch(client, pod.Namespace, pod.Name, 5 * time.Second)
defer watch.Stop()

success := false
Expand All @@ -82,10 +82,7 @@ func ScrubPodVolumeAndWatchUntilCompletion(pod *api.Pod, client client.Interface
success = true
break
} else {

// TODO how to handle pods that were killed by ActiveDeadlineSeconds

glog.V(5).Infof("Pod event %+v\n", pod)
glog.V(5).Infof("Pod event %+v\n", pod.Name + " " + string(pod.Status.Phase))
}
}

Expand Down
23 changes: 22 additions & 1 deletion pkg/volumeclaimbinder/persistent_volume_claim_binder_test.go
Expand Up @@ -199,7 +199,7 @@ func TestBindingWithExamples(t *testing.T) {
}

plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(host_path.ProbeVolumePlugins(), volume.NewFakeVolumeHost("fake", nil, nil))
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))

recycler := &PersistentVolumeRecycler{
kubeClient: client,
Expand Down Expand Up @@ -308,3 +308,24 @@ func (c *mockBinderClient) UpdatePersistentVolumeClaim(claim *api.PersistentVolu
func (c *mockBinderClient) UpdatePersistentVolumeClaimStatus(claim *api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error) {
return claim, nil
}


func newMockRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) {
return &mockRecycler{
path: spec.PersistentVolumeSource.HostPath.Path,
}, nil
}

type mockRecycler struct {
path string
host volume.VolumeHost
}

func (r *mockRecycler) GetPath() string {
return r.path
}

func (r *mockRecycler) Recycle() error {
// return nil means recycle passed
return nil
}

0 comments on commit e024dc9

Please sign in to comment.