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
d1292a73
Commit
d1292a73
authored
Dec 27, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize memory allocations in controller manager
parent
6fd22784
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
10 deletions
+20
-10
controller_ref_manager.go
pkg/controller/controller_ref_manager.go
+6
-5
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+1
-1
system_utils.go
pkg/util/system/system_utils.go
+12
-3
garbage_collector.go
test/e2e/garbage_collector.go
+1
-1
No files found.
pkg/controller/controller_ref_manager.go
View file @
d1292a73
...
@@ -66,7 +66,7 @@ func (m *PodControllerRefManager) Classify(pods []*v1.Pod) (
...
@@ -66,7 +66,7 @@ func (m *PodControllerRefManager) Classify(pods []*v1.Pod) (
pod
.
Namespace
,
pod
.
Name
,
pod
.
Status
.
Phase
,
pod
.
DeletionTimestamp
)
pod
.
Namespace
,
pod
.
Name
,
pod
.
Status
.
Phase
,
pod
.
DeletionTimestamp
)
continue
continue
}
}
controllerRef
:=
GetControllerOf
(
pod
.
ObjectMeta
)
controllerRef
:=
GetControllerOf
(
&
pod
.
ObjectMeta
)
if
controllerRef
!=
nil
{
if
controllerRef
!=
nil
{
if
controllerRef
.
UID
==
m
.
controllerObject
.
UID
{
if
controllerRef
.
UID
==
m
.
controllerObject
.
UID
{
// already controlled
// already controlled
...
@@ -93,11 +93,12 @@ func (m *PodControllerRefManager) Classify(pods []*v1.Pod) (
...
@@ -93,11 +93,12 @@ func (m *PodControllerRefManager) Classify(pods []*v1.Pod) (
// GetControllerOf returns the controllerRef if controllee has a controller,
// GetControllerOf returns the controllerRef if controllee has a controller,
// otherwise returns nil.
// otherwise returns nil.
func
GetControllerOf
(
controllee
v1
.
ObjectMeta
)
*
metav1
.
OwnerReference
{
func
GetControllerOf
(
controllee
*
v1
.
ObjectMeta
)
*
metav1
.
OwnerReference
{
for
_
,
owner
:=
range
controllee
.
OwnerReferences
{
for
i
:=
range
controllee
.
OwnerReferences
{
owner
:=
&
controllee
.
OwnerReferences
[
i
]
// controlled by other controller
// controlled by other controller
if
owner
.
Controller
!=
nil
&&
*
owner
.
Controller
==
true
{
if
owner
.
Controller
!=
nil
&&
*
owner
.
Controller
==
true
{
return
&
owner
return
owner
}
}
}
}
return
nil
return
nil
...
@@ -183,7 +184,7 @@ func (m *ReplicaSetControllerRefManager) Classify(replicaSets []*extensions.Repl
...
@@ -183,7 +184,7 @@ func (m *ReplicaSetControllerRefManager) Classify(replicaSets []*extensions.Repl
controlledDoesNotMatch
[]
*
extensions
.
ReplicaSet
)
{
controlledDoesNotMatch
[]
*
extensions
.
ReplicaSet
)
{
for
i
:=
range
replicaSets
{
for
i
:=
range
replicaSets
{
replicaSet
:=
replicaSets
[
i
]
replicaSet
:=
replicaSets
[
i
]
controllerRef
:=
GetControllerOf
(
replicaSet
.
ObjectMeta
)
controllerRef
:=
GetControllerOf
(
&
replicaSet
.
ObjectMeta
)
if
controllerRef
!=
nil
{
if
controllerRef
!=
nil
{
if
controllerRef
.
UID
!=
m
.
controllerObject
.
UID
{
if
controllerRef
.
UID
!=
m
.
controllerObject
.
UID
{
// ignoring the ReplicaSet controlled by other Deployment
// ignoring the ReplicaSet controlled by other Deployment
...
...
pkg/controller/deployment/deployment_controller.go
View file @
d1292a73
...
@@ -372,7 +372,7 @@ func (dc *DeploymentController) getDeploymentForPod(pod *v1.Pod) *extensions.Dep
...
@@ -372,7 +372,7 @@ func (dc *DeploymentController) getDeploymentForPod(pod *v1.Pod) *extensions.Dep
var
rs
*
extensions
.
ReplicaSet
var
rs
*
extensions
.
ReplicaSet
var
err
error
var
err
error
// Look at the owner reference
// Look at the owner reference
controllerRef
:=
controller
.
GetControllerOf
(
pod
.
ObjectMeta
)
controllerRef
:=
controller
.
GetControllerOf
(
&
pod
.
ObjectMeta
)
if
controllerRef
!=
nil
{
if
controllerRef
!=
nil
{
// Not a pod owned by a replica set.
// Not a pod owned by a replica set.
if
controllerRef
.
Kind
!=
extensions
.
SchemeGroupVersion
.
WithKind
(
"ReplicaSet"
)
.
Kind
{
if
controllerRef
.
Kind
!=
extensions
.
SchemeGroupVersion
.
WithKind
(
"ReplicaSet"
)
.
Kind
{
...
...
pkg/util/system/system_utils.go
View file @
d1292a73
...
@@ -17,11 +17,20 @@ limitations under the License.
...
@@ -17,11 +17,20 @@ limitations under the License.
package
system
package
system
import
(
import
(
"
regexp
"
"
strings
"
)
)
// TODO: find a better way of figuring out if given node is a registered master.
// TODO: find a better way of figuring out if given node is a registered master.
func
IsMasterNode
(
nodeName
string
)
bool
{
func
IsMasterNode
(
nodeName
string
)
bool
{
r
:=
regexp
.
MustCompile
(
"master(-...)?$"
)
// We are trying to capture "master(-...)?$" regexp.
return
r
.
MatchString
(
nodeName
)
// However, using regexp.MatchString() results even in more than 35%
// of all space allocations in ControllerManager spent in this function.
// That's why we are trying to be a bit smarter.
if
strings
.
HasSuffix
(
nodeName
,
"master"
)
{
return
true
}
if
len
(
nodeName
)
>=
10
{
return
strings
.
HasSuffix
(
nodeName
[
:
len
(
nodeName
)
-
3
],
"master-"
)
}
return
false
}
}
test/e2e/garbage_collector.go
View file @
d1292a73
...
@@ -433,7 +433,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() {
...
@@ -433,7 +433,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() {
framework
.
Failf
(
"Failed to list ReplicaSet %v"
,
err
)
framework
.
Failf
(
"Failed to list ReplicaSet %v"
,
err
)
}
}
for
_
,
replicaSet
:=
range
rs
.
Items
{
for
_
,
replicaSet
:=
range
rs
.
Items
{
if
controller
.
GetControllerOf
(
replicaSet
.
ObjectMeta
)
!=
nil
{
if
controller
.
GetControllerOf
(
&
replicaSet
.
ObjectMeta
)
!=
nil
{
framework
.
Failf
(
"Found ReplicaSet with non nil ownerRef %v"
,
replicaSet
)
framework
.
Failf
(
"Found ReplicaSet with non nil ownerRef %v"
,
replicaSet
)
}
}
}
}
...
...
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