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
552e4d3a
Commit
552e4d3a
authored
Oct 18, 2017
by
Szymon Scharmach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cpu manager reconclie loop can restore state
parent
02a7c12c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
cpu_manager.go
pkg/kubelet/cm/cpumanager/cpu_manager.go
+21
-2
policy.go
pkg/kubelet/cm/cpumanager/policy.go
+2
-0
policy_static.go
pkg/kubelet/cm/cpumanager/policy_static.go
+7
-1
No files found.
pkg/kubelet/cm/cpumanager/cpu_manager.go
View file @
552e4d3a
...
@@ -160,8 +160,8 @@ func NewManager(
...
@@ -160,8 +160,8 @@ func NewManager(
}
}
func
(
m
*
manager
)
Start
(
activePods
ActivePodsFunc
,
podStatusProvider
status
.
PodStatusProvider
,
containerRuntime
runtimeService
)
{
func
(
m
*
manager
)
Start
(
activePods
ActivePodsFunc
,
podStatusProvider
status
.
PodStatusProvider
,
containerRuntime
runtimeService
)
{
glog
.
Infof
(
"[cpumanger] starting with %s policy"
,
m
.
policy
.
Name
())
glog
.
Infof
(
"[cpuman
a
ger] starting with %s policy"
,
m
.
policy
.
Name
())
glog
.
Infof
(
"[cpumanger] reconciling every %v"
,
m
.
reconcilePeriod
)
glog
.
Infof
(
"[cpuman
a
ger] reconciling every %v"
,
m
.
reconcilePeriod
)
m
.
activePods
=
activePods
m
.
activePods
=
activePods
m
.
podStatusProvider
=
podStatusProvider
m
.
podStatusProvider
=
podStatusProvider
...
@@ -242,6 +242,25 @@ func (m *manager) reconcileState() (success []reconciledContainer, failure []rec
...
@@ -242,6 +242,25 @@ func (m *manager) reconcileState() (success []reconciledContainer, failure []rec
continue
continue
}
}
// Check whether container is present in state, there may be 3 reasons why it's not present:
// - policy does not want to track the container
// - kubelet has just been restarted - and there is no previous state file
// - container has been removed from state by RemoveContainer call (DeletionTimestamp is set)
if
_
,
ok
:=
m
.
state
.
GetCPUSet
(
containerID
);
!
ok
{
if
status
.
Phase
==
v1
.
PodRunning
&&
pod
.
DeletionTimestamp
==
nil
{
glog
.
V
(
4
)
.
Infof
(
"[cpumanager] reconcileState: container is not present in state - trying to add (pod: %s, container: %s, container id: %s)"
,
pod
.
Name
,
container
.
Name
,
containerID
)
err
:=
m
.
AddContainer
(
pod
,
&
container
,
containerID
)
if
err
!=
nil
{
glog
.
Errorf
(
"[cpumanager] reconcileState: failed to add container (pod: %s, container: %s, container id: %s, error: %v)"
,
pod
.
Name
,
container
.
Name
,
containerID
,
err
)
failure
=
append
(
failure
,
reconciledContainer
{
pod
.
Name
,
container
.
Name
,
containerID
})
}
}
else
{
// if DeletionTimestamp is set, pod has already been removed from state
// skip the pod/container since it's not running and will be deleted soon
continue
}
}
cset
:=
m
.
state
.
GetCPUSetOrDefault
(
containerID
)
cset
:=
m
.
state
.
GetCPUSetOrDefault
(
containerID
)
if
cset
.
IsEmpty
()
{
if
cset
.
IsEmpty
()
{
// NOTE: This should not happen outside of tests.
// NOTE: This should not happen outside of tests.
...
...
pkg/kubelet/cm/cpumanager/policy.go
View file @
552e4d3a
...
@@ -25,6 +25,8 @@ import (
...
@@ -25,6 +25,8 @@ import (
type
Policy
interface
{
type
Policy
interface
{
Name
()
string
Name
()
string
Start
(
s
state
.
State
)
Start
(
s
state
.
State
)
// AddContainer call is idempotent
AddContainer
(
s
state
.
State
,
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
containerID
string
)
error
AddContainer
(
s
state
.
State
,
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
containerID
string
)
error
// RemoveContainer call is idempotent
RemoveContainer
(
s
state
.
State
,
containerID
string
)
error
RemoveContainer
(
s
state
.
State
,
containerID
string
)
error
}
}
pkg/kubelet/cm/cpumanager/policy_static.go
View file @
552e4d3a
...
@@ -156,9 +156,15 @@ func (p *staticPolicy) assignableCPUs(s state.State) cpuset.CPUSet {
...
@@ -156,9 +156,15 @@ func (p *staticPolicy) assignableCPUs(s state.State) cpuset.CPUSet {
}
}
func
(
p
*
staticPolicy
)
AddContainer
(
s
state
.
State
,
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
containerID
string
)
error
{
func
(
p
*
staticPolicy
)
AddContainer
(
s
state
.
State
,
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
containerID
string
)
error
{
glog
.
Infof
(
"[cpumanager] static policy: AddContainer (pod: %s, container: %s, container id: %s)"
,
pod
.
Name
,
container
.
Name
,
containerID
)
if
numCPUs
:=
guaranteedCPUs
(
pod
,
container
);
numCPUs
!=
0
{
if
numCPUs
:=
guaranteedCPUs
(
pod
,
container
);
numCPUs
!=
0
{
glog
.
Infof
(
"[cpumanager] static policy: AddContainer (pod: %s, container: %s, container id: %s)"
,
pod
.
Name
,
container
.
Name
,
containerID
)
// container belongs in an exclusively allocated pool
// container belongs in an exclusively allocated pool
if
_
,
ok
:=
s
.
GetCPUSet
(
containerID
);
ok
{
glog
.
Infof
(
"[cpumanager] static policy: container already present in state, skipping (container: %s, container id: %s)"
,
container
.
Name
,
containerID
)
return
nil
}
cpuset
,
err
:=
p
.
allocateCPUs
(
s
,
numCPUs
)
cpuset
,
err
:=
p
.
allocateCPUs
(
s
,
numCPUs
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"[cpumanager] unable to allocate %d CPUs (container id: %s, error: %v)"
,
numCPUs
,
containerID
,
err
)
glog
.
Errorf
(
"[cpumanager] unable to allocate %d CPUs (container id: %s, error: %v)"
,
numCPUs
,
containerID
,
err
)
...
...
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