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
c5cef187
Commit
c5cef187
authored
Aug 17, 2016
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add e2e test for overlapping deployments
parent
90557ec5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
1 deletion
+125
-1
deployment.go
test/e2e/deployment.go
+112
-1
util.go
test/e2e/framework/util.go
+13
-0
No files found.
test/e2e/deployment.go
View file @
c5cef187
...
@@ -86,6 +86,9 @@ var _ = framework.KubeDescribe("Deployment", func() {
...
@@ -86,6 +86,9 @@ var _ = framework.KubeDescribe("Deployment", func() {
It
(
"scaled rollout deployment should not block on annotation check"
,
func
()
{
It
(
"scaled rollout deployment should not block on annotation check"
,
func
()
{
testScaledRolloutDeployment
(
f
)
testScaledRolloutDeployment
(
f
)
})
})
It
(
"overlapping deployment should not fight with each other"
,
func
()
{
testOverlappingDeployment
(
f
)
})
// TODO: add tests that cover deployment.Spec.MinReadySeconds once we solved clock-skew issues
// TODO: add tests that cover deployment.Spec.MinReadySeconds once we solved clock-skew issues
})
})
...
@@ -203,7 +206,7 @@ func stopDeployment(c *clientset.Clientset, oldC client.Interface, ns, deploymen
...
@@ -203,7 +206,7 @@ func stopDeployment(c *clientset.Clientset, oldC client.Interface, ns, deploymen
framework
.
Logf
(
"Ensuring deployment %s's Pods were deleted"
,
deploymentName
)
framework
.
Logf
(
"Ensuring deployment %s's Pods were deleted"
,
deploymentName
)
var
pods
*
api
.
PodList
var
pods
*
api
.
PodList
if
err
:=
wait
.
PollImmediate
(
time
.
Second
,
timeout
,
func
()
(
bool
,
error
)
{
if
err
:=
wait
.
PollImmediate
(
time
.
Second
,
timeout
,
func
()
(
bool
,
error
)
{
pods
,
err
=
c
.
Core
()
.
Pods
(
ns
)
.
List
(
api
.
ListOptions
{}
)
pods
,
err
=
c
.
Core
()
.
Pods
(
ns
)
.
List
(
options
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -1177,3 +1180,111 @@ func testScaledRolloutDeployment(f *framework.Framework) {
...
@@ -1177,3 +1180,111 @@ func testScaledRolloutDeployment(f *framework.Framework) {
err
=
framework
.
WaitForDeploymentStatus
(
c
,
deployment
)
err
=
framework
.
WaitForDeploymentStatus
(
c
,
deployment
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
}
}
func
testOverlappingDeployment
(
f
*
framework
.
Framework
)
{
ns
:=
f
.
Namespace
.
Name
// TODO: remove unversionedClient when the refactoring is done. Currently some
// functions like verifyPod still expects a unversioned#Client.
c
:=
adapter
.
FromUnversionedClient
(
f
.
Client
)
deploymentName
:=
"first-deployment"
podLabels
:=
map
[
string
]
string
{
"name"
:
redisImageName
}
replicas
:=
int32
(
1
)
By
(
fmt
.
Sprintf
(
"Creating deployment %q"
,
deploymentName
))
d
:=
newDeployment
(
deploymentName
,
replicas
,
podLabels
,
redisImageName
,
redisImage
,
extensions
.
RollingUpdateDeploymentStrategyType
,
nil
)
deploy
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Create
(
d
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed creating the first deployment"
)
// Wait for it to be updated to revision 1
err
=
framework
.
WaitForDeploymentRevisionAndImage
(
c
,
ns
,
deploy
.
Name
,
"1"
,
redisImage
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"The first deployment failed to update to revision 1"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
deploymentName
=
"second-deployment"
By
(
fmt
.
Sprintf
(
"Creating deployment %q with overlapping selector"
,
deploymentName
))
d
=
newDeployment
(
deploymentName
,
replicas
,
podLabels
,
nginxImageName
,
nginxImage
,
extensions
.
RollingUpdateDeploymentStrategyType
,
nil
)
deployOverlapping
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Create
(
d
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed creating the second deployment"
)
defer
stopDeployment
(
c
,
f
.
Client
,
ns
,
deployOverlapping
.
Name
)
// Wait for overlapping annotation updated to both deployments
By
(
"Waiting for both deployments to have overlapping annotations"
)
err
=
framework
.
WaitForOverlappingAnnotationMatch
(
c
,
ns
,
deploy
.
Name
,
deployOverlapping
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed to update the first deployment's overlapping annotation"
)
err
=
framework
.
WaitForOverlappingAnnotationMatch
(
c
,
ns
,
deployOverlapping
.
Name
,
deploy
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed to update the second deployment's overlapping annotation"
)
// Only the first deployment is synced
By
(
"Checking only the first overlapping deployment is synced"
)
options
:=
api
.
ListOptions
{}
rsList
,
err
:=
c
.
Extensions
()
.
ReplicaSets
(
ns
)
.
List
(
options
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed listing all replica sets in namespace %s"
,
ns
)
Expect
(
rsList
.
Items
)
.
To
(
HaveLen
(
int
(
replicas
)))
Expect
(
rsList
.
Items
[
0
]
.
Spec
.
Template
.
Spec
.
Containers
)
.
To
(
HaveLen
(
1
))
Expect
(
rsList
.
Items
[
0
]
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
)
.
To
(
Equal
(
deploy
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
))
By
(
"Deleting the first deployment"
)
stopDeployment
(
c
,
f
.
Client
,
ns
,
deploy
.
Name
)
// Wait for overlapping annotation cleared
By
(
"Waiting for the second deployment to clear overlapping annotation"
)
err
=
framework
.
WaitForOverlappingAnnotationMatch
(
c
,
ns
,
deployOverlapping
.
Name
,
""
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed to clear the second deployment's overlapping annotation"
)
// Wait for it to be updated to revision 1
err
=
framework
.
WaitForDeploymentRevisionAndImage
(
c
,
ns
,
deployOverlapping
.
Name
,
"1"
,
nginxImage
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"The second deployment failed to update to revision 1"
)
// Now the second deployment is synced
By
(
"Checking the second overlapping deployment is synced"
)
rsList
,
err
=
c
.
Extensions
()
.
ReplicaSets
(
ns
)
.
List
(
options
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed listing all replica sets in namespace %s"
,
ns
)
Expect
(
rsList
.
Items
)
.
To
(
HaveLen
(
int
(
replicas
)))
Expect
(
rsList
.
Items
[
0
]
.
Spec
.
Template
.
Spec
.
Containers
)
.
To
(
HaveLen
(
1
))
Expect
(
rsList
.
Items
[
0
]
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
)
.
To
(
Equal
(
deployOverlapping
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
))
deploymentName
=
"third-deployment"
podLabels
=
map
[
string
]
string
{
"name"
:
nginxImageName
}
By
(
fmt
.
Sprintf
(
"Creating deployment %q"
,
deploymentName
))
d
=
newDeployment
(
deploymentName
,
replicas
,
podLabels
,
nginxImageName
,
nginxImage
,
extensions
.
RollingUpdateDeploymentStrategyType
,
nil
)
deployLater
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Create
(
d
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed creating the third deployment"
)
defer
stopDeployment
(
c
,
f
.
Client
,
ns
,
deployLater
.
Name
)
// Wait for it to be updated to revision 1
err
=
framework
.
WaitForDeploymentRevisionAndImage
(
c
,
ns
,
deployLater
.
Name
,
"1"
,
nginxImage
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"The third deployment failed to update to revision 1"
)
// Update the second deployment's selector to make it overlap with the third deployment
By
(
fmt
.
Sprintf
(
"Updating deployment %q selector to make it overlap with existing one"
,
deployOverlapping
.
Name
))
deployOverlapping
,
err
=
framework
.
UpdateDeploymentWithRetries
(
c
,
ns
,
deployOverlapping
.
Name
,
func
(
update
*
extensions
.
Deployment
)
{
update
.
Spec
.
Selector
=
deployLater
.
Spec
.
Selector
update
.
Spec
.
Template
.
Labels
=
deployLater
.
Spec
.
Template
.
Labels
update
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
redisImage
})
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// Wait for overlapping annotation updated to both deployments
By
(
"Waiting for both deployments to have overlapping annotations"
)
err
=
framework
.
WaitForOverlappingAnnotationMatch
(
c
,
ns
,
deployOverlapping
.
Name
,
deployLater
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed to update the second deployment's overlapping annotation"
)
err
=
framework
.
WaitForOverlappingAnnotationMatch
(
c
,
ns
,
deployLater
.
Name
,
deployOverlapping
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"Failed to update the third deployment's overlapping annotation"
)
// The second deployment shouldn't be synced
By
(
"Checking the second deployment is not synced"
)
Expect
(
deployOverlapping
.
Annotations
[
deploymentutil
.
RevisionAnnotation
])
.
To
(
Equal
(
"1"
))
// Update the second deployment's selector to make it not overlap with the third deployment
By
(
fmt
.
Sprintf
(
"Updating deployment %q selector to make it not overlap with existing one"
,
deployOverlapping
.
Name
))
deployOverlapping
,
err
=
framework
.
UpdateDeploymentWithRetries
(
c
,
ns
,
deployOverlapping
.
Name
,
func
(
update
*
extensions
.
Deployment
)
{
update
.
Spec
.
Selector
=
deploy
.
Spec
.
Selector
update
.
Spec
.
Template
.
Labels
=
deploy
.
Spec
.
Template
.
Labels
})
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// Wait for the second deployment to be synced
By
(
"Checking the second deployment is now synced"
)
err
=
framework
.
WaitForDeploymentRevisionAndImage
(
c
,
ns
,
deployOverlapping
.
Name
,
"2"
,
redisImage
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"The second deployment failed to update to revision 2"
)
}
test/e2e/framework/util.go
View file @
c5cef187
...
@@ -3470,6 +3470,19 @@ func WaitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName
...
@@ -3470,6 +3470,19 @@ func WaitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName
return
nil
return
nil
}
}
func
WaitForOverlappingAnnotationMatch
(
c
clientset
.
Interface
,
ns
,
deploymentName
,
expected
string
)
error
{
return
wait
.
Poll
(
Poll
,
1
*
time
.
Minute
,
func
()
(
bool
,
error
)
{
deployment
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
if
err
!=
nil
{
return
false
,
err
}
if
deployment
.
Annotations
[
deploymentutil
.
OverlapAnnotation
]
==
expected
{
return
true
,
nil
}
return
false
,
nil
})
}
// CheckNewRSAnnotations check if the new RS's annotation is as expected
// CheckNewRSAnnotations check if the new RS's annotation is as expected
func
CheckNewRSAnnotations
(
c
clientset
.
Interface
,
ns
,
deploymentName
string
,
expectedAnnotations
map
[
string
]
string
)
error
{
func
CheckNewRSAnnotations
(
c
clientset
.
Interface
,
ns
,
deploymentName
string
,
expectedAnnotations
map
[
string
]
string
)
error
{
deployment
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
deployment
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
...
...
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