Refactored Volume plugins to use InternalVolume instead of API types

This commit is contained in:
markturansky
2015-04-14 12:29:33 -04:00
parent f7ae442a02
commit e1481fb9c2
22 changed files with 200 additions and 127 deletions

View File

@@ -50,11 +50,8 @@ func (plugin *nfsPlugin) Name() string {
return nfsPluginName
}
func (plugin *nfsPlugin) CanSupport(spec *api.Volume) bool {
if spec.VolumeSource.NFS != nil {
return true
}
return false
func (plugin *nfsPlugin) CanSupport(spec *volume.Spec) bool {
return spec.VolumeSource.NFS != nil
}
func (plugin *nfsPlugin) GetAccessModes() []api.AccessModeType {
@@ -65,11 +62,11 @@ func (plugin *nfsPlugin) GetAccessModes() []api.AccessModeType {
}
}
func (plugin *nfsPlugin) NewBuilder(spec *api.Volume, podRef *api.ObjectReference, _ volume.VolumeOptions) (volume.Builder, error) {
func (plugin *nfsPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, _ volume.VolumeOptions) (volume.Builder, error) {
return plugin.newBuilderInternal(spec, podRef, plugin.mounter)
}
func (plugin *nfsPlugin) newBuilderInternal(spec *api.Volume, podRef *api.ObjectReference, mounter nfsMountInterface) (volume.Builder, error) {
func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, podRef *api.ObjectReference, mounter nfsMountInterface) (volume.Builder, error) {
return &nfs{
volName: spec.Name,
server: spec.VolumeSource.NFS.Server,

View File

@@ -37,10 +37,10 @@ func TestCanSupport(t *testing.T) {
if plug.Name() != "kubernetes.io/nfs" {
t.Errorf("Wrong name: %s", plug.Name())
}
if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{}}}) {
if !plug.CanSupport(&volume.Spec{Name: "foo", VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{}}}) {
t.Errorf("Expected true")
}
if plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{}}) {
if plug.CanSupport(&volume.Spec{Name: "foo", VolumeSource: api.VolumeSource{}}) {
t.Errorf("Expected false")
}
}
@@ -108,7 +108,7 @@ func TestPlugin(t *testing.T) {
VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{"localhost", "/tmp", false}},
}
fake := &fakeNFSMounter{}
builder, err := plug.(*nfsPlugin).newBuilderInternal(spec, &api.ObjectReference{UID: types.UID("poduid")}, fake)
builder, err := plug.(*nfsPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), &api.ObjectReference{UID: types.UID("poduid")}, fake)
volumePath := builder.GetPath()
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)