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
182753f8
Commit
182753f8
authored
Mar 06, 2017
by
Anthony Yeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DaemonSet: Check that ControllerRef UID matches.
parent
97c363a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
25 deletions
+31
-25
daemoncontroller.go
pkg/controller/daemon/daemoncontroller.go
+31
-25
No files found.
pkg/controller/daemon/daemoncontroller.go
View file @
182753f8
...
@@ -284,19 +284,15 @@ func (dsc *DaemonSetsController) addPod(obj interface{}) {
...
@@ -284,19 +284,15 @@ func (dsc *DaemonSetsController) addPod(obj interface{}) {
// If it has a ControllerRef, that's all that matters.
// If it has a ControllerRef, that's all that matters.
if
controllerRef
:=
controller
.
GetControllerOf
(
pod
);
controllerRef
!=
nil
{
if
controllerRef
:=
controller
.
GetControllerOf
(
pod
);
controllerRef
!=
nil
{
if
controllerRef
.
Kind
!=
controllerKind
.
Kind
{
ds
:=
dsc
.
resolveControllerRef
(
pod
.
Namespace
,
controllerRef
)
// It's controlled by a different type of controller.
if
ds
==
nil
{
return
}
glog
.
V
(
4
)
.
Infof
(
"Pod %s added."
,
pod
.
Name
)
ds
,
err
:=
dsc
.
dsLister
.
DaemonSets
(
pod
.
Namespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
return
return
}
}
dsKey
,
err
:=
controller
.
KeyFunc
(
ds
)
dsKey
,
err
:=
controller
.
KeyFunc
(
ds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"Pod %s added."
,
pod
.
Name
)
dsc
.
expectations
.
CreationObserved
(
dsKey
)
dsc
.
expectations
.
CreationObserved
(
dsKey
)
dsc
.
enqueueDaemonSet
(
ds
)
dsc
.
enqueueDaemonSet
(
ds
)
return
return
...
@@ -333,26 +329,20 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
...
@@ -333,26 +329,20 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
curControllerRef
:=
controller
.
GetControllerOf
(
curPod
)
curControllerRef
:=
controller
.
GetControllerOf
(
curPod
)
oldControllerRef
:=
controller
.
GetControllerOf
(
oldPod
)
oldControllerRef
:=
controller
.
GetControllerOf
(
oldPod
)
controllerRefChanged
:=
!
reflect
.
DeepEqual
(
curControllerRef
,
oldControllerRef
)
controllerRefChanged
:=
!
reflect
.
DeepEqual
(
curControllerRef
,
oldControllerRef
)
if
controllerRefChanged
&&
if
controllerRefChanged
&&
oldControllerRef
!=
nil
{
oldControllerRef
!=
nil
&&
oldControllerRef
.
Kind
==
controllerKind
.
Kind
{
// The ControllerRef was changed. Sync the old controller, if any.
// The ControllerRef was changed. Sync the old controller, if any.
ds
,
err
:=
dsc
.
dsLister
.
DaemonSets
(
oldPod
.
Namespace
)
.
Get
(
oldControllerRef
.
Name
)
if
ds
:=
dsc
.
resolveControllerRef
(
oldPod
.
Namespace
,
oldControllerRef
);
ds
!=
nil
{
if
err
==
nil
{
dsc
.
enqueueDaemonSet
(
ds
)
dsc
.
enqueueDaemonSet
(
ds
)
}
}
}
}
// If it has a ControllerRef, that's all that matters.
// If it has a ControllerRef, that's all that matters.
if
curControllerRef
!=
nil
{
if
curControllerRef
!=
nil
{
if
curControllerRef
.
Kind
!=
controllerKind
.
Kind
{
ds
:=
dsc
.
resolveControllerRef
(
curPod
.
Namespace
,
curControllerRef
)
// It's controlled by a different type of controller.
if
ds
==
nil
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"Pod %s updated."
,
curPod
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"Pod %s updated."
,
curPod
.
Name
)
ds
,
err
:=
dsc
.
dsLister
.
DaemonSets
(
curPod
.
Namespace
)
.
Get
(
curControllerRef
.
Name
)
if
err
!=
nil
{
return
}
dsc
.
enqueueDaemonSet
(
ds
)
dsc
.
enqueueDaemonSet
(
ds
)
// See https://github.com/kubernetes/kubernetes/pull/38076 for more details
// See https://github.com/kubernetes/kubernetes/pull/38076 for more details
if
changedToReady
&&
ds
.
Spec
.
MinReadySeconds
>
0
{
if
changedToReady
&&
ds
.
Spec
.
MinReadySeconds
>
0
{
...
@@ -400,20 +390,15 @@ func (dsc *DaemonSetsController) deletePod(obj interface{}) {
...
@@ -400,20 +390,15 @@ func (dsc *DaemonSetsController) deletePod(obj interface{}) {
// No controller should care about orphans being deleted.
// No controller should care about orphans being deleted.
return
return
}
}
if
controllerRef
.
Kind
!=
controllerKind
.
Kind
{
ds
:=
dsc
.
resolveControllerRef
(
pod
.
Namespace
,
controllerRef
)
// It's controlled by a different type of controller.
if
ds
==
nil
{
return
}
glog
.
V
(
4
)
.
Infof
(
"Pod %s deleted."
,
pod
.
Name
)
ds
,
err
:=
dsc
.
dsLister
.
DaemonSets
(
pod
.
Namespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
return
return
}
}
dsKey
,
err
:=
controller
.
KeyFunc
(
ds
)
dsKey
,
err
:=
controller
.
KeyFunc
(
ds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"Pod %s deleted."
,
pod
.
Name
)
dsc
.
expectations
.
DeletionObserved
(
dsKey
)
dsc
.
expectations
.
DeletionObserved
(
dsKey
)
dsc
.
enqueueDaemonSet
(
ds
)
dsc
.
enqueueDaemonSet
(
ds
)
}
}
...
@@ -498,6 +483,27 @@ func (dsc *DaemonSetsController) getNodesToDaemonPods(ds *extensions.DaemonSet)
...
@@ -498,6 +483,27 @@ func (dsc *DaemonSetsController) getNodesToDaemonPods(ds *extensions.DaemonSet)
return
nodeToDaemonPods
,
nil
return
nodeToDaemonPods
,
nil
}
}
// resolveControllerRef returns the controller referenced by a ControllerRef,
// or nil if the ControllerRef could not be resolved to a matching controller
// of the corrrect Kind.
func
(
dsc
*
DaemonSetsController
)
resolveControllerRef
(
namespace
string
,
controllerRef
*
metav1
.
OwnerReference
)
*
extensions
.
DaemonSet
{
// We can't look up by UID, so look up by Name and then verify UID.
// Don't even try to look up by Name if it's the wrong Kind.
if
controllerRef
.
Kind
!=
controllerKind
.
Kind
{
return
nil
}
ds
,
err
:=
dsc
.
dsLister
.
DaemonSets
(
namespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
return
nil
}
if
ds
.
UID
!=
controllerRef
.
UID
{
// The controller we found with this Name is not the same one that the
// ControllerRef points to.
return
nil
}
return
ds
}
func
(
dsc
*
DaemonSetsController
)
manage
(
ds
*
extensions
.
DaemonSet
,
nodeToDaemonPods
map
[
string
][]
*
v1
.
Pod
)
error
{
func
(
dsc
*
DaemonSetsController
)
manage
(
ds
*
extensions
.
DaemonSet
,
nodeToDaemonPods
map
[
string
][]
*
v1
.
Pod
)
error
{
// For each node, if the node is running the daemon pod but isn't supposed to, kill the daemon
// For each node, if the node is running the daemon pod but isn't supposed to, kill the daemon
// pod. If the node is supposed to run the daemon pod, but isn't, create the daemon pod on the node.
// pod. If the node is supposed to run the daemon pod, but isn't, create the daemon pod on the node.
...
...
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