Refactor volume interfaces to receive pod instead of ObjectReference

This commit is contained in:
Paul Morie
2015-05-10 20:12:57 -04:00
parent 738f403eea
commit cd359ffa73
21 changed files with 93 additions and 88 deletions

View File

@@ -51,8 +51,8 @@ func (plugin *persistentClaimPlugin) CanSupport(spec *volume.Spec) bool {
return spec.VolumeSource.PersistentVolumeClaimVolumeSource != nil
}
func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
claim, err := plugin.host.GetKubeClient().PersistentVolumeClaims(podRef.Namespace).Get(spec.VolumeSource.PersistentVolumeClaimVolumeSource.ClaimName)
func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
claim, err := plugin.host.GetKubeClient().PersistentVolumeClaims(pod.Namespace).Get(spec.VolumeSource.PersistentVolumeClaimVolumeSource.ClaimName)
if err != nil {
glog.Errorf("Error finding claim: %+v\n", spec.VolumeSource.PersistentVolumeClaimVolumeSource.ClaimName)
return nil, err
@@ -68,7 +68,7 @@ func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, podRef *api.O
return nil, err
}
builder, err := plugin.host.NewWrapperBuilder(volume.NewSpecFromPersistentVolume(pv), podRef, opts, mounter)
builder, err := plugin.host.NewWrapperBuilder(volume.NewSpecFromPersistentVolume(pv), pod, opts, mounter)
if err != nil {
glog.Errorf("Error creating builder for claim: %+v\n", claim.Name)
return nil, err

View File

@@ -169,7 +169,8 @@ func TestNewBuilder(t *testing.T) {
Name: "vol1",
VolumeSource: item.podVolume,
}
builder, err := plug.NewBuilder(spec, &api.ObjectReference{UID: types.UID("poduid")}, volume.VolumeOptions{}, nil)
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
builder, err := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
@@ -229,7 +230,8 @@ func TestNewBuilderClaimNotBound(t *testing.T) {
Name: "vol1",
VolumeSource: podVolume,
}
builder, err := plug.NewBuilder(spec, &api.ObjectReference{UID: types.UID("poduid")}, volume.VolumeOptions{}, nil)
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
builder, err := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
if builder != nil {
t.Errorf("Expected a nil builder if the claim wasn't bound")
}