Fix persistent volumes.
Check Spec.PersistentVolumeSource in NFS, RBD, Gluster and iSCSI volume plugins.
This commit is contained in:

committed by
markturansky

parent
74b688dc0e
commit
d2b4ae4df4
@@ -65,7 +65,8 @@ func (plugin *glusterfsPlugin) GetAccessModes() []api.PersistentVolumeAccessMode
|
||||
}
|
||||
|
||||
func (plugin *glusterfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
ep_name := spec.VolumeSource.Glusterfs.EndpointsName
|
||||
source := plugin.getGlusterVolumeSource(spec)
|
||||
ep_name := source.EndpointsName
|
||||
ns := pod.Namespace
|
||||
ep, err := plugin.host.GetKubeClient().Endpoints(ns).Get(ep_name)
|
||||
if err != nil {
|
||||
@@ -76,12 +77,21 @@ func (plugin *glusterfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ vol
|
||||
return plugin.newBuilderInternal(spec, ep, pod, mounter, exec.New())
|
||||
}
|
||||
|
||||
func (plugin *glusterfsPlugin) getGlusterVolumeSource(spec *volume.Spec) *api.GlusterfsVolumeSource {
|
||||
if spec.VolumeSource.Glusterfs != nil {
|
||||
return spec.VolumeSource.Glusterfs
|
||||
} else {
|
||||
return spec.PersistentVolumeSource.Glusterfs
|
||||
}
|
||||
}
|
||||
|
||||
func (plugin *glusterfsPlugin) newBuilderInternal(spec *volume.Spec, ep *api.Endpoints, pod *api.Pod, mounter mount.Interface, exe exec.Interface) (volume.Builder, error) {
|
||||
source := plugin.getGlusterVolumeSource(spec)
|
||||
return &glusterfs{
|
||||
volName: spec.Name,
|
||||
hosts: ep,
|
||||
path: spec.VolumeSource.Glusterfs.Path,
|
||||
readonly: spec.VolumeSource.Glusterfs.ReadOnly,
|
||||
path: source.Path,
|
||||
readonly: source.ReadOnly,
|
||||
mounter: mounter,
|
||||
exe: exe,
|
||||
pod: pod,
|
||||
|
@@ -70,17 +70,13 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
|
||||
return false
|
||||
}
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/glusterfs")
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
}
|
||||
spec := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{Glusterfs: &api.GlusterfsVolumeSource{"ep", "vol", false}},
|
||||
}
|
||||
ep := &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "foo"}, Subsets: []api.EndpointSubset{{
|
||||
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}}}}
|
||||
var fcmd exec.FakeCmd
|
||||
@@ -98,7 +94,7 @@ func TestPlugin(t *testing.T) {
|
||||
},
|
||||
}
|
||||
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
|
||||
builder, err := plug.(*glusterfsPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), ep, pod, &mount.FakeMounter{}, &fake)
|
||||
builder, err := plug.(*glusterfsPlugin).newBuilderInternal(spec, ep, pod, &mount.FakeMounter{}, &fake)
|
||||
volumePath := builder.GetPath()
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Builder: %v", err)
|
||||
@@ -136,3 +132,26 @@ func TestPlugin(t *testing.T) {
|
||||
t.Errorf("SetUp() failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginVolume(t *testing.T) {
|
||||
vol := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{Glusterfs: &api.GlusterfsVolumeSource{"ep", "vol", false}},
|
||||
}
|
||||
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
||||
}
|
||||
|
||||
func TestPluginPersistentVolume(t *testing.T) {
|
||||
vol := &api.PersistentVolume{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "vol1",
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
Glusterfs: &api.GlusterfsVolumeSource{"ep", "vol", false},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
|
||||
}
|
||||
|
Reference in New Issue
Block a user