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
1334b610
Commit
1334b610
authored
Feb 01, 2018
by
Jun Xiang Tee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add basic functionality deployment integration tests
parent
02f14bc6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
124 additions
and
8 deletions
+124
-8
deployment.go
test/e2e/apps/deployment.go
+1
-1
deployment_util.go
test/e2e/framework/deployment_util.go
+3
-3
BUILD
test/integration/deployment/BUILD
+3
-0
deployment_test.go
test/integration/deployment/deployment_test.go
+0
-0
util.go
test/integration/deployment/util.go
+92
-2
deployment.go
test/utils/deployment.go
+2
-2
replicaset.go
test/utils/replicaset.go
+23
-0
No files found.
test/e2e/apps/deployment.go
View file @
1334b610
...
...
@@ -423,7 +423,7 @@ func testRolloverDeployment(f *framework.Framework) {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
framework
.
Logf
(
"Make sure deployment %q performs scaling operations"
,
deploymentName
)
// Make sure the deployment starts to scale up and down replica sets by checking if its updated replicas >= 1
err
=
framework
.
WaitForDeploymentUpdatedReplicas
L
TE
(
c
,
ns
,
deploymentName
,
deploymentReplicas
,
deployment
.
Generation
)
err
=
framework
.
WaitForDeploymentUpdatedReplicas
G
TE
(
c
,
ns
,
deploymentName
,
deploymentReplicas
,
deployment
.
Generation
)
// Check if it's updated to revision 1 correctly
framework
.
Logf
(
"Check revision of new replica set for deployment %q"
,
deploymentName
)
err
=
framework
.
CheckDeploymentRevisionAndImage
(
c
,
ns
,
deploymentName
,
"1"
,
deploymentImage
)
...
...
test/e2e/framework/deployment_util.go
View file @
1334b610
...
...
@@ -127,9 +127,9 @@ func WaitForDeploymentCompleteAndCheckRolling(c clientset.Interface, d *extensio
return
testutils
.
WaitForDeploymentCompleteAndCheckRolling
(
c
,
d
,
Logf
,
Poll
,
pollLongTimeout
)
}
// WaitForDeploymentUpdatedReplicas
L
TE waits for given deployment to be observed by the controller and has at least a number of updatedReplicas
func
WaitForDeploymentUpdatedReplicas
L
TE
(
c
clientset
.
Interface
,
ns
,
deploymentName
string
,
minUpdatedReplicas
int32
,
desiredGeneration
int64
)
error
{
return
testutils
.
WaitForDeploymentUpdatedReplicas
L
TE
(
c
,
ns
,
deploymentName
,
minUpdatedReplicas
,
desiredGeneration
,
Poll
,
pollLongTimeout
)
// WaitForDeploymentUpdatedReplicas
G
TE waits for given deployment to be observed by the controller and has at least a number of updatedReplicas
func
WaitForDeploymentUpdatedReplicas
G
TE
(
c
clientset
.
Interface
,
ns
,
deploymentName
string
,
minUpdatedReplicas
int32
,
desiredGeneration
int64
)
error
{
return
testutils
.
WaitForDeploymentUpdatedReplicas
G
TE
(
c
,
ns
,
deploymentName
,
minUpdatedReplicas
,
desiredGeneration
,
Poll
,
pollLongTimeout
)
}
// WaitForDeploymentRollbackCleared waits for given deployment either started rolling back or doesn't need to rollback.
...
...
test/integration/deployment/BUILD
View file @
1334b610
...
...
@@ -18,12 +18,15 @@ go_test(
tags = ["integration"],
deps = [
"//pkg/controller/deployment/util:go_default_library",
"//pkg/util/pointer:go_default_library",
"//test/integration/framework:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/util/retry:go_default_library",
],
)
...
...
test/integration/deployment/deployment_test.go
View file @
1334b610
This diff is collapsed.
Click to expand it.
test/integration/deployment/util.go
View file @
1334b610
...
...
@@ -368,6 +368,10 @@ func (d *deploymentTester) updateReplicaSet(name string, applyUpdate testutil.Up
return
testutil
.
UpdateReplicaSetWithRetries
(
d
.
c
,
d
.
deployment
.
Namespace
,
name
,
applyUpdate
,
d
.
t
.
Logf
,
pollInterval
,
pollTimeout
)
}
func
(
d
*
deploymentTester
)
updateReplicaSetStatus
(
name
string
,
applyStatusUpdate
testutil
.
UpdateReplicaSetFunc
)
(
*
v1beta1
.
ReplicaSet
,
error
)
{
return
testutil
.
UpdateReplicaSetStatusWithRetries
(
d
.
c
,
d
.
deployment
.
Namespace
,
name
,
applyStatusUpdate
,
d
.
t
.
Logf
,
pollInterval
,
pollTimeout
)
}
// waitForDeploymentRollbackCleared waits for deployment either started rolling back or doesn't need to rollback.
func
(
d
*
deploymentTester
)
waitForDeploymentRollbackCleared
()
error
{
return
testutil
.
WaitForDeploymentRollbackCleared
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
pollInterval
,
pollTimeout
)
...
...
@@ -378,8 +382,8 @@ func (d *deploymentTester) checkDeploymentRevisionAndImage(revision, image strin
return
testutil
.
CheckDeploymentRevisionAndImage
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
revision
,
image
)
}
func
(
d
*
deploymentTester
)
waitForDeploymentUpdatedReplicas
L
TE
(
minUpdatedReplicas
int32
)
error
{
return
testutil
.
WaitForDeploymentUpdatedReplicas
L
TE
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
minUpdatedReplicas
,
d
.
deployment
.
Generation
,
pollInterval
,
pollTimeout
)
func
(
d
*
deploymentTester
)
waitForDeploymentUpdatedReplicas
G
TE
(
minUpdatedReplicas
int32
)
error
{
return
testutil
.
WaitForDeploymentUpdatedReplicas
G
TE
(
d
.
c
,
d
.
deployment
.
Namespace
,
d
.
deployment
.
Name
,
minUpdatedReplicas
,
d
.
deployment
.
Generation
,
pollInterval
,
pollTimeout
)
}
func
(
d
*
deploymentTester
)
waitForDeploymentWithCondition
(
reason
string
,
condType
v1beta1
.
DeploymentConditionType
)
error
{
...
...
@@ -416,3 +420,89 @@ func (d *deploymentTester) listUpdatedPods() ([]v1.Pod, error) {
func
(
d
*
deploymentTester
)
waitRSStable
(
replicaset
*
v1beta1
.
ReplicaSet
)
error
{
return
testutil
.
WaitRSStable
(
d
.
t
,
d
.
c
,
replicaset
,
pollInterval
,
pollTimeout
)
}
func
(
d
*
deploymentTester
)
scaleDeployment
(
newReplicas
int32
)
error
{
var
err
error
d
.
deployment
,
err
=
d
.
updateDeployment
(
func
(
update
*
v1beta1
.
Deployment
)
{
update
.
Spec
.
Replicas
=
&
newReplicas
})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed updating deployment %q: %v"
,
d
.
deployment
.
Name
,
err
)
}
if
err
:=
d
.
waitForDeploymentCompleteAndMarkPodsReady
();
err
!=
nil
{
return
err
}
rs
,
err
:=
d
.
expectNewReplicaSet
()
if
err
!=
nil
{
return
err
}
if
*
rs
.
Spec
.
Replicas
!=
newReplicas
{
return
fmt
.
Errorf
(
"expected new replicaset replicas = %d, got %d"
,
newReplicas
,
*
rs
.
Spec
.
Replicas
)
}
return
nil
}
// waitForReadyReplicas waits for number of ready replicas to equal number of replicas.
func
(
d
*
deploymentTester
)
waitForReadyReplicas
()
error
{
if
err
:=
wait
.
PollImmediate
(
pollInterval
,
pollTimeout
,
func
()
(
bool
,
error
)
{
deployment
,
err
:=
d
.
c
.
ExtensionsV1beta1
()
.
Deployments
(
d
.
deployment
.
Namespace
)
.
Get
(
d
.
deployment
.
Name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"failed to get deployment %q: %v"
,
d
.
deployment
.
Name
,
err
)
}
return
deployment
.
Status
.
ReadyReplicas
==
*
deployment
.
Spec
.
Replicas
,
nil
});
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to wait for .readyReplicas to equal .replicas: %v"
,
err
)
}
return
nil
}
// markUpdatedPodsReadyWithoutComplete marks updated Deployment pods as ready without waiting for deployment to complete.
func
(
d
*
deploymentTester
)
markUpdatedPodsReadyWithoutComplete
()
error
{
if
err
:=
wait
.
PollImmediate
(
pollInterval
,
pollTimeout
,
func
()
(
bool
,
error
)
{
pods
,
err
:=
d
.
listUpdatedPods
()
if
err
!=
nil
{
return
false
,
err
}
for
i
:=
range
pods
{
pod
:=
pods
[
i
]
if
podutil
.
IsPodReady
(
&
pod
)
{
continue
}
if
err
=
markPodReady
(
d
.
c
,
d
.
deployment
.
Namespace
,
&
pod
);
err
!=
nil
{
d
.
t
.
Logf
(
"failed to update Deployment pod %q, will retry later: %v"
,
pod
.
Name
,
err
)
return
false
,
nil
}
}
return
true
,
nil
});
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to mark all updated pods as ready: %v"
,
err
)
}
return
nil
}
// Verify all replicas fields of DeploymentStatus have desired count.
// Immediately return an error when found a non-matching replicas field.
func
(
d
*
deploymentTester
)
checkDeploymentStatusReplicasFields
(
replicas
,
updatedReplicas
,
readyReplicas
,
availableReplicas
,
unavailableReplicas
int32
)
error
{
deployment
,
err
:=
d
.
c
.
ExtensionsV1beta1
()
.
Deployments
(
d
.
deployment
.
Namespace
)
.
Get
(
d
.
deployment
.
Name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get deployment %q: %v"
,
d
.
deployment
.
Name
,
err
)
}
if
deployment
.
Status
.
Replicas
!=
replicas
{
return
fmt
.
Errorf
(
"unexpected .replicas: expect %d, got %d"
,
replicas
,
deployment
.
Status
.
Replicas
)
}
if
deployment
.
Status
.
UpdatedReplicas
!=
updatedReplicas
{
return
fmt
.
Errorf
(
"unexpected .updatedReplicas: expect %d, got %d"
,
updatedReplicas
,
deployment
.
Status
.
UpdatedReplicas
)
}
if
deployment
.
Status
.
ReadyReplicas
!=
readyReplicas
{
return
fmt
.
Errorf
(
"unexpected .readyReplicas: expect %d, got %d"
,
readyReplicas
,
deployment
.
Status
.
ReadyReplicas
)
}
if
deployment
.
Status
.
AvailableReplicas
!=
availableReplicas
{
return
fmt
.
Errorf
(
"unexpected .replicas: expect %d, got %d"
,
availableReplicas
,
deployment
.
Status
.
AvailableReplicas
)
}
if
deployment
.
Status
.
UnavailableReplicas
!=
unavailableReplicas
{
return
fmt
.
Errorf
(
"unexpected .replicas: expect %d, got %d"
,
unavailableReplicas
,
deployment
.
Status
.
UnavailableReplicas
)
}
return
nil
}
test/utils/deployment.go
View file @
1334b610
...
...
@@ -302,8 +302,8 @@ func WaitForDeploymentRollbackCleared(c clientset.Interface, ns, deploymentName
return
nil
}
// WaitForDeploymentUpdatedReplicas
L
TE waits for given deployment to be observed by the controller and has at least a number of updatedReplicas
func
WaitForDeploymentUpdatedReplicas
L
TE
(
c
clientset
.
Interface
,
ns
,
deploymentName
string
,
minUpdatedReplicas
int32
,
desiredGeneration
int64
,
pollInterval
,
pollTimeout
time
.
Duration
)
error
{
// WaitForDeploymentUpdatedReplicas
G
TE waits for given deployment to be observed by the controller and has at least a number of updatedReplicas
func
WaitForDeploymentUpdatedReplicas
G
TE
(
c
clientset
.
Interface
,
ns
,
deploymentName
string
,
minUpdatedReplicas
int32
,
desiredGeneration
int64
,
pollInterval
,
pollTimeout
time
.
Duration
)
error
{
var
deployment
*
extensions
.
Deployment
err
:=
wait
.
PollImmediate
(
pollInterval
,
pollTimeout
,
func
()
(
bool
,
error
)
{
d
,
err
:=
c
.
ExtensionsV1beta1
()
.
Deployments
(
ns
)
.
Get
(
deploymentName
,
metav1
.
GetOptions
{})
...
...
test/utils/replicaset.go
View file @
1334b610
...
...
@@ -66,3 +66,26 @@ func WaitRSStable(t *testing.T, clientSet clientset.Interface, rs *extensions.Re
}
return
nil
}
func
UpdateReplicaSetStatusWithRetries
(
c
clientset
.
Interface
,
namespace
,
name
string
,
applyUpdate
UpdateReplicaSetFunc
,
logf
LogfFn
,
pollInterval
,
pollTimeout
time
.
Duration
)
(
*
extensions
.
ReplicaSet
,
error
)
{
var
rs
*
extensions
.
ReplicaSet
var
updateErr
error
pollErr
:=
wait
.
PollImmediate
(
pollInterval
,
pollTimeout
,
func
()
(
bool
,
error
)
{
var
err
error
if
rs
,
err
=
c
.
ExtensionsV1beta1
()
.
ReplicaSets
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{});
err
!=
nil
{
return
false
,
err
}
// Apply the update, then attempt to push it to the apiserver.
applyUpdate
(
rs
)
if
rs
,
err
=
c
.
ExtensionsV1beta1
()
.
ReplicaSets
(
namespace
)
.
UpdateStatus
(
rs
);
err
==
nil
{
logf
(
"Updating replica set %q"
,
name
)
return
true
,
nil
}
updateErr
=
err
return
false
,
nil
})
if
pollErr
==
wait
.
ErrWaitTimeout
{
pollErr
=
fmt
.
Errorf
(
"couldn't apply the provided update to replicaset %q: %v"
,
name
,
updateErr
)
}
return
rs
,
pollErr
}
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