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
5dbb8e0d
Commit
5dbb8e0d
authored
Mar 02, 2017
by
Łukasz Oleś
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enque DaemonSet sync when node taints changed
Fixes #42398
parent
fc31dae1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
3 deletions
+71
-3
daemoncontroller.go
pkg/controller/daemon/daemoncontroller.go
+6
-3
daemoncontroller_test.go
pkg/controller/daemon/daemoncontroller_test.go
+65
-0
No files found.
pkg/controller/daemon/daemoncontroller.go
View file @
5dbb8e0d
...
@@ -85,6 +85,8 @@ type DaemonSetsController struct {
...
@@ -85,6 +85,8 @@ type DaemonSetsController struct {
// To allow injection of syncDaemonSet for testing.
// To allow injection of syncDaemonSet for testing.
syncHandler
func
(
dsKey
string
)
error
syncHandler
func
(
dsKey
string
)
error
// used for unit testing
enqueueDaemonSet
func
(
ds
*
extensions
.
DaemonSet
)
// A TTLCache of pod creates/deletes each ds expects to see
// A TTLCache of pod creates/deletes each ds expects to see
expectations
controller
.
ControllerExpectationsInterface
expectations
controller
.
ControllerExpectationsInterface
// dsLister can list/get daemonsets from the shared informer's store
// dsLister can list/get daemonsets from the shared informer's store
...
@@ -181,6 +183,7 @@ func NewDaemonSetsController(daemonSetInformer extensionsinformers.DaemonSetInfo
...
@@ -181,6 +183,7 @@ func NewDaemonSetsController(daemonSetInformer extensionsinformers.DaemonSetInfo
dsc
.
nodeLister
=
nodeInformer
.
Lister
()
dsc
.
nodeLister
=
nodeInformer
.
Lister
()
dsc
.
syncHandler
=
dsc
.
syncDaemonSet
dsc
.
syncHandler
=
dsc
.
syncDaemonSet
dsc
.
enqueueDaemonSet
=
dsc
.
enqueue
dsc
.
lookupCache
=
controller
.
NewMatchingCache
(
lookupCacheSize
)
dsc
.
lookupCache
=
controller
.
NewMatchingCache
(
lookupCacheSize
)
return
dsc
return
dsc
}
}
...
@@ -248,7 +251,7 @@ func (dsc *DaemonSetsController) processNextWorkItem() bool {
...
@@ -248,7 +251,7 @@ func (dsc *DaemonSetsController) processNextWorkItem() bool {
return
true
return
true
}
}
func
(
dsc
*
DaemonSetsController
)
enqueue
DaemonSet
(
ds
*
extensions
.
DaemonSet
)
{
func
(
dsc
*
DaemonSetsController
)
enqueue
(
ds
*
extensions
.
DaemonSet
)
{
key
,
err
:=
controller
.
KeyFunc
(
ds
)
key
,
err
:=
controller
.
KeyFunc
(
ds
)
if
err
!=
nil
{
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Couldn't get key for object %#v: %v"
,
ds
,
err
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Couldn't get key for object %#v: %v"
,
ds
,
err
))
...
@@ -432,8 +435,8 @@ func (dsc *DaemonSetsController) addNode(obj interface{}) {
...
@@ -432,8 +435,8 @@ func (dsc *DaemonSetsController) addNode(obj interface{}) {
func
(
dsc
*
DaemonSetsController
)
updateNode
(
old
,
cur
interface
{})
{
func
(
dsc
*
DaemonSetsController
)
updateNode
(
old
,
cur
interface
{})
{
oldNode
:=
old
.
(
*
v1
.
Node
)
oldNode
:=
old
.
(
*
v1
.
Node
)
curNode
:=
cur
.
(
*
v1
.
Node
)
curNode
:=
cur
.
(
*
v1
.
Node
)
if
reflect
.
DeepEqual
(
oldNode
.
Labels
,
curNode
.
Labels
)
{
if
reflect
.
DeepEqual
(
oldNode
.
Labels
,
curNode
.
Labels
)
&&
reflect
.
DeepEqual
(
oldNode
.
Spec
.
Taints
,
curNode
.
Spec
.
Taints
)
{
// If node labels didn't change, we can ignore this update.
// If node labels
and taints
didn't change, we can ignore this update.
return
return
}
}
dsList
,
err
:=
dsc
.
dsLister
.
List
(
labels
.
Everything
())
dsList
,
err
:=
dsc
.
dsLister
.
List
(
labels
.
Everything
())
...
...
pkg/controller/daemon/daemoncontroller_test.go
View file @
5dbb8e0d
...
@@ -1086,3 +1086,68 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
...
@@ -1086,3 +1086,68 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
}
}
}
}
}
}
// DaemonSets should be resynced when node labels or taints changed
func
TestUpdateNode
(
t
*
testing
.
T
)
{
var
enqueued
bool
cases
:=
[]
struct
{
test
string
newNode
*
v1
.
Node
oldNode
*
v1
.
Node
ds
*
extensions
.
DaemonSet
shouldEnqueue
bool
}{
{
test
:
"Nothing changed, should not enqueue"
,
oldNode
:
newNode
(
"node1"
,
nil
),
newNode
:
newNode
(
"node1"
,
nil
),
ds
:
func
()
*
extensions
.
DaemonSet
{
ds
:=
newDaemonSet
(
"ds"
)
ds
.
Spec
.
Template
.
Spec
.
NodeSelector
=
simpleNodeLabel
return
ds
}(),
shouldEnqueue
:
false
,
},
{
test
:
"Node labels changed"
,
oldNode
:
newNode
(
"node1"
,
nil
),
newNode
:
newNode
(
"node1"
,
simpleNodeLabel
),
ds
:
func
()
*
extensions
.
DaemonSet
{
ds
:=
newDaemonSet
(
"ds"
)
ds
.
Spec
.
Template
.
Spec
.
NodeSelector
=
simpleNodeLabel
return
ds
}(),
shouldEnqueue
:
true
,
},
{
test
:
"Node taints changed"
,
oldNode
:
func
()
*
v1
.
Node
{
node
:=
newNode
(
"node1"
,
nil
)
setNodeTaint
(
node
,
noScheduleTaints
)
return
node
}(),
newNode
:
newNode
(
"node1"
,
nil
),
ds
:
newDaemonSet
(
"ds"
),
shouldEnqueue
:
true
,
},
}
for
_
,
c
:=
range
cases
{
manager
,
podControl
,
_
:=
newTestController
()
manager
.
nodeStore
.
Add
(
c
.
oldNode
)
manager
.
dsStore
.
Add
(
c
.
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
c
.
ds
,
podControl
,
0
,
0
)
manager
.
enqueueDaemonSet
=
func
(
ds
*
extensions
.
DaemonSet
)
{
if
ds
.
Name
==
"ds"
{
enqueued
=
true
}
}
enqueued
=
false
manager
.
updateNode
(
c
.
oldNode
,
c
.
newNode
)
if
enqueued
!=
c
.
shouldEnqueue
{
t
.
Errorf
(
"Test case: '%s', expected: %t, got: %t"
,
c
.
test
,
c
.
shouldEnqueue
,
enqueued
)
}
}
}
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