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
b646a729
Commit
b646a729
authored
Sep 07, 2017
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address comments
parent
124344a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
40 deletions
+89
-40
deployment_test.go
test/integration/deployment/deployment_test.go
+62
-24
util.go
test/integration/deployment/util.go
+27
-16
No files found.
test/integration/deployment/deployment_test.go
View file @
b646a729
...
@@ -54,13 +54,20 @@ func TestNewDeployment(t *testing.T) {
...
@@ -54,13 +54,20 @@ func TestNewDeployment(t *testing.T) {
go
dc
.
Run
(
5
,
stopCh
)
go
dc
.
Run
(
5
,
stopCh
)
// Wait for the Deployment to be updated to revision 1
// Wait for the Deployment to be updated to revision 1
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
)
if
err
:=
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
()
if
err
:=
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Check new RS annotations
// Check new RS annotations
newRS
:=
tester
.
expectNewReplicaSet
()
newRS
,
err
:=
tester
.
expectNewReplicaSet
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
newRS
.
Annotations
[
"test"
]
!=
"should-copy-to-replica-set"
{
if
newRS
.
Annotations
[
"test"
]
!=
"should-copy-to-replica-set"
{
t
.
Errorf
(
"expected new ReplicaSet annotations copied from Deployment %s, got: %v"
,
tester
.
deployment
.
Name
,
newRS
.
Annotations
)
t
.
Errorf
(
"expected new ReplicaSet annotations copied from Deployment %s, got: %v"
,
tester
.
deployment
.
Name
,
newRS
.
Annotations
)
}
}
...
@@ -159,35 +166,47 @@ func TestPausedDeployment(t *testing.T) {
...
@@ -159,35 +166,47 @@ func TestPausedDeployment(t *testing.T) {
go
dc
.
Run
(
5
,
stopCh
)
go
dc
.
Run
(
5
,
stopCh
)
// Verify that the paused deployment won't create new replica set.
// Verify that the paused deployment won't create new replica set.
tester
.
expectNoNewReplicaSet
()
if
err
:=
tester
.
expectNoNewReplicaSet
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Resume the deployment
// Resume the deployment
tester
.
deployment
,
err
=
tester
.
updateDeployment
(
resumeFn
())
tester
.
deployment
,
err
=
tester
.
updateDeployment
(
resumeFn
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"failed to resume deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
t
.
Fatal
f
(
"failed to resume deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
}
// Wait for the controller to notice the resume.
// Wait for the controller to notice the resume.
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
)
if
err
:=
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Wait for the Deployment to be updated to revision 1
// Wait for the Deployment to be updated to revision 1
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
)
if
err
:=
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
()
if
err
:=
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// A new replicaset should be created.
// A new replicaset should be created.
tester
.
expectNewReplicaSet
()
if
_
,
err
:=
tester
.
expectNewReplicaSet
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Pause the deployment.
// Pause the deployment.
// The paused deployment shouldn't trigger a new rollout.
// The paused deployment shouldn't trigger a new rollout.
tester
.
deployment
,
err
=
tester
.
updateDeployment
(
pauseFn
())
tester
.
deployment
,
err
=
tester
.
updateDeployment
(
pauseFn
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"failed to pause deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
t
.
Fatal
f
(
"failed to pause deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
}
// Wait for the controller to notice the pause.
// Wait for the controller to notice the pause.
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
)
if
err
:=
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Update the deployment template
// Update the deployment template
newTGPS
:=
int64
(
0
)
newTGPS
:=
int64
(
0
)
...
@@ -195,18 +214,22 @@ func TestPausedDeployment(t *testing.T) {
...
@@ -195,18 +214,22 @@ func TestPausedDeployment(t *testing.T) {
update
.
Spec
.
Template
.
Spec
.
TerminationGracePeriodSeconds
=
&
newTGPS
update
.
Spec
.
Template
.
Spec
.
TerminationGracePeriodSeconds
=
&
newTGPS
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"failed updating
deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
t
.
Fatalf
(
"failed updating template of
deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
}
// Wait for the controller to notice the rollout.
// Wait for the controller to notice the rollout.
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
)
if
err
:=
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Verify that the paused deployment won't create new replica set.
// Verify that the paused deployment won't create new replica set.
tester
.
expectNoNewReplicaSet
()
if
err
:=
tester
.
expectNoNewReplicaSet
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
allOldRs
,
err
:=
deploymentutil
.
GetOldReplicaSets
(
tester
.
deployment
,
c
.
ExtensionsV1beta1
())
_
,
allOldRs
,
err
:=
deploymentutil
.
GetOldReplicaSets
(
tester
.
deployment
,
c
.
ExtensionsV1beta1
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"failed retrieving old replicasets of deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
t
.
Fatal
f
(
"failed retrieving old replicasets of deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
}
if
len
(
allOldRs
)
!=
1
{
if
len
(
allOldRs
)
!=
1
{
t
.
Errorf
(
"expected an old replica set, got %v"
,
allOldRs
)
t
.
Errorf
(
"expected an old replica set, got %v"
,
allOldRs
)
...
@@ -243,22 +266,30 @@ func TestScalePausedDeployment(t *testing.T) {
...
@@ -243,22 +266,30 @@ func TestScalePausedDeployment(t *testing.T) {
go
dc
.
Run
(
5
,
stopCh
)
go
dc
.
Run
(
5
,
stopCh
)
// Wait for the Deployment to be updated to revision 1
// Wait for the Deployment to be updated to revision 1
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
)
if
err
:=
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
()
if
err
:=
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// A new replicaset should be created.
// A new replicaset should be created.
tester
.
expectNewReplicaSet
()
if
_
,
err
:=
tester
.
expectNewReplicaSet
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Pause the deployment.
// Pause the deployment.
tester
.
deployment
,
err
=
tester
.
updateDeployment
(
pauseFn
())
tester
.
deployment
,
err
=
tester
.
updateDeployment
(
pauseFn
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"failed to pause deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
t
.
Fatal
f
(
"failed to pause deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
}
// Wait for the controller to notice the scale.
// Wait for the controller to notice the scale.
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
)
if
err
:=
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Scale the paused deployment.
// Scale the paused deployment.
newReplicas
:=
int32
(
10
)
newReplicas
:=
int32
(
10
)
...
@@ -266,18 +297,25 @@ func TestScalePausedDeployment(t *testing.T) {
...
@@ -266,18 +297,25 @@ func TestScalePausedDeployment(t *testing.T) {
update
.
Spec
.
Replicas
=
&
newReplicas
update
.
Spec
.
Replicas
=
&
newReplicas
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"failed updating deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
t
.
Fatal
f
(
"failed updating deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
}
// Wait for the controller to notice the scale.
// Wait for the controller to notice the scale.
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
)
if
err
:=
tester
.
waitForObservedDeployment
(
tester
.
deployment
.
Generation
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Verify that the new replicaset is scaled.
// Verify that the new replicaset is scaled.
rs
:=
tester
.
expectNewReplicaSet
()
rs
,
err
:=
tester
.
expectNewReplicaSet
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
*
rs
.
Spec
.
Replicas
!=
newReplicas
{
if
*
rs
.
Spec
.
Replicas
!=
newReplicas
{
t
.
Errorf
(
"expected new replicaset replicas = %d, got %d"
,
newReplicas
,
*
rs
.
Spec
.
Replicas
)
t
.
Errorf
(
"expected new replicaset replicas = %d, got %d"
,
newReplicas
,
*
rs
.
Spec
.
Replicas
)
}
}
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
// Make sure the Deployment status becomes valid while manually marking Deployment pods as ready at the same time
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
()
if
err
:=
tester
.
waitForDeploymentStatusValidAndMarkPodsReady
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
test/integration/deployment/util.go
View file @
b646a729
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
deployment
package
deployment
import
(
import
(
"fmt"
"net/http/httptest"
"net/http/httptest"
"testing"
"testing"
"time"
"time"
...
@@ -144,10 +145,11 @@ func addPodConditionReady(pod *v1.Pod, time metav1.Time) {
...
@@ -144,10 +145,11 @@ func addPodConditionReady(pod *v1.Pod, time metav1.Time) {
}
}
}
}
func
(
d
*
deploymentTester
)
waitForDeploymentRevisionAndImage
(
revision
,
image
string
)
{
func
(
d
*
deploymentTester
)
waitForDeploymentRevisionAndImage
(
revision
,
image
string
)
error
{
if
err
:=
testutil
.
WaitForDeploymentRevisionAndImage
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
revision
,
image
,
d
.
t
.
Logf
,
pollInterval
,
pollTimeout
);
err
!=
nil
{
if
err
:=
testutil
.
WaitForDeploymentRevisionAndImage
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
revision
,
image
,
d
.
t
.
Logf
,
pollInterval
,
pollTimeout
);
err
!=
nil
{
d
.
t
.
Fatal
f
(
"failed to wait for Deployment revision %s: %v"
,
d
.
deployment
.
Name
,
err
)
return
fmt
.
Error
f
(
"failed to wait for Deployment revision %s: %v"
,
d
.
deployment
.
Name
,
err
)
}
}
return
nil
}
}
// markAllPodsReady manually updates all Deployment pods status to ready
// markAllPodsReady manually updates all Deployment pods status to ready
...
@@ -194,48 +196,57 @@ func (d *deploymentTester) waitForDeploymentStatusValid() error {
...
@@ -194,48 +196,57 @@ func (d *deploymentTester) waitForDeploymentStatusValid() error {
// waitForDeploymentStatusValidAndMarkPodsReady waits for the Deployment status to become valid
// waitForDeploymentStatusValidAndMarkPodsReady waits for the Deployment status to become valid
// while marking all Deployment pods as ready at the same time.
// while marking all Deployment pods as ready at the same time.
func
(
d
*
deploymentTester
)
waitForDeploymentStatusValidAndMarkPodsReady
()
{
func
(
d
*
deploymentTester
)
waitForDeploymentStatusValidAndMarkPodsReady
()
error
{
// Manually mark all Deployment pods as ready in a separate goroutine
// Manually mark all Deployment pods as ready in a separate goroutine
go
d
.
markAllPodsReady
()
go
d
.
markAllPodsReady
()
// Make sure the Deployment status is valid while Deployment pods are becoming ready
// Make sure the Deployment status is valid while Deployment pods are becoming ready
err
:=
d
.
waitForDeploymentStatusValid
()
err
:=
d
.
waitForDeploymentStatusValid
()
if
err
!=
nil
{
if
err
!=
nil
{
d
.
t
.
Fatal
f
(
"failed to wait for Deployment status %s: %v"
,
d
.
deployment
.
Name
,
err
)
return
fmt
.
Error
f
(
"failed to wait for Deployment status %s: %v"
,
d
.
deployment
.
Name
,
err
)
}
}
return
nil
}
}
func
(
d
*
deploymentTester
)
updateDeployment
(
applyUpdate
testutil
.
UpdateDeploymentFunc
)
(
*
v1beta1
.
Deployment
,
error
)
{
func
(
d
*
deploymentTester
)
updateDeployment
(
applyUpdate
testutil
.
UpdateDeploymentFunc
)
(
*
v1beta1
.
Deployment
,
error
)
{
return
testutil
.
UpdateDeploymentWithRetries
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
applyUpdate
,
d
.
t
.
Logf
)
return
testutil
.
UpdateDeploymentWithRetries
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
applyUpdate
,
d
.
t
.
Logf
)
}
}
func
(
d
*
deploymentTester
)
waitForObservedDeployment
(
desiredGeneration
int64
)
{
func
(
d
*
deploymentTester
)
waitForObservedDeployment
(
desiredGeneration
int64
)
error
{
if
err
:=
testutil
.
WaitForObservedDeployment
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
desiredGeneration
);
err
!=
nil
{
if
err
:=
testutil
.
WaitForObservedDeployment
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
desiredGeneration
);
err
!=
nil
{
d
.
t
.
Fatal
f
(
"failed waiting for ObservedGeneration of deployment %s to become %d: %v"
,
d
.
deployment
.
Name
,
desiredGeneration
,
err
)
return
fmt
.
Error
f
(
"failed waiting for ObservedGeneration of deployment %s to become %d: %v"
,
d
.
deployment
.
Name
,
desiredGeneration
,
err
)
}
}
return
nil
}
}
func
(
d
*
deploymentTester
)
getNewReplicaSet
()
*
v1beta1
.
ReplicaSet
{
func
(
d
*
deploymentTester
)
getNewReplicaSet
()
(
*
v1beta1
.
ReplicaSet
,
error
)
{
rs
,
err
:=
deploymentutil
.
GetNewReplicaSet
(
d
.
deployment
,
d
.
c
.
ExtensionsV1beta1
())
rs
,
err
:=
deploymentutil
.
GetNewReplicaSet
(
d
.
deployment
,
d
.
c
.
ExtensionsV1beta1
())
if
err
!=
nil
{
if
err
!=
nil
{
d
.
t
.
Fatal
f
(
"failed retrieving new replicaset of deployment %s: %v"
,
d
.
deployment
.
Name
,
err
)
return
nil
,
fmt
.
Error
f
(
"failed retrieving new replicaset of deployment %s: %v"
,
d
.
deployment
.
Name
,
err
)
}
}
return
rs
return
rs
,
nil
}
}
func
(
d
*
deploymentTester
)
expectNoNewReplicaSet
()
{
func
(
d
*
deploymentTester
)
expectNoNewReplicaSet
()
error
{
rs
:=
d
.
getNewReplicaSet
()
rs
,
err
:=
d
.
getNewReplicaSet
()
if
err
!=
nil
{
return
err
}
if
rs
!=
nil
{
if
rs
!=
nil
{
d
.
t
.
Fatal
f
(
"expected deployment %s not to create a new replicaset, got %v"
,
d
.
deployment
.
Name
,
rs
)
return
fmt
.
Error
f
(
"expected deployment %s not to create a new replicaset, got %v"
,
d
.
deployment
.
Name
,
rs
)
}
}
return
nil
}
}
func
(
d
*
deploymentTester
)
expectNewReplicaSet
()
*
v1beta1
.
ReplicaSet
{
func
(
d
*
deploymentTester
)
expectNewReplicaSet
()
(
*
v1beta1
.
ReplicaSet
,
error
)
{
rs
:=
d
.
getNewReplicaSet
()
rs
,
err
:=
d
.
getNewReplicaSet
()
if
err
!=
nil
{
return
nil
,
err
}
if
rs
==
nil
{
if
rs
==
nil
{
d
.
t
.
Fatal
f
(
"expected deployment %s to create a new replicaset, got nil"
,
d
.
deployment
.
Name
)
return
nil
,
fmt
.
Error
f
(
"expected deployment %s to create a new replicaset, got nil"
,
d
.
deployment
.
Name
)
}
}
return
rs
return
rs
,
nil
}
}
func
pauseFn
()
func
(
update
*
v1beta1
.
Deployment
)
{
func
pauseFn
()
func
(
update
*
v1beta1
.
Deployment
)
{
...
...
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