Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d2b4ae4d
Commit
d2b4ae4d
authored
Jun 01, 2015
by
Jan Safranek
Committed by
markturansky
Jun 02, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix persistent volumes.
Check Spec.PersistentVolumeSource in NFS, RBD, Gluster and iSCSI volume plugins.
parent
74b688dc
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
172 additions
and
54 deletions
+172
-54
glusterfs.go
pkg/volume/glusterfs/glusterfs.go
+13
-3
glusterfs_test.go
pkg/volume/glusterfs/glusterfs_test.go
+25
-6
iscsi.go
pkg/volume/iscsi/iscsi.go
+7
-1
iscsi_test.go
pkg/volume/iscsi/iscsi_test.go
+36
-13
nfs.go
pkg/volume/nfs/nfs.go
+11
-3
nfs_test.go
pkg/volume/nfs/nfs_test.go
+25
-6
rbd.go
pkg/volume/rbd/rbd.go
+21
-10
rbd_test.go
pkg/volume/rbd/rbd_test.go
+34
-12
No files found.
pkg/volume/glusterfs/glusterfs.go
View file @
d2b4ae4d
...
@@ -65,7 +65,8 @@ func (plugin *glusterfsPlugin) GetAccessModes() []api.PersistentVolumeAccessMode
...
@@ -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
)
{
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
ns
:=
pod
.
Namespace
ep
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
Endpoints
(
ns
)
.
Get
(
ep_name
)
ep
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
Endpoints
(
ns
)
.
Get
(
ep_name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -76,12 +77,21 @@ func (plugin *glusterfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ vol
...
@@ -76,12 +77,21 @@ func (plugin *glusterfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ vol
return
plugin
.
newBuilderInternal
(
spec
,
ep
,
pod
,
mounter
,
exec
.
New
())
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
)
{
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
{
return
&
glusterfs
{
volName
:
spec
.
Name
,
volName
:
spec
.
Name
,
hosts
:
ep
,
hosts
:
ep
,
path
:
s
pec
.
VolumeSource
.
Glusterfs
.
Path
,
path
:
s
ource
.
Path
,
readonly
:
s
pec
.
VolumeSource
.
Glusterfs
.
ReadOnly
,
readonly
:
s
ource
.
ReadOnly
,
mounter
:
mounter
,
mounter
:
mounter
,
exe
:
exe
,
exe
:
exe
,
pod
:
pod
,
pod
:
pod
,
...
...
pkg/volume/glusterfs/glusterfs_test.go
View file @
d2b4ae4d
...
@@ -70,17 +70,13 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
...
@@ -70,17 +70,13 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
return
false
return
false
}
}
func
TestPlugin
(
t
*
testing
.
T
)
{
func
doTestPlugin
(
t
*
testing
.
T
,
spec
*
volume
.
Spec
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/glusterfs"
)
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/glusterfs"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
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
{{
ep
:=
&
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
Subsets
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"127.0.0.1"
}}}}}
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"127.0.0.1"
}}}}}
var
fcmd
exec
.
FakeCmd
var
fcmd
exec
.
FakeCmd
...
@@ -98,7 +94,7 @@ func TestPlugin(t *testing.T) {
...
@@ -98,7 +94,7 @@ func TestPlugin(t *testing.T) {
},
},
}
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
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
()
volumePath
:=
builder
.
GetPath
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
...
@@ -136,3 +132,26 @@ func TestPlugin(t *testing.T) {
...
@@ -136,3 +132,26 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
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
))
}
pkg/volume/iscsi/iscsi.go
View file @
d2b4ae4d
...
@@ -80,7 +80,13 @@ func (plugin *ISCSIPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.
...
@@ -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
)
{
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
)
lun
:=
strconv
.
Itoa
(
iscsi
.
Lun
)
return
&
iscsiDisk
{
return
&
iscsiDisk
{
...
...
pkg/volume/iscsi/iscsi_test.go
View file @
d2b4ae4d
...
@@ -96,7 +96,7 @@ func (fake *fakeDiskManager) DetachDisk(disk iscsiDisk, mntPath string) error {
...
@@ -96,7 +96,7 @@ func (fake *fakeDiskManager) DetachDisk(disk iscsiDisk, mntPath string) error {
return
nil
return
nil
}
}
func
TestPlugin
(
t
*
testing
.
T
)
{
func
doTestPlugin
(
t
*
testing
.
T
,
spec
*
volume
.
Spec
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
...
@@ -104,20 +104,9 @@ func TestPlugin(t *testing.T) {
...
@@ -104,20 +104,9 @@ func TestPlugin(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
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
{}
fakeManager
:=
&
fakeDiskManager
{}
fakeMounter
:=
&
mount
.
FakeMounter
{}
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
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
}
...
@@ -172,3 +161,37 @@ func TestPlugin(t *testing.T) {
...
@@ -172,3 +161,37 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Detach was not called"
)
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
))
}
pkg/volume/nfs/nfs.go
View file @
d2b4ae4d
...
@@ -68,15 +68,23 @@ func (plugin *nfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
...
@@ -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
)
{
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
{
return
&
nfs
{
volName
:
spec
.
Name
,
volName
:
spec
.
Name
,
server
:
s
pec
.
VolumeSource
.
NFS
.
Server
,
server
:
s
ource
.
Server
,
exportPath
:
s
pec
.
VolumeSource
.
NFS
.
Path
,
exportPath
:
s
ource
.
Path
,
readOnly
:
s
pec
.
VolumeSource
.
NFS
.
ReadOnly
,
readOnly
:
s
ource
.
ReadOnly
,
mounter
:
mounter
,
mounter
:
mounter
,
pod
:
pod
,
pod
:
pod
,
plugin
:
plugin
,
plugin
:
plugin
,
},
nil
},
nil
}
}
func
(
plugin
*
nfsPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
nfsPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
...
...
pkg/volume/nfs/nfs_test.go
View file @
d2b4ae4d
...
@@ -69,20 +69,16 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
...
@@ -69,20 +69,16 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
return
false
return
false
}
}
func
TestPlugin
(
t
*
testing
.
T
)
{
func
doTestPlugin
(
t
*
testing
.
T
,
spec
*
volume
.
Spec
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/nfs"
)
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/nfs"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
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
{}
fake
:=
&
mount
.
FakeMounter
{}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
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
()
volumePath
:=
builder
.
GetPath
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
...
@@ -141,3 +137,26 @@ func TestPlugin(t *testing.T) {
...
@@ -141,3 +137,26 @@ func TestPlugin(t *testing.T) {
fake
.
ResetLog
()
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
))
}
pkg/volume/rbd/rbd.go
View file @
d2b4ae4d
...
@@ -74,15 +74,17 @@ func (plugin *RBDPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
...
@@ -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
)
{
func
(
plugin
*
RBDPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
secret
:=
""
secret
:=
""
if
spec
.
VolumeSource
.
RBD
.
SecretRef
!=
nil
{
source
:=
plugin
.
getRBDVolumeSource
(
spec
)
if
source
.
SecretRef
!=
nil
{
kubeClient
:=
plugin
.
host
.
GetKubeClient
()
kubeClient
:=
plugin
.
host
.
GetKubeClient
()
if
kubeClient
==
nil
{
if
kubeClient
==
nil
{
return
nil
,
fmt
.
Errorf
(
"Cannot get kube client"
)
return
nil
,
fmt
.
Errorf
(
"Cannot get kube client"
)
}
}
secretName
,
err
:=
kubeClient
.
Secrets
(
pod
.
Namespace
)
.
Get
(
s
pec
.
VolumeSource
.
RBD
.
SecretRef
.
Name
)
secretName
,
err
:=
kubeClient
.
Secrets
(
pod
.
Namespace
)
.
Get
(
s
ource
.
SecretRef
.
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't get secret %v/%v"
,
pod
.
Namespace
,
s
pec
.
VolumeSource
.
RBD
.
SecretRef
)
glog
.
Errorf
(
"Couldn't get secret %v/%v"
,
pod
.
Namespace
,
s
ource
.
SecretRef
)
return
nil
,
err
return
nil
,
err
}
}
for
name
,
data
:=
range
secretName
.
Data
{
for
name
,
data
:=
range
secretName
.
Data
{
...
@@ -95,16 +97,25 @@ func (plugin *RBDPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
...
@@ -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
)
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
)
{
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
==
""
{
if
pool
==
""
{
pool
=
"rbd"
pool
=
"rbd"
}
}
id
:=
s
pec
.
VolumeSource
.
RBD
.
RadosUser
id
:=
s
ource
.
RadosUser
if
id
==
""
{
if
id
==
""
{
id
=
"admin"
id
=
"admin"
}
}
keyring
:=
s
pec
.
VolumeSource
.
RBD
.
Keyring
keyring
:=
s
ource
.
Keyring
if
keyring
==
""
{
if
keyring
==
""
{
keyring
=
"/etc/ceph/keyring"
keyring
=
"/etc/ceph/keyring"
}
}
...
@@ -112,14 +123,14 @@ func (plugin *RBDPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID,
...
@@ -112,14 +123,14 @@ func (plugin *RBDPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID,
return
&
rbd
{
return
&
rbd
{
podUID
:
podUID
,
podUID
:
podUID
,
volName
:
spec
.
Name
,
volName
:
spec
.
Name
,
mon
:
s
pec
.
VolumeSource
.
RBD
.
CephMonitors
,
mon
:
s
ource
.
CephMonitors
,
image
:
s
pec
.
VolumeSource
.
RBD
.
RBDImage
,
image
:
s
ource
.
RBDImage
,
pool
:
pool
,
pool
:
pool
,
id
:
id
,
id
:
id
,
keyring
:
keyring
,
keyring
:
keyring
,
secret
:
secret
,
secret
:
secret
,
fsType
:
s
pec
.
VolumeSource
.
RBD
.
FSType
,
fsType
:
s
ource
.
FSType
,
readOnly
:
s
pec
.
VolumeSource
.
RBD
.
ReadOnly
,
readOnly
:
s
ource
.
ReadOnly
,
manager
:
manager
,
manager
:
manager
,
mounter
:
mounter
,
mounter
:
mounter
,
plugin
:
plugin
,
plugin
:
plugin
,
...
...
pkg/volume/rbd/rbd_test.go
View file @
d2b4ae4d
...
@@ -65,7 +65,7 @@ func (fake *fakeDiskManager) DetachDisk(disk rbd, mntPath string) error {
...
@@ -65,7 +65,7 @@ func (fake *fakeDiskManager) DetachDisk(disk rbd, mntPath string) error {
return
nil
return
nil
}
}
func
TestPlugin
(
t
*
testing
.
T
)
{
func
doTestPlugin
(
t
*
testing
,
spec
*
volume
.
Spec
T
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
...
@@ -73,17 +73,7 @@ func TestPlugin(t *testing.T) {
...
@@ -73,17 +73,7 @@ func TestPlugin(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
t
.
Errorf
(
"Can't find the plugin by name"
)
}
}
spec
:=
&
api
.
Volume
{
builder
,
err
:=
plug
.
(
*
RBDPlugin
)
.
newBuilderInternal
(
spec
,
types
.
UID
(
"poduid"
),
&
fakeDiskManager
{},
&
mount
.
FakeMounter
{},
"secrets"
)
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"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
}
...
@@ -131,3 +121,35 @@ func TestPlugin(t *testing.T) {
...
@@ -131,3 +121,35 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
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
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment