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
f2a2895a
Commit
f2a2895a
authored
Mar 06, 2017
by
Anthony Yeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deployment: Check that ControllerRef UID matches.
parent
111b9ce9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
25 deletions
+24
-25
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+24
-25
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
f2a2895a
...
@@ -203,15 +203,11 @@ func (dc *DeploymentController) addReplicaSet(obj interface{}) {
...
@@ -203,15 +203,11 @@ func (dc *DeploymentController) addReplicaSet(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
(
rs
);
controllerRef
!=
nil
{
if
controllerRef
:=
controller
.
GetControllerOf
(
rs
);
controllerRef
!=
nil
{
if
controllerRef
.
Kind
!=
controllerKind
.
Kind
{
d
:=
dc
.
resolveControllerRef
(
rs
.
Namespace
,
controllerRef
)
// It's controller by a different type of controller.
if
d
==
nil
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"ReplicaSet %s added."
,
rs
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"ReplicaSet %s added."
,
rs
.
Name
)
d
,
err
:=
dc
.
dLister
.
Deployments
(
rs
.
Namespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
return
}
dc
.
enqueueDeployment
(
d
)
dc
.
enqueueDeployment
(
d
)
return
return
}
}
...
@@ -264,26 +260,20 @@ func (dc *DeploymentController) updateReplicaSet(old, cur interface{}) {
...
@@ -264,26 +260,20 @@ func (dc *DeploymentController) updateReplicaSet(old, cur interface{}) {
curControllerRef
:=
controller
.
GetControllerOf
(
curRS
)
curControllerRef
:=
controller
.
GetControllerOf
(
curRS
)
oldControllerRef
:=
controller
.
GetControllerOf
(
oldRS
)
oldControllerRef
:=
controller
.
GetControllerOf
(
oldRS
)
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.
d
,
err
:=
dc
.
dLister
.
Deployments
(
oldRS
.
Namespace
)
.
Get
(
oldControllerRef
.
Name
)
if
d
:=
dc
.
resolveControllerRef
(
oldRS
.
Namespace
,
oldControllerRef
);
d
!=
nil
{
if
err
==
nil
{
dc
.
enqueueDeployment
(
d
)
dc
.
enqueueDeployment
(
d
)
}
}
}
}
// 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
{
d
:=
dc
.
resolveControllerRef
(
curRS
.
Namespace
,
curControllerRef
)
// It's controlled by a different type of controller.
if
d
==
nil
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"ReplicaSet %s updated."
,
curRS
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"ReplicaSet %s updated."
,
curRS
.
Name
)
d
,
err
:=
dc
.
dLister
.
Deployments
(
curRS
.
Namespace
)
.
Get
(
curControllerRef
.
Name
)
if
err
!=
nil
{
return
}
dc
.
enqueueDeployment
(
d
)
dc
.
enqueueDeployment
(
d
)
return
return
}
}
...
@@ -331,16 +321,11 @@ func (dc *DeploymentController) deleteReplicaSet(obj interface{}) {
...
@@ -331,16 +321,11 @@ func (dc *DeploymentController) deleteReplicaSet(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
{
d
:=
dc
.
resolveControllerRef
(
rs
.
Namespace
,
controllerRef
)
// It's controlled by a different type of controller.
if
d
==
nil
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"ReplicaSet %s deleted."
,
rs
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"ReplicaSet %s deleted."
,
rs
.
Name
)
d
,
err
:=
dc
.
dLister
.
Deployments
(
rs
.
Namespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
return
}
dc
.
enqueueDeployment
(
d
)
dc
.
enqueueDeployment
(
d
)
}
}
...
@@ -431,7 +416,7 @@ func (dc *DeploymentController) getDeploymentForPod(pod *v1.Pod) *extensions.Dep
...
@@ -431,7 +416,7 @@ func (dc *DeploymentController) getDeploymentForPod(pod *v1.Pod) *extensions.Dep
return
nil
return
nil
}
}
rs
,
err
=
dc
.
rsLister
.
ReplicaSets
(
pod
.
Namespace
)
.
Get
(
controllerRef
.
Name
)
rs
,
err
=
dc
.
rsLister
.
ReplicaSets
(
pod
.
Namespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
if
err
!=
nil
||
rs
.
UID
!=
controllerRef
.
UID
{
glog
.
V
(
4
)
.
Infof
(
"Cannot get replicaset %q for pod %q: %v"
,
controllerRef
.
Name
,
pod
.
Name
,
err
)
glog
.
V
(
4
)
.
Infof
(
"Cannot get replicaset %q for pod %q: %v"
,
controllerRef
.
Name
,
pod
.
Name
,
err
)
return
nil
return
nil
}
}
...
@@ -441,13 +426,27 @@ func (dc *DeploymentController) getDeploymentForPod(pod *v1.Pod) *extensions.Dep
...
@@ -441,13 +426,27 @@ func (dc *DeploymentController) getDeploymentForPod(pod *v1.Pod) *extensions.Dep
if
controllerRef
==
nil
{
if
controllerRef
==
nil
{
return
nil
return
nil
}
}
return
dc
.
resolveControllerRef
(
rs
.
Namespace
,
controllerRef
)
}
// 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
(
dc
*
DeploymentController
)
resolveControllerRef
(
namespace
string
,
controllerRef
*
metav1
.
OwnerReference
)
*
extensions
.
Deployment
{
// 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
{
if
controllerRef
.
Kind
!=
controllerKind
.
Kind
{
return
nil
return
nil
}
}
d
,
err
:=
dc
.
dLister
.
Deployments
(
rs
.
N
amespace
)
.
Get
(
controllerRef
.
Name
)
d
,
err
:=
dc
.
dLister
.
Deployments
(
n
amespace
)
.
Get
(
controllerRef
.
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
nil
}
}
if
d
.
UID
!=
controllerRef
.
UID
{
// The controller we found with this Name is not the same one that the
// ControllerRef points to.
return
nil
}
return
d
return
d
}
}
...
...
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