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
2d1490a0
Commit
2d1490a0
authored
Aug 03, 2016
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the map concurrent read/write issue in deployment controller
parent
2301ab7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
19 deletions
+47
-19
deployment_util.go
pkg/controller/deployment/util/deployment_util.go
+15
-6
deployment_util_test.go
pkg/controller/deployment/util/deployment_util_test.go
+32
-13
No files found.
pkg/controller/deployment/util/deployment_util.go
View file @
2d1490a0
...
@@ -402,17 +402,26 @@ func ListPods(deployment *extensions.Deployment, getPodList podListFunc) (*api.P
...
@@ -402,17 +402,26 @@ func ListPods(deployment *extensions.Deployment, getPodList podListFunc) (*api.P
// (e.g. the addition of a new field will cause the hash code to change)
// (e.g. the addition of a new field will cause the hash code to change)
// Note that we assume input podTemplateSpecs contain non-empty labels
// Note that we assume input podTemplateSpecs contain non-empty labels
func
equalIgnoreHash
(
template1
,
template2
api
.
PodTemplateSpec
)
(
bool
,
error
)
{
func
equalIgnoreHash
(
template1
,
template2
api
.
PodTemplateSpec
)
(
bool
,
error
)
{
// First, compare template.Labels (ignoring hash)
labels1
,
labels2
:=
template1
.
Labels
,
template2
.
Labels
// The podTemplateSpec must have a non-empty label so that label selectors can find them.
// The podTemplateSpec must have a non-empty label so that label selectors can find them.
// This is checked by validation (of resources contain a podTemplateSpec).
// This is checked by validation (of resources contain a podTemplateSpec).
if
len
(
template1
.
Labels
)
==
0
||
len
(
template2
.
Labels
)
==
0
{
if
len
(
labels1
)
==
0
||
len
(
labels2
)
==
0
{
return
false
,
fmt
.
Errorf
(
"Unexpected empty labels found in given template"
)
return
false
,
fmt
.
Errorf
(
"Unexpected empty labels found in given template"
)
}
}
hash1
:=
template1
.
Labels
[
extensions
.
DefaultDeploymentUniqueLabelKey
]
if
len
(
labels1
)
>
len
(
labels2
)
{
hash2
:=
template2
.
Labels
[
extensions
.
DefaultDeploymentUniqueLabelKey
]
labels1
,
labels2
=
labels2
,
labels1
// compare equality ignoring pod-template-hash
}
template1
.
Labels
[
extensions
.
DefaultDeploymentUniqueLabelKey
]
=
hash2
// We make sure len(labels2) >= len(labels1)
for
k
,
v
:=
range
labels2
{
if
labels1
[
k
]
!=
v
&&
k
!=
extensions
.
DefaultDeploymentUniqueLabelKey
{
return
false
,
nil
}
}
// Then, compare the templates without comparing their labels
template1
.
Labels
,
template2
.
Labels
=
nil
,
nil
result
:=
api
.
Semantic
.
DeepEqual
(
template1
,
template2
)
result
:=
api
.
Semantic
.
DeepEqual
(
template1
,
template2
)
template1
.
Labels
[
extensions
.
DefaultDeploymentUniqueLabelKey
]
=
hash1
return
result
,
nil
return
result
,
nil
}
}
...
...
pkg/controller/deployment/util/deployment_util_test.go
View file @
2d1490a0
...
@@ -464,20 +464,39 @@ func TestEqualIgnoreHash(t *testing.T) {
...
@@ -464,20 +464,39 @@ func TestEqualIgnoreHash(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
equal
,
err
:=
equalIgnoreHash
(
test
.
former
,
test
.
latter
)
runTest
:=
func
(
t1
,
t2
api
.
PodTemplateSpec
,
reversed
bool
)
{
if
err
!=
nil
{
// Set up
t
.
Errorf
(
"In test case %q, returned unexpected error %v"
,
test
.
test
,
err
)
t1Copy
,
err
:=
api
.
Scheme
.
DeepCopy
(
t1
)
}
if
err
!=
nil
{
if
equal
!=
test
.
expected
{
t
.
Errorf
(
"Failed setting up the test: %v"
,
err
)
t
.
Errorf
(
"In test case %q, expected %v"
,
test
.
test
,
test
.
expected
)
}
}
t2Copy
,
err
:=
api
.
Scheme
.
DeepCopy
(
t2
)
equal
,
err
=
equalIgnoreHash
(
test
.
latter
,
test
.
former
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed setting up the test: %v"
,
err
)
t
.
Errorf
(
"In test case %q (reverse order), returned unexpected error %v"
,
test
.
test
,
err
)
}
}
reverseString
:=
""
if
equal
!=
test
.
expected
{
if
reversed
{
t
.
Errorf
(
"In test case %q (reverse order), expected %v"
,
test
.
test
,
test
.
expected
)
reverseString
=
" (reverse order)"
}
// Run
equal
,
err
:=
equalIgnoreHash
(
t1
,
t2
)
// Check
if
err
!=
nil
{
t
.
Errorf
(
"In test case %q%s, expected no error, returned %v"
,
test
.
test
,
reverseString
,
err
)
}
if
equal
!=
test
.
expected
{
t
.
Errorf
(
"In test case %q%s, expected %v"
,
test
.
test
,
reverseString
,
test
.
expected
)
}
if
t1
.
Labels
==
nil
||
t2
.
Labels
==
nil
{
t
.
Errorf
(
"In test case %q%s, unexpected labels becomes nil"
,
test
.
test
,
reverseString
)
}
if
!
reflect
.
DeepEqual
(
t1
,
t1Copy
)
||
!
reflect
.
DeepEqual
(
t2
,
t2Copy
)
{
t
.
Errorf
(
"In test case %q%s, unexpected input template modified"
,
test
.
test
,
reverseString
)
}
}
}
runTest
(
test
.
former
,
test
.
latter
,
false
)
// Test the same case in reverse order
runTest
(
test
.
latter
,
test
.
former
,
true
)
}
}
}
}
...
...
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