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
0b6c028c
Commit
0b6c028c
authored
Mar 18, 2019
by
Yecheng Fu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract testing VolumeReactor into a separate package
parent
6d691c99
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
50 deletions
+35
-50
delete_test.go
pkg/controller/volume/persistentvolume/delete_test.go
+7
-12
framework_test.go
pkg/controller/volume/persistentvolume/framework_test.go
+0
-0
provision_test.go
pkg/controller/volume/persistentvolume/provision_test.go
+9
-10
pv_controller_test.go
pkg/controller/volume/persistentvolume/pv_controller_test.go
+11
-10
recycle_test.go
pkg/controller/volume/persistentvolume/recycle_test.go
+8
-18
testing.go
pkg/controller/volume/persistentvolume/testing/testing.go
+0
-0
No files found.
pkg/controller/volume/persistentvolume/delete_test.go
View file @
0b6c028c
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1"
storage
"k8s.io/api/storage/v1"
pvtesting
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"
)
)
// Test single call to syncVolume, expecting recycling to happen.
// Test single call to syncVolume, expecting recycling to happen.
...
@@ -91,11 +92,9 @@ func TestDeleteSync(t *testing.T) {
...
@@ -91,11 +92,9 @@ func TestDeleteSync(t *testing.T) {
noclaims
,
noclaims
,
noclaims
,
noclaims
,
noevents
,
noerrors
,
noevents
,
noerrors
,
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationDelete
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
)
{
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationDelete
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
)
{
// Delete the volume before delete operation starts
// Delete the volume before delete operation starts
reactor
.
lock
.
Lock
()
reactor
.
DeleteVolume
(
"volume8-6"
)
delete
(
reactor
.
volumes
,
"volume8-6"
)
reactor
.
lock
.
Unlock
()
}),
}),
},
},
{
{
...
@@ -108,16 +107,12 @@ func TestDeleteSync(t *testing.T) {
...
@@ -108,16 +107,12 @@ func TestDeleteSync(t *testing.T) {
noclaims
,
noclaims
,
newClaimArray
(
"claim8-7"
,
"uid8-7"
,
"10Gi"
,
"volume8-7"
,
v1
.
ClaimBound
,
nil
),
newClaimArray
(
"claim8-7"
,
"uid8-7"
,
"10Gi"
,
"volume8-7"
,
v1
.
ClaimBound
,
nil
),
noevents
,
noerrors
,
noevents
,
noerrors
,
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationDelete
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
volumeReactor
)
{
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationDelete
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
VolumeReactor
)
{
reactor
.
lock
.
Lock
()
defer
reactor
.
lock
.
Unlock
()
// Bind the volume to resurrected claim (this should never
// Bind the volume to resurrected claim (this should never
// happen)
// happen)
claim
:=
newClaim
(
"claim8-7"
,
"uid8-7"
,
"10Gi"
,
"volume8-7"
,
v1
.
ClaimBound
,
nil
)
claim
:=
newClaim
(
"claim8-7"
,
"uid8-7"
,
"10Gi"
,
"volume8-7"
,
v1
.
ClaimBound
,
nil
)
reactor
.
claims
[
claim
.
Name
]
=
claim
reactor
.
AddClaimBoundToVolume
(
claim
)
ctrl
.
claims
.
Add
(
claim
)
ctrl
.
claims
.
Add
(
claim
)
volume
:=
reactor
.
volumes
[
"volume8-7"
]
volume
.
Status
.
Phase
=
v1
.
VolumeBound
}),
}),
},
},
{
{
...
@@ -141,7 +136,7 @@ func TestDeleteSync(t *testing.T) {
...
@@ -141,7 +136,7 @@ func TestDeleteSync(t *testing.T) {
noclaims
,
noclaims
,
noclaims
,
noclaims
,
noevents
,
noerrors
,
noevents
,
noerrors
,
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
,
test
controllerTest
)
error
{
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
,
test
controllerTest
)
error
{
// Inject external deleter annotation
// Inject external deleter annotation
test
.
initialVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
test
.
initialVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
test
.
expectedVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
test
.
expectedVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
...
@@ -184,7 +179,7 @@ func TestDeleteSync(t *testing.T) {
...
@@ -184,7 +179,7 @@ func TestDeleteSync(t *testing.T) {
newClaimArray
(
"claim8-12"
,
"uid8-12"
,
"10Gi"
,
"volume8-12-2"
,
v1
.
ClaimBound
,
nil
),
newClaimArray
(
"claim8-12"
,
"uid8-12"
,
"10Gi"
,
"volume8-12-2"
,
v1
.
ClaimBound
,
nil
),
newClaimArray
(
"claim8-12"
,
"uid8-12"
,
"10Gi"
,
"volume8-12-2"
,
v1
.
ClaimBound
,
nil
),
newClaimArray
(
"claim8-12"
,
"uid8-12"
,
"10Gi"
,
"volume8-12-2"
,
v1
.
ClaimBound
,
nil
),
noevents
,
noerrors
,
noevents
,
noerrors
,
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
,
test
controllerTest
)
error
{
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
,
test
controllerTest
)
error
{
// Inject external deleter annotation
// Inject external deleter annotation
test
.
initialVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
test
.
initialVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
test
.
expectedVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
test
.
expectedVolumes
[
0
]
.
Annotations
[
annDynamicallyProvisioned
]
=
"external.io/test"
...
...
pkg/controller/volume/persistentvolume/framework_test.go
View file @
0b6c028c
This diff is collapsed.
Click to expand it.
pkg/controller/volume/persistentvolume/provision_test.go
View file @
0b6c028c
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
apierrs
"k8s.io/apimachinery/pkg/api/errors"
apierrs
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
pvtesting
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"
)
)
var
class1Parameters
=
map
[
string
]
string
{
var
class1Parameters
=
map
[
string
]
string
{
...
@@ -191,13 +192,11 @@ func TestProvisionSync(t *testing.T) {
...
@@ -191,13 +192,11 @@ func TestProvisionSync(t *testing.T) {
// The claim would be bound in next syncClaim
// The claim would be bound in next syncClaim
newClaimArray
(
"claim11-7"
,
"uid11-7"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-7"
,
"uid11-7"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
noevents
,
noerrors
,
noevents
,
noerrors
,
wrapTestWithInjectedOperation
(
wrapTestWithProvisionCalls
([]
provisionCall
{},
testSyncClaim
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
)
{
wrapTestWithInjectedOperation
(
wrapTestWithProvisionCalls
([]
provisionCall
{},
testSyncClaim
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
)
{
// Create a volume before provisionClaimOperation starts.
// Create a volume before provisionClaimOperation starts.
// This similates a parallel controller provisioning the volume.
// This similates a parallel controller provisioning the volume.
reactor
.
lock
.
Lock
()
volume
:=
newVolume
(
"pvc-uid11-7"
,
"1Gi"
,
"uid11-7"
,
"claim11-7"
,
v1
.
VolumeBound
,
v1
.
PersistentVolumeReclaimDelete
,
classGold
,
annBoundByController
,
annDynamicallyProvisioned
)
volume
:=
newVolume
(
"pvc-uid11-7"
,
"1Gi"
,
"uid11-7"
,
"claim11-7"
,
v1
.
VolumeBound
,
v1
.
PersistentVolumeReclaimDelete
,
classGold
,
annBoundByController
,
annDynamicallyProvisioned
)
reactor
.
volumes
[
volume
.
Name
]
=
volume
reactor
.
AddVolume
(
volume
)
reactor
.
lock
.
Unlock
()
}),
}),
},
},
{
{
...
@@ -210,7 +209,7 @@ func TestProvisionSync(t *testing.T) {
...
@@ -210,7 +209,7 @@ func TestProvisionSync(t *testing.T) {
// Binding will be completed in the next syncClaim
// Binding will be completed in the next syncClaim
newClaimArray
(
"claim11-8"
,
"uid11-8"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-8"
,
"uid11-8"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
[]
string
{
"Normal ProvisioningSucceeded"
},
[]
string
{
"Normal ProvisioningSucceeded"
},
[]
r
eactorError
{
[]
pvtesting
.
R
eactorError
{
// Inject error to the first
// Inject error to the first
// kubeclient.PersistentVolumes.Create() call. All other calls
// kubeclient.PersistentVolumes.Create() call. All other calls
// will succeed.
// will succeed.
...
@@ -227,7 +226,7 @@ func TestProvisionSync(t *testing.T) {
...
@@ -227,7 +226,7 @@ func TestProvisionSync(t *testing.T) {
newClaimArray
(
"claim11-9"
,
"uid11-9"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-9"
,
"uid11-9"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-9"
,
"uid11-9"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-9"
,
"uid11-9"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
[]
string
{
"Warning ProvisioningFailed"
},
[]
string
{
"Warning ProvisioningFailed"
},
[]
r
eactorError
{
[]
pvtesting
.
R
eactorError
{
// Inject error to five kubeclient.PersistentVolumes.Create()
// Inject error to five kubeclient.PersistentVolumes.Create()
// calls
// calls
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
...
@@ -252,7 +251,7 @@ func TestProvisionSync(t *testing.T) {
...
@@ -252,7 +251,7 @@ func TestProvisionSync(t *testing.T) {
newClaimArray
(
"claim11-10"
,
"uid11-10"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-10"
,
"uid11-10"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-10"
,
"uid11-10"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-10"
,
"uid11-10"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
[]
string
{
"Warning ProvisioningFailed"
,
"Warning ProvisioningCleanupFailed"
},
[]
string
{
"Warning ProvisioningFailed"
,
"Warning ProvisioningCleanupFailed"
},
[]
r
eactorError
{
[]
pvtesting
.
R
eactorError
{
// Inject error to five kubeclient.PersistentVolumes.Create()
// Inject error to five kubeclient.PersistentVolumes.Create()
// calls
// calls
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
...
@@ -273,7 +272,7 @@ func TestProvisionSync(t *testing.T) {
...
@@ -273,7 +272,7 @@ func TestProvisionSync(t *testing.T) {
newClaimArray
(
"claim11-11"
,
"uid11-11"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-11"
,
"uid11-11"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-11"
,
"uid11-11"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-11"
,
"uid11-11"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
[]
string
{
"Warning ProvisioningFailed"
,
"Warning ProvisioningCleanupFailed"
},
[]
string
{
"Warning ProvisioningFailed"
,
"Warning ProvisioningCleanupFailed"
},
[]
r
eactorError
{
[]
pvtesting
.
R
eactorError
{
// Inject error to five kubeclient.PersistentVolumes.Create()
// Inject error to five kubeclient.PersistentVolumes.Create()
// calls
// calls
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
...
@@ -303,7 +302,7 @@ func TestProvisionSync(t *testing.T) {
...
@@ -303,7 +302,7 @@ func TestProvisionSync(t *testing.T) {
newClaimArray
(
"claim11-12"
,
"uid11-12"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-12"
,
"uid11-12"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-12"
,
"uid11-12"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-12"
,
"uid11-12"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
[]
string
{
"Warning ProvisioningFailed"
},
[]
string
{
"Warning ProvisioningFailed"
},
[]
r
eactorError
{
[]
pvtesting
.
R
eactorError
{
// Inject error to five kubeclient.PersistentVolumes.Create()
// Inject error to five kubeclient.PersistentVolumes.Create()
// calls
// calls
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
...
@@ -397,7 +396,7 @@ func TestProvisionSync(t *testing.T) {
...
@@ -397,7 +396,7 @@ func TestProvisionSync(t *testing.T) {
newClaimArray
(
"claim11-19"
,
"uid11-19"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-19"
,
"uid11-19"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
),
newClaimArray
(
"claim11-19"
,
"uid11-19"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
newClaimArray
(
"claim11-19"
,
"uid11-19"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
&
classGold
,
annStorageProvisioner
),
noevents
,
noevents
,
[]
r
eactorError
{
[]
pvtesting
.
R
eactorError
{
// Inject errors to simulate crashed API server during
// Inject errors to simulate crashed API server during
// kubeclient.PersistentVolumes.Create()
// kubeclient.PersistentVolumes.Create()
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
{
"create"
,
"persistentvolumes"
,
errors
.
New
(
"Mock creation error1"
)},
...
...
pkg/controller/volume/persistentvolume/pv_controller_test.go
View file @
0b6c028c
...
@@ -30,6 +30,7 @@ import (
...
@@ -30,6 +30,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
pvtesting
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"
)
)
var
(
var
(
...
@@ -60,9 +61,9 @@ func TestControllerSync(t *testing.T) {
...
@@ -60,9 +61,9 @@ func TestControllerSync(t *testing.T) {
newClaimArray
(
"claim5-2"
,
"uid5-2"
,
"1Gi"
,
"volume5-2"
,
v1
.
ClaimBound
,
nil
,
annBoundByController
,
annBindCompleted
),
newClaimArray
(
"claim5-2"
,
"uid5-2"
,
"1Gi"
,
"volume5-2"
,
v1
.
ClaimBound
,
nil
,
annBoundByController
,
annBindCompleted
),
noevents
,
noerrors
,
noevents
,
noerrors
,
// Custom test function that generates an add event
// Custom test function that generates an add event
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
,
test
controllerTest
)
error
{
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
,
test
controllerTest
)
error
{
claim
:=
newClaim
(
"claim5-2"
,
"uid5-2"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
nil
)
claim
:=
newClaim
(
"claim5-2"
,
"uid5-2"
,
"1Gi"
,
""
,
v1
.
ClaimPending
,
nil
)
reactor
.
a
ddClaimEvent
(
claim
)
reactor
.
A
ddClaimEvent
(
claim
)
return
nil
return
nil
},
},
},
},
...
@@ -75,10 +76,10 @@ func TestControllerSync(t *testing.T) {
...
@@ -75,10 +76,10 @@ func TestControllerSync(t *testing.T) {
noclaims
,
noclaims
,
noevents
,
noerrors
,
noevents
,
noerrors
,
// Custom test function that generates a delete event
// Custom test function that generates a delete event
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
,
test
controllerTest
)
error
{
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
,
test
controllerTest
)
error
{
obj
:=
ctrl
.
claims
.
List
()[
0
]
obj
:=
ctrl
.
claims
.
List
()[
0
]
claim
:=
obj
.
(
*
v1
.
PersistentVolumeClaim
)
claim
:=
obj
.
(
*
v1
.
PersistentVolumeClaim
)
reactor
.
d
eleteClaimEvent
(
claim
)
reactor
.
D
eleteClaimEvent
(
claim
)
return
nil
return
nil
},
},
},
},
...
@@ -91,10 +92,10 @@ func TestControllerSync(t *testing.T) {
...
@@ -91,10 +92,10 @@ func TestControllerSync(t *testing.T) {
newClaimArray
(
"claim5-4"
,
"uid5-4"
,
"1Gi"
,
"volume5-4"
,
v1
.
ClaimLost
,
nil
,
annBoundByController
,
annBindCompleted
),
newClaimArray
(
"claim5-4"
,
"uid5-4"
,
"1Gi"
,
"volume5-4"
,
v1
.
ClaimLost
,
nil
,
annBoundByController
,
annBindCompleted
),
[]
string
{
"Warning ClaimLost"
},
noerrors
,
[]
string
{
"Warning ClaimLost"
},
noerrors
,
// Custom test function that generates a delete event
// Custom test function that generates a delete event
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
,
test
controllerTest
)
error
{
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
,
test
controllerTest
)
error
{
obj
:=
ctrl
.
volumes
.
store
.
List
()[
0
]
obj
:=
ctrl
.
volumes
.
store
.
List
()[
0
]
volume
:=
obj
.
(
*
v1
.
PersistentVolume
)
volume
:=
obj
.
(
*
v1
.
PersistentVolume
)
reactor
.
d
eleteVolumeEvent
(
volume
)
reactor
.
D
eleteVolumeEvent
(
volume
)
return
nil
return
nil
},
},
},
},
...
@@ -120,13 +121,13 @@ func TestControllerSync(t *testing.T) {
...
@@ -120,13 +121,13 @@ func TestControllerSync(t *testing.T) {
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
fakeVolumeWatch
,
fakeClaimWatch
,
test
.
errors
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
fakeVolumeWatch
,
fakeClaimWatch
,
test
.
errors
)
for
_
,
claim
:=
range
test
.
initialClaims
{
for
_
,
claim
:=
range
test
.
initialClaims
{
reactor
.
claims
[
claim
.
Name
]
=
claim
reactor
.
AddClaim
(
claim
)
go
func
(
claim
*
v1
.
PersistentVolumeClaim
)
{
go
func
(
claim
*
v1
.
PersistentVolumeClaim
)
{
fakeClaimWatch
.
Add
(
claim
)
fakeClaimWatch
.
Add
(
claim
)
}(
claim
)
}(
claim
)
}
}
for
_
,
volume
:=
range
test
.
initialVolumes
{
for
_
,
volume
:=
range
test
.
initialVolumes
{
reactor
.
volumes
[
volume
.
Name
]
=
volume
reactor
.
AddVolume
(
volume
)
go
func
(
volume
*
v1
.
PersistentVolume
)
{
go
func
(
volume
*
v1
.
PersistentVolume
)
{
fakeVolumeWatch
.
Add
(
volume
)
fakeVolumeWatch
.
Add
(
volume
)
}(
volume
)
}(
volume
)
...
@@ -148,7 +149,7 @@ func TestControllerSync(t *testing.T) {
...
@@ -148,7 +149,7 @@ func TestControllerSync(t *testing.T) {
klog
.
V
(
4
)
.
Infof
(
"controller synced, starting test"
)
klog
.
V
(
4
)
.
Infof
(
"controller synced, starting test"
)
// Call the tested function
// Call the tested function
err
=
test
.
test
(
ctrl
,
reactor
,
test
)
err
=
test
.
test
(
ctrl
,
reactor
.
VolumeReactor
,
test
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Test %q initial test call failed: %v"
,
test
.
name
,
err
)
t
.
Errorf
(
"Test %q initial test call failed: %v"
,
test
.
name
,
err
)
}
}
...
@@ -162,7 +163,7 @@ func TestControllerSync(t *testing.T) {
...
@@ -162,7 +163,7 @@ func TestControllerSync(t *testing.T) {
}
}
close
(
stopCh
)
close
(
stopCh
)
evaluateTestResults
(
ctrl
,
reactor
,
test
,
t
)
evaluateTestResults
(
ctrl
,
reactor
.
VolumeReactor
,
test
,
t
)
}
}
}
}
...
...
pkg/controller/volume/persistentvolume/recycle_test.go
View file @
0b6c028c
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1"
storage
"k8s.io/api/storage/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
pvtesting
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"
)
)
// Test single call to syncVolume, expecting recycling to happen.
// Test single call to syncVolume, expecting recycling to happen.
...
@@ -130,11 +131,9 @@ func TestRecycleSync(t *testing.T) {
...
@@ -130,11 +131,9 @@ func TestRecycleSync(t *testing.T) {
noclaims
,
noclaims
,
noclaims
,
noclaims
,
noevents
,
noerrors
,
noevents
,
noerrors
,
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationRecycle
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
)
{
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationRecycle
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
)
{
// Delete the volume before recycle operation starts
// Delete the volume before recycle operation starts
reactor
.
lock
.
Lock
()
reactor
.
DeleteVolume
(
"volume6-6"
)
delete
(
reactor
.
volumes
,
"volume6-6"
)
reactor
.
lock
.
Unlock
()
}),
}),
},
},
{
{
...
@@ -147,14 +146,9 @@ func TestRecycleSync(t *testing.T) {
...
@@ -147,14 +146,9 @@ func TestRecycleSync(t *testing.T) {
noclaims
,
noclaims
,
noclaims
,
noclaims
,
noevents
,
noerrors
,
noevents
,
noerrors
,
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationRecycle
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
)
{
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationRecycle
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
)
{
// Mark the volume as Available before the recycler starts
// Mark the volume as Available before the recycler starts
reactor
.
lock
.
Lock
()
reactor
.
MarkVolumeAvaiable
(
"volume6-7"
)
volume
:=
reactor
.
volumes
[
"volume6-7"
]
volume
.
Spec
.
ClaimRef
=
nil
volume
.
Status
.
Phase
=
v1
.
VolumeAvailable
volume
.
Annotations
=
nil
reactor
.
lock
.
Unlock
()
}),
}),
},
},
{
{
...
@@ -164,17 +158,13 @@ func TestRecycleSync(t *testing.T) {
...
@@ -164,17 +158,13 @@ func TestRecycleSync(t *testing.T) {
// user.
// user.
"6-8 - prebound volume is deleted before recycling"
,
"6-8 - prebound volume is deleted before recycling"
,
newVolumeArray
(
"volume6-8"
,
"1Gi"
,
"uid6-8"
,
"claim6-8"
,
v1
.
VolumeBound
,
v1
.
PersistentVolumeReclaimRecycle
,
classEmpty
),
newVolumeArray
(
"volume6-8"
,
"1Gi"
,
"uid6-8"
,
"claim6-8"
,
v1
.
VolumeBound
,
v1
.
PersistentVolumeReclaimRecycle
,
classEmpty
),
newVolumeArray
(
"volume6-8"
,
"1Gi"
,
""
,
"
claim6-8
"
,
v1
.
VolumeAvailable
,
v1
.
PersistentVolumeReclaimRecycle
,
classEmpty
),
newVolumeArray
(
"volume6-8"
,
"1Gi"
,
""
,
""
,
v1
.
VolumeAvailable
,
v1
.
PersistentVolumeReclaimRecycle
,
classEmpty
),
noclaims
,
noclaims
,
noclaims
,
noclaims
,
noevents
,
noerrors
,
noevents
,
noerrors
,
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationRecycle
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
v
olumeReactor
)
{
wrapTestWithInjectedOperation
(
wrapTestWithReclaimCalls
(
operationRecycle
,
[]
error
{},
testSyncVolume
),
func
(
ctrl
*
PersistentVolumeController
,
reactor
*
pvtesting
.
V
olumeReactor
)
{
// Mark the volume as Available before the recycler starts
// Mark the volume as Available before the recycler starts
reactor
.
lock
.
Lock
()
reactor
.
MarkVolumeAvaiable
(
"volume6-8"
)
volume
:=
reactor
.
volumes
[
"volume6-8"
]
volume
.
Spec
.
ClaimRef
.
UID
=
""
volume
.
Status
.
Phase
=
v1
.
VolumeAvailable
reactor
.
lock
.
Unlock
()
}),
}),
},
},
{
{
...
...
pkg/controller/volume/persistentvolume/testing/testing.go
0 → 100644
View file @
0b6c028c
This diff is collapsed.
Click to expand it.
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