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
63ccfa2b
Commit
63ccfa2b
authored
Jul 01, 2015
by
markturansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for each PV using IsReadOnly
parent
fae67594
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
337 additions
and
14 deletions
+337
-14
aws_ebs_test.go
pkg/volume/aws_ebs/aws_ebs_test.go
+4
-4
gce_pd_test.go
pkg/volume/gce_pd/gce_pd_test.go
+49
-0
glusterfs_test.go
pkg/volume/glusterfs/glusterfs_test.go
+61
-1
host_path.go
pkg/volume/host_path/host_path.go
+10
-3
host_path_test.go
pkg/volume/host_path/host_path_test.go
+49
-0
iscsi_test.go
pkg/volume/iscsi/iscsi_test.go
+55
-1
nfs.go
pkg/volume/nfs/nfs.go
+5
-2
nfs_test.go
pkg/volume/nfs/nfs_test.go
+50
-1
persistent_claim.go
pkg/volume/persistent_claim/persistent_claim.go
+0
-1
rbd_test.go
pkg/volume/rbd/rbd_test.go
+54
-1
No files found.
pkg/volume/aws_ebs/aws_ebs_test.go
View file @
63ccfa2b
...
@@ -196,13 +196,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
...
@@ -196,13 +196,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
awsElasticBlockStorePluginName
)
plug
,
_
:=
plugMgr
.
FindPluginByName
(
awsElasticBlockStorePluginName
)
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
false
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
builder
.
IsReadOnly
()
{
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected
fals
e for builder.IsReadOnly"
)
t
.
Errorf
(
"Expected
tru
e for builder.IsReadOnly"
)
}
}
}
}
pkg/volume/gce_pd/gce_pd_test.go
View file @
63ccfa2b
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
...
@@ -171,3 +173,50 @@ func TestPlugin(t *testing.T) {
...
@@ -171,3 +173,50 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Detach watch not called"
)
t
.
Errorf
(
"Detach watch not called"
)
}
}
}
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pvA"
,
},
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{},
},
ClaimRef
:
&
api
.
ObjectReference
{
Name
:
"claimA"
,
},
},
}
claim
:=
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"claimA"
,
Namespace
:
"nsA"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
},
}
o
:=
testclient
.
NewObjects
(
api
.
Scheme
,
api
.
Scheme
)
o
.
Add
(
pv
)
o
.
Add
(
claim
)
client
:=
&
testclient
.
Fake
{
ReactFn
:
testclient
.
ObjectReaction
(
o
,
latest
.
RESTMapper
)}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
gcePersistentDiskPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected true for builder.IsReadOnly"
)
}
}
pkg/volume/glusterfs/glusterfs_test.go
View file @
63ccfa2b
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
...
@@ -153,5 +155,63 @@ func TestPluginPersistentVolume(t *testing.T) {
...
@@ -153,5 +155,63 @@ func TestPluginPersistentVolume(t *testing.T) {
},
},
}
}
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
))
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pvA"
,
},
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
Glusterfs
:
&
api
.
GlusterfsVolumeSource
{
"ep"
,
"vol"
,
false
},
},
ClaimRef
:
&
api
.
ObjectReference
{
Name
:
"claimA"
,
},
},
}
claim
:=
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"claimA"
,
Namespace
:
"nsA"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
},
}
ep
:=
&
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"ep"
,
},
Subsets
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"127.0.0.1"
}},
Ports
:
[]
api
.
EndpointPort
{{
"foo"
,
80
,
api
.
ProtocolTCP
}},
}},
}
o
:=
testclient
.
NewObjects
(
api
.
Scheme
,
api
.
Scheme
)
o
.
Add
(
pv
)
o
.
Add
(
claim
)
o
.
Add
(
ep
)
client
:=
&
testclient
.
Fake
{
ReactFn
:
testclient
.
ObjectReaction
(
o
,
latest
.
RESTMapper
)}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
glusterfsPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected true for builder.IsReadOnly"
)
}
}
}
pkg/volume/host_path/host_path.go
View file @
63ccfa2b
...
@@ -71,9 +71,15 @@ func (plugin *hostPathPlugin) GetAccessModes() []api.PersistentVolumeAccessMode
...
@@ -71,9 +71,15 @@ func (plugin *hostPathPlugin) GetAccessModes() []api.PersistentVolumeAccessMode
func
(
plugin
*
hostPathPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
_
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
hostPathPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
_
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
if
spec
.
VolumeSource
.
HostPath
!=
nil
{
if
spec
.
VolumeSource
.
HostPath
!=
nil
{
return
&
hostPathBuilder
{
&
hostPath
{
spec
.
VolumeSource
.
HostPath
.
Path
}},
nil
return
&
hostPathBuilder
{
hostPath
:
spec
.
VolumeSource
.
HostPath
,
readOnly
:
false
,
},
nil
}
else
{
}
else
{
return
&
hostPathBuilder
{
&
hostPath
{
spec
.
PersistentVolumeSource
.
HostPath
.
Path
}},
nil
return
&
hostPathBuilder
{
hostPath
:
spec
.
PersistentVolumeSource
.
HostPath
,
readOnly
:
spec
.
ReadOnly
,
},
nil
}
}
}
}
...
@@ -105,6 +111,7 @@ func (hp *hostPath) GetPath() string {
...
@@ -105,6 +111,7 @@ func (hp *hostPath) GetPath() string {
type
hostPathBuilder
struct
{
type
hostPathBuilder
struct
{
*
hostPath
*
hostPath
readOnly
bool
}
}
var
_
volume
.
Builder
=
&
hostPathBuilder
{}
var
_
volume
.
Builder
=
&
hostPathBuilder
{}
...
@@ -120,7 +127,7 @@ func (b *hostPathBuilder) SetUpAt(dir string) error {
...
@@ -120,7 +127,7 @@ func (b *hostPathBuilder) SetUpAt(dir string) error {
}
}
func
(
b
*
hostPathBuilder
)
IsReadOnly
()
bool
{
func
(
b
*
hostPathBuilder
)
IsReadOnly
()
bool
{
return
false
return
b
.
readOnly
}
}
func
(
b
*
hostPathBuilder
)
GetPath
()
string
{
func
(
b
*
hostPathBuilder
)
GetPath
()
string
{
...
...
pkg/volume/host_path/host_path_test.go
View file @
63ccfa2b
...
@@ -20,6 +20,8 @@ import (
...
@@ -20,6 +20,8 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
)
)
...
@@ -142,3 +144,50 @@ func TestPlugin(t *testing.T) {
...
@@ -142,3 +144,50 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Expected success, got: %v"
,
err
)
t
.
Errorf
(
"Expected success, got: %v"
,
err
)
}
}
}
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pvA"
,
},
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
HostPath
:
&
api
.
HostPathVolumeSource
{
"foo"
},
},
ClaimRef
:
&
api
.
ObjectReference
{
Name
:
"claimA"
,
},
},
}
claim
:=
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"claimA"
,
Namespace
:
"nsA"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
},
}
o
:=
testclient
.
NewObjects
(
api
.
Scheme
,
api
.
Scheme
)
o
.
Add
(
pv
)
o
.
Add
(
claim
)
client
:=
&
testclient
.
Fake
{
ReactFn
:
testclient
.
ObjectReaction
(
o
,
latest
.
RESTMapper
)}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
hostPathPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected true for builder.IsReadOnly"
)
}
}
pkg/volume/iscsi/iscsi_test.go
View file @
63ccfa2b
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
...
@@ -193,5 +195,57 @@ func TestPluginPersistentVolume(t *testing.T) {
...
@@ -193,5 +195,57 @@ func TestPluginPersistentVolume(t *testing.T) {
},
},
},
},
}
}
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
))
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pvA"
,
},
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
,
},
},
ClaimRef
:
&
api
.
ObjectReference
{
Name
:
"claimA"
,
},
},
}
claim
:=
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"claimA"
,
Namespace
:
"nsA"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
},
}
o
:=
testclient
.
NewObjects
(
api
.
Scheme
,
api
.
Scheme
)
o
.
Add
(
pv
)
o
.
Add
(
claim
)
client
:=
&
testclient
.
Fake
{
ReactFn
:
testclient
.
ObjectReaction
(
o
,
latest
.
RESTMapper
)}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
iscsiPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected true for builder.IsReadOnly"
)
}
}
}
pkg/volume/nfs/nfs.go
View file @
63ccfa2b
...
@@ -76,11 +76,13 @@ func (plugin *nfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
...
@@ -76,11 +76,13 @@ 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
var
source
*
api
.
NFSVolumeSource
var
readOnly
bool
if
spec
.
VolumeSource
.
NFS
!=
nil
{
if
spec
.
VolumeSource
.
NFS
!=
nil
{
source
=
spec
.
VolumeSource
.
NFS
source
=
spec
.
VolumeSource
.
NFS
readOnly
=
spec
.
VolumeSource
.
NFS
.
ReadOnly
}
else
{
}
else
{
source
=
spec
.
PersistentVolumeSource
.
NFS
source
=
spec
.
PersistentVolumeSource
.
NFS
readOnly
=
spec
.
ReadOnly
}
}
return
&
nfsBuilder
{
return
&
nfsBuilder
{
nfs
:
&
nfs
{
nfs
:
&
nfs
{
...
@@ -91,7 +93,8 @@ func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mou
...
@@ -91,7 +93,8 @@ func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mou
},
},
server
:
source
.
Server
,
server
:
source
.
Server
,
exportPath
:
source
.
Path
,
exportPath
:
source
.
Path
,
readOnly
:
source
.
ReadOnly
},
nil
readOnly
:
readOnly
,
},
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 @
63ccfa2b
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
...
@@ -199,5 +201,52 @@ func TestPluginPersistentVolume(t *testing.T) {
...
@@ -199,5 +201,52 @@ func TestPluginPersistentVolume(t *testing.T) {
},
},
}
}
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
))
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pvA"
,
},
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
NFS
:
&
api
.
NFSVolumeSource
{},
},
ClaimRef
:
&
api
.
ObjectReference
{
Name
:
"claimA"
,
},
},
}
claim
:=
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"claimA"
,
Namespace
:
"nsA"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
},
}
o
:=
testclient
.
NewObjects
(
api
.
Scheme
,
api
.
Scheme
)
o
.
Add
(
pv
)
o
.
Add
(
claim
)
client
:=
&
testclient
.
Fake
{
ReactFn
:
testclient
.
ObjectReaction
(
o
,
latest
.
RESTMapper
)}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
nfsPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected true for builder.IsReadOnly"
)
}
}
}
pkg/volume/persistent_claim/persistent_claim.go
View file @
63ccfa2b
...
@@ -53,7 +53,6 @@ func (plugin *persistentClaimPlugin) CanSupport(spec *volume.Spec) bool {
...
@@ -53,7 +53,6 @@ func (plugin *persistentClaimPlugin) CanSupport(spec *volume.Spec) bool {
}
}
func
(
plugin
*
persistentClaimPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
persistentClaimPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
plugin
.
readOnly
=
spec
.
ReadOnly
claim
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
PersistentVolumeClaims
(
pod
.
Namespace
)
.
Get
(
spec
.
VolumeSource
.
PersistentVolumeClaim
.
ClaimName
)
claim
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
PersistentVolumeClaims
(
pod
.
Namespace
)
.
Get
(
spec
.
VolumeSource
.
PersistentVolumeClaim
.
ClaimName
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error finding claim: %+v
\n
"
,
spec
.
VolumeSource
.
PersistentVolumeClaim
.
ClaimName
)
glog
.
Errorf
(
"Error finding claim: %+v
\n
"
,
spec
.
VolumeSource
.
PersistentVolumeClaim
.
ClaimName
)
...
...
pkg/volume/rbd/rbd_test.go
View file @
63ccfa2b
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
...
@@ -151,5 +153,56 @@ func TestPluginPersistentVolume(t *testing.T) {
...
@@ -151,5 +153,56 @@ func TestPluginPersistentVolume(t *testing.T) {
},
},
}
}
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
))
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pvA"
,
},
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
RBD
:
&
api
.
RBDVolumeSource
{
CephMonitors
:
[]
string
{
"a"
,
"b"
},
RBDImage
:
"bar"
,
FSType
:
"ext4"
,
},
},
ClaimRef
:
&
api
.
ObjectReference
{
Name
:
"claimA"
,
},
},
}
claim
:=
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"claimA"
,
Namespace
:
"nsA"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
},
}
o
:=
testclient
.
NewObjects
(
api
.
Scheme
,
api
.
Scheme
)
o
.
Add
(
pv
)
o
.
Add
(
claim
)
client
:=
&
testclient
.
Fake
{
ReactFn
:
testclient
.
ObjectReaction
(
o
,
latest
.
RESTMapper
)}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
rbdPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
spec
:=
volume
.
NewSpecFromPersistentVolume
(
pv
,
true
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
_
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
!
builder
.
IsReadOnly
()
{
t
.
Errorf
(
"Expected true for builder.IsReadOnly"
)
}
}
}
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