mirror of https://github.com/k3s-io/k3s
Fix persistent volumes.
Check Spec.PersistentVolumeSource in NFS, RBD, Gluster and iSCSI volume plugins.pull/6/head
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))
|
||||
}
|
||||
|
|
|
@ -80,7 +80,13 @@ func (plugin *ISCSIPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.
|
|||
}
|
||||
|
||||
func (plugin *ISCSIPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID, manager diskManager, mounter mount.Interface) (volume.Builder, error) {
|
||||
iscsi := spec.VolumeSource.ISCSI
|
||||
var iscsi *api.ISCSIVolumeSource
|
||||
if spec.VolumeSource.ISCSI != nil {
|
||||
iscsi = spec.VolumeSource.ISCSI
|
||||
} else {
|
||||
iscsi = spec.PersistentVolumeSource.ISCSI
|
||||
}
|
||||
|
||||
lun := strconv.Itoa(iscsi.Lun)
|
||||
|
||||
return &iscsiDisk{
|
||||
|
|
|
@ -96,7 +96,7 @@ func (fake *fakeDiskManager) DetachDisk(disk iscsiDisk, mntPath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
|
@ -104,20 +104,9 @@ func TestPlugin(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
}
|
||||
spec := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{
|
||||
ISCSI: &api.ISCSIVolumeSource{
|
||||
TargetPortal: "127.0.0.1:3260",
|
||||
IQN: "iqn.2014-12.server:storage.target01",
|
||||
FSType: "ext4",
|
||||
Lun: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
fakeManager := &fakeDiskManager{}
|
||||
fakeMounter := &mount.FakeMounter{}
|
||||
builder, err := plug.(*ISCSIPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), types.UID("poduid"), fakeManager, fakeMounter)
|
||||
builder, err := plug.(*ISCSIPlugin).newBuilderInternal(spec, types.UID("poduid"), fakeManager, fakeMounter)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Builder: %v", err)
|
||||
}
|
||||
|
@ -172,3 +161,37 @@ func TestPlugin(t *testing.T) {
|
|||
t.Errorf("Detach was not called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginVolume(t *testing.T) {
|
||||
vol := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{
|
||||
ISCSI: &api.ISCSIVolumeSource{
|
||||
TargetPortal: "127.0.0.1:3260",
|
||||
IQN: "iqn.2014-12.server:storage.target01",
|
||||
FSType: "ext4",
|
||||
Lun: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
||||
}
|
||||
|
||||
func TestPluginPersistentVolume(t *testing.T) {
|
||||
vol := &api.PersistentVolume{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "vol1",
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
ISCSI: &api.ISCSIVolumeSource{
|
||||
TargetPortal: "127.0.0.1:3260",
|
||||
IQN: "iqn.2014-12.server:storage.target01",
|
||||
FSType: "ext4",
|
||||
Lun: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
|
||||
}
|
||||
|
|
|
@ -68,15 +68,23 @@ func (plugin *nfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
|
|||
}
|
||||
|
||||
func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mounter mount.Interface) (volume.Builder, error) {
|
||||
var source *api.NFSVolumeSource
|
||||
|
||||
if spec.VolumeSource.NFS != nil {
|
||||
source = spec.VolumeSource.NFS
|
||||
} else {
|
||||
source = spec.PersistentVolumeSource.NFS
|
||||
}
|
||||
return &nfs{
|
||||
volName: spec.Name,
|
||||
server: spec.VolumeSource.NFS.Server,
|
||||
exportPath: spec.VolumeSource.NFS.Path,
|
||||
readOnly: spec.VolumeSource.NFS.ReadOnly,
|
||||
server: source.Server,
|
||||
exportPath: source.Path,
|
||||
readOnly: source.ReadOnly,
|
||||
mounter: mounter,
|
||||
pod: pod,
|
||||
plugin: plugin,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (plugin *nfsPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
|
||||
|
|
|
@ -69,20 +69,16 @@ 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/nfs")
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
}
|
||||
spec := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{"localhost", "/tmp", false}},
|
||||
}
|
||||
fake := &mount.FakeMounter{}
|
||||
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
|
||||
builder, err := plug.(*nfsPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), pod, fake)
|
||||
builder, err := plug.(*nfsPlugin).newBuilderInternal(spec, pod, fake)
|
||||
volumePath := builder.GetPath()
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Builder: %v", err)
|
||||
|
@ -141,3 +137,26 @@ func TestPlugin(t *testing.T) {
|
|||
|
||||
fake.ResetLog()
|
||||
}
|
||||
|
||||
func TestPluginVolume(t *testing.T) {
|
||||
vol := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{"localhost", "/tmp", 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{
|
||||
NFS: &api.NFSVolumeSource{"localhost", "/tmp", false},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
|
||||
}
|
||||
|
|
|
@ -74,15 +74,17 @@ func (plugin *RBDPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
|
|||
|
||||
func (plugin *RBDPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
secret := ""
|
||||
if spec.VolumeSource.RBD.SecretRef != nil {
|
||||
source := plugin.getRBDVolumeSource(spec)
|
||||
|
||||
if source.SecretRef != nil {
|
||||
kubeClient := plugin.host.GetKubeClient()
|
||||
if kubeClient == nil {
|
||||
return nil, fmt.Errorf("Cannot get kube client")
|
||||
}
|
||||
|
||||
secretName, err := kubeClient.Secrets(pod.Namespace).Get(spec.VolumeSource.RBD.SecretRef.Name)
|
||||
secretName, err := kubeClient.Secrets(pod.Namespace).Get(source.SecretRef.Name)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't get secret %v/%v", pod.Namespace, spec.VolumeSource.RBD.SecretRef)
|
||||
glog.Errorf("Couldn't get secret %v/%v", pod.Namespace, source.SecretRef)
|
||||
return nil, err
|
||||
}
|
||||
for name, data := range secretName.Data {
|
||||
|
@ -95,16 +97,25 @@ func (plugin *RBDPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
|
|||
return plugin.newBuilderInternal(spec, pod.UID, &RBDUtil{}, mounter, secret)
|
||||
}
|
||||
|
||||
func (plugin *RBDPlugin) getRBDVolumeSource(spec *volume.Spec) *api.RBDVolumeSource {
|
||||
if spec.VolumeSource.RBD != nil {
|
||||
return spec.VolumeSource.RBD
|
||||
} else {
|
||||
return spec.PersistentVolumeSource.RBD
|
||||
}
|
||||
}
|
||||
|
||||
func (plugin *RBDPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID, manager diskManager, mounter mount.Interface, secret string) (volume.Builder, error) {
|
||||
pool := spec.VolumeSource.RBD.RBDPool
|
||||
source := plugin.getRBDVolumeSource(spec)
|
||||
pool := source.RBDPool
|
||||
if pool == "" {
|
||||
pool = "rbd"
|
||||
}
|
||||
id := spec.VolumeSource.RBD.RadosUser
|
||||
id := source.RadosUser
|
||||
if id == "" {
|
||||
id = "admin"
|
||||
}
|
||||
keyring := spec.VolumeSource.RBD.Keyring
|
||||
keyring := source.Keyring
|
||||
if keyring == "" {
|
||||
keyring = "/etc/ceph/keyring"
|
||||
}
|
||||
|
@ -112,14 +123,14 @@ func (plugin *RBDPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID,
|
|||
return &rbd{
|
||||
podUID: podUID,
|
||||
volName: spec.Name,
|
||||
mon: spec.VolumeSource.RBD.CephMonitors,
|
||||
image: spec.VolumeSource.RBD.RBDImage,
|
||||
mon: source.CephMonitors,
|
||||
image: source.RBDImage,
|
||||
pool: pool,
|
||||
id: id,
|
||||
keyring: keyring,
|
||||
secret: secret,
|
||||
fsType: spec.VolumeSource.RBD.FSType,
|
||||
readOnly: spec.VolumeSource.RBD.ReadOnly,
|
||||
fsType: source.FSType,
|
||||
readOnly: source.ReadOnly,
|
||||
manager: manager,
|
||||
mounter: mounter,
|
||||
plugin: plugin,
|
||||
|
|
|
@ -65,7 +65,7 @@ func (fake *fakeDiskManager) DetachDisk(disk rbd, mntPath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
func doTestPlugin(t *testing, spec *volume.SpecT) {
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
|
||||
|
@ -73,17 +73,7 @@ func TestPlugin(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
}
|
||||
spec := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{
|
||||
RBD: &api.RBDVolumeSource{
|
||||
CephMonitors: []string{"a", "b"},
|
||||
RBDImage: "bar",
|
||||
FSType: "ext4",
|
||||
},
|
||||
},
|
||||
}
|
||||
builder, err := plug.(*RBDPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), types.UID("poduid"), &fakeDiskManager{}, &mount.FakeMounter{}, "secrets")
|
||||
builder, err := plug.(*RBDPlugin).newBuilderInternal(spec, types.UID("poduid"), &fakeDiskManager{}, &mount.FakeMounter{}, "secrets")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Builder: %v", err)
|
||||
}
|
||||
|
@ -131,3 +121,35 @@ func TestPlugin(t *testing.T) {
|
|||
t.Errorf("SetUp() failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginVolume(t *testing.T) {
|
||||
vol := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{
|
||||
RBD: &api.RBDVolumeSource{
|
||||
CephMonitors: []string{"a", "b"},
|
||||
RBDImage: "bar",
|
||||
FSType: "ext4",
|
||||
},
|
||||
},
|
||||
}
|
||||
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
||||
}
|
||||
func TestPluginPersistentVolume(t *testing.T) {
|
||||
vol := &api.PersistentVolume{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "vol1",
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
RBD: &api.RBDVolumeSource{
|
||||
CephMonitors: []string{"a", "b"},
|
||||
RBDImage: "bar",
|
||||
FSType: "ext4",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue