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
910fd195
Commit
910fd195
authored
Apr 24, 2018
by
hangaoshuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixtodo:validate events on PVCs in integration volume binding test
parent
e85943f9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
15 deletions
+50
-15
BUILD
test/integration/scheduler/BUILD
+2
-0
volume_binding_test.go
test/integration/scheduler/volume_binding_test.go
+48
-15
No files found.
test/integration/scheduler/BUILD
View file @
910fd195
...
@@ -29,6 +29,7 @@ go_test(
...
@@ -29,6 +29,7 @@ go_test(
"//pkg/client/clientset_generated/internalclientset:go_default_library",
"//pkg/client/clientset_generated/internalclientset:go_default_library",
"//pkg/client/informers/informers_generated/internalversion:go_default_library",
"//pkg/client/informers/informers_generated/internalversion:go_default_library",
"//pkg/controller/nodelifecycle:go_default_library",
"//pkg/controller/nodelifecycle:go_default_library",
"//pkg/controller/volume/events:go_default_library",
"//pkg/controller/volume/persistentvolume:go_default_library",
"//pkg/controller/volume/persistentvolume:go_default_library",
"//pkg/features:go_default_library",
"//pkg/features:go_default_library",
"//pkg/kubeapiserver/admission:go_default_library",
"//pkg/kubeapiserver/admission:go_default_library",
...
@@ -59,6 +60,7 @@ go_test(
...
@@ -59,6 +60,7 @@ go_test(
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/k8s.io/client-go/informers:go_default_library",
"//vendor/k8s.io/client-go/informers:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/listers/core/v1:go_default_library",
"//vendor/k8s.io/client-go/listers/core/v1:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
...
...
test/integration/scheduler/volume_binding_test.go
View file @
910fd195
...
@@ -35,6 +35,11 @@ import (
...
@@ -35,6 +35,11 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
clientset
"k8s.io/client-go/kubernetes"
clientset
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
v1core
"k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/controller/volume/events"
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
)
)
...
@@ -76,6 +81,7 @@ type testPVC struct {
...
@@ -76,6 +81,7 @@ type testPVC struct {
name
string
name
string
scMode
storagev1
.
VolumeBindingMode
scMode
storagev1
.
VolumeBindingMode
preboundPV
string
preboundPV
string
eventsReason
string
}
}
func
TestVolumeBinding
(
t
*
testing
.
T
)
{
func
TestVolumeBinding
(
t
*
testing
.
T
)
{
...
@@ -94,42 +100,42 @@ func TestVolumeBinding(t *testing.T) {
...
@@ -94,42 +100,42 @@ func TestVolumeBinding(t *testing.T) {
"immediate can bind"
:
{
"immediate can bind"
:
{
pod
:
makePod
(
"pod-i-canbind"
,
config
.
ns
,
[]
string
{
"pvc-i-canbind"
}),
pod
:
makePod
(
"pod-i-canbind"
,
config
.
ns
,
[]
string
{
"pvc-i-canbind"
}),
pvs
:
[]
*
testPV
{{
"pv-i-canbind"
,
modeImmediate
,
""
,
node1
}},
pvs
:
[]
*
testPV
{{
"pv-i-canbind"
,
modeImmediate
,
""
,
node1
}},
pvcs
:
[]
*
testPVC
{{
"pvc-i-canbind"
,
modeImmediate
,
""
}},
pvcs
:
[]
*
testPVC
{{
"pvc-i-canbind"
,
modeImmediate
,
""
,
""
}},
},
},
"immediate cannot bind"
:
{
"immediate cannot bind"
:
{
pod
:
makePod
(
"pod-i-cannotbind"
,
config
.
ns
,
[]
string
{
"pvc-i-cannotbind"
}),
pod
:
makePod
(
"pod-i-cannotbind"
,
config
.
ns
,
[]
string
{
"pvc-i-cannotbind"
}),
unboundPvcs
:
[]
*
testPVC
{{
"pvc-i-cannotbind"
,
modeImmediate
,
""
}},
unboundPvcs
:
[]
*
testPVC
{{
"pvc-i-cannotbind"
,
modeImmediate
,
""
,
events
.
ProvisioningFailed
}},
shouldFail
:
true
,
shouldFail
:
true
,
},
},
"immediate pvc prebound"
:
{
"immediate pvc prebound"
:
{
pod
:
makePod
(
"pod-i-pvc-prebound"
,
config
.
ns
,
[]
string
{
"pvc-i-prebound"
}),
pod
:
makePod
(
"pod-i-pvc-prebound"
,
config
.
ns
,
[]
string
{
"pvc-i-prebound"
}),
pvs
:
[]
*
testPV
{{
"pv-i-pvc-prebound"
,
modeImmediate
,
""
,
node1
}},
pvs
:
[]
*
testPV
{{
"pv-i-pvc-prebound"
,
modeImmediate
,
""
,
node1
}},
pvcs
:
[]
*
testPVC
{{
"pvc-i-prebound"
,
modeImmediate
,
"pv-i-pvc-prebound"
}},
pvcs
:
[]
*
testPVC
{{
"pvc-i-prebound"
,
modeImmediate
,
"pv-i-pvc-prebound"
,
""
}},
},
},
"immediate pv prebound"
:
{
"immediate pv prebound"
:
{
pod
:
makePod
(
"pod-i-pv-prebound"
,
config
.
ns
,
[]
string
{
"pvc-i-pv-prebound"
}),
pod
:
makePod
(
"pod-i-pv-prebound"
,
config
.
ns
,
[]
string
{
"pvc-i-pv-prebound"
}),
pvs
:
[]
*
testPV
{{
"pv-i-prebound"
,
modeImmediate
,
"pvc-i-pv-prebound"
,
node1
}},
pvs
:
[]
*
testPV
{{
"pv-i-prebound"
,
modeImmediate
,
"pvc-i-pv-prebound"
,
node1
}},
pvcs
:
[]
*
testPVC
{{
"pvc-i-pv-prebound"
,
modeImmediate
,
""
}},
pvcs
:
[]
*
testPVC
{{
"pvc-i-pv-prebound"
,
modeImmediate
,
""
,
""
}},
},
},
"wait can bind"
:
{
"wait can bind"
:
{
pod
:
makePod
(
"pod-w-canbind"
,
config
.
ns
,
[]
string
{
"pvc-w-canbind"
}),
pod
:
makePod
(
"pod-w-canbind"
,
config
.
ns
,
[]
string
{
"pvc-w-canbind"
}),
pvs
:
[]
*
testPV
{{
"pv-w-canbind"
,
modeWait
,
""
,
node1
}},
pvs
:
[]
*
testPV
{{
"pv-w-canbind"
,
modeWait
,
""
,
node1
}},
pvcs
:
[]
*
testPVC
{{
"pvc-w-canbind"
,
modeWait
,
""
}},
pvcs
:
[]
*
testPVC
{{
"pvc-w-canbind"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
}},
},
},
"wait cannot bind"
:
{
"wait cannot bind"
:
{
pod
:
makePod
(
"pod-w-cannotbind"
,
config
.
ns
,
[]
string
{
"pvc-w-cannotbind"
}),
pod
:
makePod
(
"pod-w-cannotbind"
,
config
.
ns
,
[]
string
{
"pvc-w-cannotbind"
}),
unboundPvcs
:
[]
*
testPVC
{{
"pvc-w-cannotbind"
,
modeWait
,
""
}},
unboundPvcs
:
[]
*
testPVC
{{
"pvc-w-cannotbind"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
}},
shouldFail
:
true
,
shouldFail
:
true
,
},
},
"wait pvc prebound"
:
{
"wait pvc prebound"
:
{
pod
:
makePod
(
"pod-w-pvc-prebound"
,
config
.
ns
,
[]
string
{
"pvc-w-prebound"
}),
pod
:
makePod
(
"pod-w-pvc-prebound"
,
config
.
ns
,
[]
string
{
"pvc-w-prebound"
}),
pvs
:
[]
*
testPV
{{
"pv-w-pvc-prebound"
,
modeWait
,
""
,
node1
}},
pvs
:
[]
*
testPV
{{
"pv-w-pvc-prebound"
,
modeWait
,
""
,
node1
}},
pvcs
:
[]
*
testPVC
{{
"pvc-w-prebound"
,
modeWait
,
"pv-w-pvc-prebound"
}},
pvcs
:
[]
*
testPVC
{{
"pvc-w-prebound"
,
modeWait
,
"pv-w-pvc-prebound"
,
events
.
WaitForFirstConsumer
}},
},
},
"wait pv prebound"
:
{
"wait pv prebound"
:
{
pod
:
makePod
(
"pod-w-pv-prebound"
,
config
.
ns
,
[]
string
{
"pvc-w-pv-prebound"
}),
pod
:
makePod
(
"pod-w-pv-prebound"
,
config
.
ns
,
[]
string
{
"pvc-w-pv-prebound"
}),
pvs
:
[]
*
testPV
{{
"pv-w-prebound"
,
modeWait
,
"pvc-w-pv-prebound"
,
node1
}},
pvs
:
[]
*
testPV
{{
"pv-w-prebound"
,
modeWait
,
"pvc-w-pv-prebound"
,
node1
}},
pvcs
:
[]
*
testPVC
{{
"pvc-w-pv-prebound"
,
modeWait
,
""
}},
pvcs
:
[]
*
testPVC
{{
"pvc-w-pv-prebound"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
}},
},
},
"wait can bind two"
:
{
"wait can bind two"
:
{
pod
:
makePod
(
"pod-w-canbind-2"
,
config
.
ns
,
[]
string
{
"pvc-w-canbind-2"
,
"pvc-w-canbind-3"
}),
pod
:
makePod
(
"pod-w-canbind-2"
,
config
.
ns
,
[]
string
{
"pvc-w-canbind-2"
,
"pvc-w-canbind-3"
}),
...
@@ -138,8 +144,8 @@ func TestVolumeBinding(t *testing.T) {
...
@@ -138,8 +144,8 @@ func TestVolumeBinding(t *testing.T) {
{
"pv-w-canbind-3"
,
modeWait
,
""
,
node2
},
{
"pv-w-canbind-3"
,
modeWait
,
""
,
node2
},
},
},
pvcs
:
[]
*
testPVC
{
pvcs
:
[]
*
testPVC
{
{
"pvc-w-canbind-2"
,
modeWait
,
""
},
{
"pvc-w-canbind-2"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
},
{
"pvc-w-canbind-3"
,
modeWait
,
""
},
{
"pvc-w-canbind-3"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
},
},
},
unboundPvs
:
[]
*
testPV
{
unboundPvs
:
[]
*
testPV
{
{
"pv-w-canbind-5"
,
modeWait
,
""
,
node1
},
{
"pv-w-canbind-5"
,
modeWait
,
""
,
node1
},
...
@@ -148,8 +154,8 @@ func TestVolumeBinding(t *testing.T) {
...
@@ -148,8 +154,8 @@ func TestVolumeBinding(t *testing.T) {
"wait cannot bind two"
:
{
"wait cannot bind two"
:
{
pod
:
makePod
(
"pod-w-cannotbind-2"
,
config
.
ns
,
[]
string
{
"pvc-w-cannotbind-1"
,
"pvc-w-cannotbind-2"
}),
pod
:
makePod
(
"pod-w-cannotbind-2"
,
config
.
ns
,
[]
string
{
"pvc-w-cannotbind-1"
,
"pvc-w-cannotbind-2"
}),
unboundPvcs
:
[]
*
testPVC
{
unboundPvcs
:
[]
*
testPVC
{
{
"pvc-w-cannotbind-1"
,
modeWait
,
""
},
{
"pvc-w-cannotbind-1"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
},
{
"pvc-w-cannotbind-2"
,
modeWait
,
""
},
{
"pvc-w-cannotbind-2"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
},
},
},
unboundPvs
:
[]
*
testPV
{
unboundPvs
:
[]
*
testPV
{
{
"pv-w-cannotbind-1"
,
modeWait
,
""
,
node2
},
{
"pv-w-cannotbind-1"
,
modeWait
,
""
,
node2
},
...
@@ -164,8 +170,8 @@ func TestVolumeBinding(t *testing.T) {
...
@@ -164,8 +170,8 @@ func TestVolumeBinding(t *testing.T) {
{
"pv-i-canbind-2"
,
modeImmediate
,
""
,
node1
},
{
"pv-i-canbind-2"
,
modeImmediate
,
""
,
node1
},
},
},
pvcs
:
[]
*
testPVC
{
pvcs
:
[]
*
testPVC
{
{
"pvc-w-canbind-4"
,
modeWait
,
""
},
{
"pvc-w-canbind-4"
,
modeWait
,
""
,
events
.
WaitForFirstConsumer
},
{
"pvc-i-canbind-2"
,
modeImmediate
,
""
},
{
"pvc-i-canbind-2"
,
modeImmediate
,
""
,
""
},
},
},
},
},
}
}
...
@@ -230,9 +236,11 @@ func TestVolumeBinding(t *testing.T) {
...
@@ -230,9 +236,11 @@ func TestVolumeBinding(t *testing.T) {
// Validate PVC/PV binding
// Validate PVC/PV binding
for
_
,
pvc
:=
range
test
.
pvcs
{
for
_
,
pvc
:=
range
test
.
pvcs
{
validatePVCPhase
(
t
,
config
.
client
,
pvc
.
name
,
config
.
ns
,
v1
.
ClaimBound
)
validatePVCPhase
(
t
,
config
.
client
,
pvc
.
name
,
config
.
ns
,
v1
.
ClaimBound
)
validatePVCEvent
(
t
,
config
.
client
,
pvc
.
name
,
config
.
ns
,
pvc
.
eventsReason
)
}
}
for
_
,
pvc
:=
range
test
.
unboundPvcs
{
for
_
,
pvc
:=
range
test
.
unboundPvcs
{
validatePVCPhase
(
t
,
config
.
client
,
pvc
.
name
,
config
.
ns
,
v1
.
ClaimPending
)
validatePVCPhase
(
t
,
config
.
client
,
pvc
.
name
,
config
.
ns
,
v1
.
ClaimPending
)
validatePVCEvent
(
t
,
config
.
client
,
pvc
.
name
,
config
.
ns
,
pvc
.
eventsReason
)
}
}
for
_
,
pv
:=
range
test
.
pvs
{
for
_
,
pv
:=
range
test
.
pvs
{
validatePVPhase
(
t
,
config
.
client
,
pv
.
name
,
v1
.
VolumeBound
)
validatePVPhase
(
t
,
config
.
client
,
pv
.
name
,
v1
.
VolumeBound
)
...
@@ -375,6 +383,10 @@ func setupCluster(t *testing.T, nsName string, numberOfNodes int) *testConfig {
...
@@ -375,6 +383,10 @@ func setupCluster(t *testing.T, nsName string, numberOfNodes int) *testConfig {
ns
:=
context
.
ns
.
Name
ns
:=
context
.
ns
.
Name
informers
:=
context
.
informerFactory
informers
:=
context
.
informerFactory
broadcaster
:=
record
.
NewBroadcaster
()
broadcaster
.
StartLogging
(
glog
.
Infof
)
broadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
clientset
.
CoreV1
()
.
Events
(
""
)})
eventRecorder
:=
broadcaster
.
NewRecorder
(
scheme
.
Scheme
,
v1
.
EventSource
{
Component
:
"test-persistentvolume-controller"
})
// Start PV controller for volume binding.
// Start PV controller for volume binding.
params
:=
persistentvolume
.
ControllerParameters
{
params
:=
persistentvolume
.
ControllerParameters
{
KubeClient
:
clientset
,
KubeClient
:
clientset
,
...
@@ -386,7 +398,7 @@ func setupCluster(t *testing.T, nsName string, numberOfNodes int) *testConfig {
...
@@ -386,7 +398,7 @@ func setupCluster(t *testing.T, nsName string, numberOfNodes int) *testConfig {
ClaimInformer
:
informers
.
Core
()
.
V1
()
.
PersistentVolumeClaims
(),
ClaimInformer
:
informers
.
Core
()
.
V1
()
.
PersistentVolumeClaims
(),
ClassInformer
:
informers
.
Storage
()
.
V1
()
.
StorageClasses
(),
ClassInformer
:
informers
.
Storage
()
.
V1
()
.
StorageClasses
(),
PodInformer
:
informers
.
Core
()
.
V1
()
.
Pods
(),
PodInformer
:
informers
.
Core
()
.
V1
()
.
Pods
(),
EventRecorder
:
nil
,
// TODO: add one so we can test PV events
EventRecorder
:
eventRecorder
,
EnableDynamicProvisioning
:
true
,
EnableDynamicProvisioning
:
true
,
}
}
ctrl
,
err
:=
persistentvolume
.
NewController
(
params
)
ctrl
,
err
:=
persistentvolume
.
NewController
(
params
)
...
@@ -571,6 +583,27 @@ func validatePVCPhase(t *testing.T, client clientset.Interface, pvcName string,
...
@@ -571,6 +583,27 @@ func validatePVCPhase(t *testing.T, client clientset.Interface, pvcName string,
}
}
}
}
func
validatePVCEvent
(
t
*
testing
.
T
,
client
clientset
.
Interface
,
pvcName
string
,
ns
string
,
reason
string
)
{
claim
,
err
:=
client
.
CoreV1
()
.
PersistentVolumeClaims
(
ns
)
.
Get
(
pvcName
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get PVC %v/%v: %v"
,
ns
,
pvcName
,
err
)
}
pvcEvents
,
err
:=
client
.
CoreV1
()
.
Events
(
ns
)
.
Search
(
legacyscheme
.
Scheme
,
claim
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get PVC events %v/%v: %v"
,
ns
,
pvcName
,
err
)
}
if
len
(
pvcEvents
.
Items
)
>
0
{
for
_
,
e
:=
range
pvcEvents
.
Items
{
if
e
.
Reason
==
reason
{
return
}
}
t
.
Errorf
(
"Failed to get PVC %v/%v events reason:%s"
,
ns
,
pvcName
,
reason
)
}
}
func
validatePVPhase
(
t
*
testing
.
T
,
client
clientset
.
Interface
,
pvName
string
,
phase
v1
.
PersistentVolumePhase
)
{
func
validatePVPhase
(
t
*
testing
.
T
,
client
clientset
.
Interface
,
pvName
string
,
phase
v1
.
PersistentVolumePhase
)
{
pv
,
err
:=
client
.
CoreV1
()
.
PersistentVolumes
()
.
Get
(
pvName
,
metav1
.
GetOptions
{})
pv
,
err
:=
client
.
CoreV1
()
.
PersistentVolumes
()
.
Get
(
pvName
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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