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
7899fb47
Commit
7899fb47
authored
Mar 26, 2018
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only check hash labels of non-adopted resources in integration tests
parent
fa0ce15d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
98 deletions
+26
-98
deployment_test.go
test/integration/deployment/deployment_test.go
+26
-98
No files found.
test/integration/deployment/deployment_test.go
View file @
7899fb47
...
@@ -81,6 +81,32 @@ func TestNewDeployment(t *testing.T) {
...
@@ -81,6 +81,32 @@ func TestNewDeployment(t *testing.T) {
if
newRS
.
Annotations
[
v1
.
LastAppliedConfigAnnotation
]
!=
""
{
if
newRS
.
Annotations
[
v1
.
LastAppliedConfigAnnotation
]
!=
""
{
t
.
Errorf
(
"expected new ReplicaSet last-applied annotation not copied from Deployment %s"
,
tester
.
deployment
.
Name
)
t
.
Errorf
(
"expected new ReplicaSet last-applied annotation not copied from Deployment %s"
,
tester
.
deployment
.
Name
)
}
}
// New RS should contain pod-template-hash in its selector, label, and template label
rsHash
,
err
:=
checkRSHashLabels
(
newRS
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
// All pods targeted by the deployment should contain pod-template-hash in their labels
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
tester
.
deployment
.
Spec
.
Selector
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to parse deployment %s selector: %v"
,
name
,
err
)
}
pods
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
.
Name
)
.
List
(
metav1
.
ListOptions
{
LabelSelector
:
selector
.
String
()})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to list pods of deployment %s: %v"
,
name
,
err
)
}
if
len
(
pods
.
Items
)
!=
int
(
replicas
)
{
t
.
Errorf
(
"expected %d pods, got %d pods"
,
replicas
,
len
(
pods
.
Items
))
}
podHash
,
err
:=
checkPodsHashLabel
(
pods
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
rsHash
!=
podHash
{
t
.
Errorf
(
"found mismatching pod-template-hash value: rs hash = %s whereas pod hash = %s"
,
rsHash
,
podHash
)
}
}
}
// Deployments should support roll out, roll back, and roll over
// Deployments should support roll out, roll back, and roll over
...
@@ -654,104 +680,6 @@ func checkPodsHashLabel(pods *v1.PodList) (string, error) {
...
@@ -654,104 +680,6 @@ func checkPodsHashLabel(pods *v1.PodList) (string, error) {
return
hash
,
nil
return
hash
,
nil
}
}
// Deployment should label adopted ReplicaSets and Pods.
func
TestDeploymentLabelAdopted
(
t
*
testing
.
T
)
{
s
,
closeFn
,
rm
,
dc
,
informers
,
c
:=
dcSetup
(
t
)
defer
closeFn
()
name
:=
"test-adopted-deployment"
ns
:=
framework
.
CreateTestingNamespace
(
name
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
// Start informer and controllers
stopCh
:=
make
(
chan
struct
{})
defer
close
(
stopCh
)
informers
.
Start
(
stopCh
)
go
rm
.
Run
(
5
,
stopCh
)
go
dc
.
Run
(
5
,
stopCh
)
// Create a RS to be adopted by the deployment.
rsName
:=
"test-adopted-controller"
replicas
:=
int32
(
1
)
rs
:=
newReplicaSet
(
rsName
,
ns
.
Name
,
replicas
)
_
,
err
:=
c
.
ExtensionsV1beta1
()
.
ReplicaSets
(
ns
.
Name
)
.
Create
(
rs
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create replicaset %s: %v"
,
rsName
,
err
)
}
// Mark RS pods as ready.
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
rs
.
Spec
.
Selector
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to parse replicaset %s selector: %v"
,
rsName
,
err
)
}
if
err
=
wait
.
PollImmediate
(
pollInterval
,
pollTimeout
,
func
()
(
bool
,
error
)
{
pods
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
.
Name
)
.
List
(
metav1
.
ListOptions
{
LabelSelector
:
selector
.
String
()})
if
err
!=
nil
{
return
false
,
err
}
if
len
(
pods
.
Items
)
!=
int
(
replicas
)
{
return
false
,
nil
}
for
_
,
pod
:=
range
pods
.
Items
{
if
err
=
markPodReady
(
c
,
ns
.
Name
,
&
pod
);
err
!=
nil
{
return
false
,
nil
}
}
return
true
,
nil
});
err
!=
nil
{
t
.
Fatalf
(
"failed to mark pods replicaset %s as ready: %v"
,
rsName
,
err
)
}
// Create a Deployment to adopt the old rs.
tester
:=
&
deploymentTester
{
t
:
t
,
c
:
c
,
deployment
:
newDeployment
(
name
,
ns
.
Name
,
replicas
)}
if
tester
.
deployment
,
err
=
c
.
ExtensionsV1beta1
()
.
Deployments
(
ns
.
Name
)
.
Create
(
tester
.
deployment
);
err
!=
nil
{
t
.
Fatalf
(
"failed to create deployment %s: %v"
,
tester
.
deployment
.
Name
,
err
)
}
// Wait for the Deployment to be updated to revision 1
if
err
=
tester
.
waitForDeploymentRevisionAndImage
(
"1"
,
fakeImage
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// The RS and pods should be relabeled after the Deployment finishes adopting it and completes.
if
err
:=
tester
.
waitForDeploymentComplete
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// There should be no old RSes (overlapping RS)
oldRSs
,
allOldRSs
,
newRS
,
err
:=
deploymentutil
.
GetAllReplicaSets
(
tester
.
deployment
,
c
.
ExtensionsV1beta1
())
if
err
!=
nil
{
t
.
Fatalf
(
"failed to get all replicasets owned by deployment %s: %v"
,
name
,
err
)
}
if
len
(
oldRSs
)
!=
0
||
len
(
allOldRSs
)
!=
0
{
t
.
Errorf
(
"expected deployment to have no old replicasets, got %d old replicasets"
,
len
(
allOldRSs
))
}
// New RS should be relabeled, i.e. contain pod-template-hash in its selector, label, and template label
rsHash
,
err
:=
checkRSHashLabels
(
newRS
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
// All pods targeted by the deployment should contain pod-template-hash in their labels, and there should be only 3 pods
selector
,
err
=
metav1
.
LabelSelectorAsSelector
(
tester
.
deployment
.
Spec
.
Selector
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to parse deployment %s selector: %v"
,
name
,
err
)
}
pods
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
.
Name
)
.
List
(
metav1
.
ListOptions
{
LabelSelector
:
selector
.
String
()})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to list pods of deployment %s: %v"
,
name
,
err
)
}
if
len
(
pods
.
Items
)
!=
int
(
replicas
)
{
t
.
Errorf
(
"expected %d pods, got %d pods"
,
replicas
,
len
(
pods
.
Items
))
}
podHash
,
err
:=
checkPodsHashLabel
(
pods
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
rsHash
!=
podHash
{
t
.
Errorf
(
"found mismatching pod-template-hash value: rs hash = %s whereas pod hash = %s"
,
rsHash
,
podHash
)
}
}
// Deployment should have a timeout condition when it fails to progress after given deadline.
// Deployment should have a timeout condition when it fails to progress after given deadline.
func
TestFailedDeployment
(
t
*
testing
.
T
)
{
func
TestFailedDeployment
(
t
*
testing
.
T
)
{
s
,
closeFn
,
rm
,
dc
,
informers
,
c
:=
dcSetup
(
t
)
s
,
closeFn
,
rm
,
dc
,
informers
,
c
:=
dcSetup
(
t
)
...
...
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