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
327210c2
Commit
327210c2
authored
Jun 15, 2016
by
Matthew Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add integration test for binding PVs using label selectors
parent
6ebf168b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
persistent_volumes_test.go
test/integration/persistent_volumes_test.go
+73
-0
No files found.
test/integration/persistent_volumes_test.go
View file @
327210c2
...
...
@@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/restclient"
fake_cloud
"k8s.io/kubernetes/pkg/cloudprovider/providers/fake"
...
...
@@ -267,6 +268,78 @@ func TestPersistentVolumeBindRace(t *testing.T) {
}
}
// TestPersistentVolumeClaimLabelSelector test binding using label selectors
func
TestPersistentVolumeClaimLabelSelector
(
t
*
testing
.
T
)
{
_
,
s
:=
framework
.
RunAMaster
(
t
)
defer
s
.
Close
()
deleteAllEtcdKeys
()
testClient
,
controller
,
watchPV
,
watchPVC
:=
createClients
(
t
,
s
)
defer
watchPV
.
Stop
()
defer
watchPVC
.
Stop
()
controller
.
Run
()
defer
controller
.
Stop
()
var
(
err
error
modes
=
[]
api
.
PersistentVolumeAccessMode
{
api
.
ReadWriteOnce
}
reclaim
=
api
.
PersistentVolumeReclaimRetain
pv_true
=
createPV
(
"pv-true"
,
"/tmp/foo-label"
,
"1G"
,
modes
,
reclaim
)
pv_false
=
createPV
(
"pv-false"
,
"/tmp/foo-label"
,
"1G"
,
modes
,
reclaim
)
pvc
=
createPVC
(
"pvc-ls-1"
,
"1G"
,
modes
)
)
pv_true
.
ObjectMeta
.
SetLabels
(
map
[
string
]
string
{
"foo"
:
"true"
})
pv_false
.
ObjectMeta
.
SetLabels
(
map
[
string
]
string
{
"foo"
:
"false"
})
_
,
err
=
testClient
.
PersistentVolumes
()
.
Create
(
pv_true
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create PersistentVolume: %v"
,
err
)
}
_
,
err
=
testClient
.
PersistentVolumes
()
.
Create
(
pv_false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create PersistentVolume: %v"
,
err
)
}
t
.
Log
(
"volumes created"
)
pvc
.
Spec
.
Selector
=
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"true"
,
},
}
_
,
err
=
testClient
.
PersistentVolumeClaims
(
api
.
NamespaceDefault
)
.
Create
(
pvc
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create PersistentVolumeClaim: %v"
,
err
)
}
t
.
Log
(
"claim created"
)
waitForAnyPersistentVolumePhase
(
watchPV
,
api
.
VolumeBound
)
t
.
Log
(
"volume bound"
)
waitForPersistentVolumeClaimPhase
(
testClient
,
pvc
.
Name
,
watchPVC
,
api
.
ClaimBound
)
t
.
Log
(
"claim bound"
)
pv
,
err
:=
testClient
.
PersistentVolumes
()
.
Get
(
"pv-false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error getting pv: %v"
,
err
)
}
if
pv
.
Spec
.
ClaimRef
!=
nil
{
t
.
Fatalf
(
"False PV shouldn't be bound"
)
}
pv
,
err
=
testClient
.
PersistentVolumes
()
.
Get
(
"pv-true"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error getting pv: %v"
,
err
)
}
if
pv
.
Spec
.
ClaimRef
==
nil
{
t
.
Fatalf
(
"True PV should be bound"
)
}
if
pv
.
Spec
.
ClaimRef
.
Namespace
!=
pvc
.
Namespace
||
pv
.
Spec
.
ClaimRef
.
Name
!=
pvc
.
Name
{
t
.
Fatalf
(
"Bind mismatch! Expected %s/%s but got %s/%s"
,
pvc
.
Namespace
,
pvc
.
Name
,
pv
.
Spec
.
ClaimRef
.
Namespace
,
pv
.
Spec
.
ClaimRef
.
Name
)
}
}
// TestPersistentVolumeMultiPVs tests binding of one PVC to 100 PVs with
// different size.
func
TestPersistentVolumeMultiPVs
(
t
*
testing
.
T
)
{
...
...
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