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
7e7301ff
Commit
7e7301ff
authored
Oct 17, 2017
by
Szymon Scharmach
Committed by
Szymon Scharmach
Nov 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable file state in static policy
parent
21062657
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
6 deletions
+63
-6
server.go
cmd/kubelet/app/server.go
+1
-0
container_manager.go
pkg/kubelet/cm/container_manager.go
+1
-0
container_manager_linux.go
pkg/kubelet/cm/container_manager_linux.go
+1
-0
cpu_manager.go
pkg/kubelet/cm/cpumanager/cpu_manager.go
+10
-1
policy_static.go
pkg/kubelet/cm/cpumanager/policy_static.go
+39
-3
state_file.go
pkg/kubelet/cm/cpumanager/state/state_file.go
+11
-2
No files found.
cmd/kubelet/app/server.go
View file @
7e7301ff
...
@@ -462,6 +462,7 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies) (err error) {
...
@@ -462,6 +462,7 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies) (err error) {
CgroupsPerQOS
:
s
.
CgroupsPerQOS
,
CgroupsPerQOS
:
s
.
CgroupsPerQOS
,
CgroupRoot
:
s
.
CgroupRoot
,
CgroupRoot
:
s
.
CgroupRoot
,
CgroupDriver
:
s
.
CgroupDriver
,
CgroupDriver
:
s
.
CgroupDriver
,
KubeletRootDir
:
s
.
RootDirectory
,
ProtectKernelDefaults
:
s
.
ProtectKernelDefaults
,
ProtectKernelDefaults
:
s
.
ProtectKernelDefaults
,
NodeAllocatableConfig
:
cm
.
NodeAllocatableConfig
{
NodeAllocatableConfig
:
cm
.
NodeAllocatableConfig
{
KubeReservedCgroupName
:
s
.
KubeReservedCgroup
,
KubeReservedCgroupName
:
s
.
KubeReservedCgroup
,
...
...
pkg/kubelet/cm/container_manager.go
View file @
7e7301ff
...
@@ -96,6 +96,7 @@ type NodeConfig struct {
...
@@ -96,6 +96,7 @@ type NodeConfig struct {
CgroupsPerQOS
bool
CgroupsPerQOS
bool
CgroupRoot
string
CgroupRoot
string
CgroupDriver
string
CgroupDriver
string
KubeletRootDir
string
ProtectKernelDefaults
bool
ProtectKernelDefaults
bool
NodeAllocatableConfig
NodeAllocatableConfig
ExperimentalQOSReserved
map
[
v1
.
ResourceName
]
int64
ExperimentalQOSReserved
map
[
v1
.
ResourceName
]
int64
...
...
pkg/kubelet/cm/container_manager_linux.go
View file @
7e7301ff
...
@@ -291,6 +291,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
...
@@ -291,6 +291,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
nodeConfig
.
ExperimentalCPUManagerReconcilePeriod
,
nodeConfig
.
ExperimentalCPUManagerReconcilePeriod
,
machineInfo
,
machineInfo
,
cm
.
GetNodeAllocatableReservation
(),
cm
.
GetNodeAllocatableReservation
(),
nodeConfig
.
KubeletRootDir
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"failed to initialize cpu manager: %v"
,
err
)
glog
.
Errorf
(
"failed to initialize cpu manager: %v"
,
err
)
...
...
pkg/kubelet/cm/cpumanager/cpu_manager.go
View file @
7e7301ff
...
@@ -33,6 +33,7 @@ import (
...
@@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/status"
"k8s.io/kubernetes/pkg/kubelet/status"
"path"
)
)
// ActivePodsFunc is a function that returns a list of pods to reconcile.
// ActivePodsFunc is a function that returns a list of pods to reconcile.
...
@@ -44,6 +45,9 @@ type runtimeService interface {
...
@@ -44,6 +45,9 @@ type runtimeService interface {
type
policyName
string
type
policyName
string
// CPUManagerStateFileName is the name file name where cpu manager stores it's state
const
CPUManagerStateFileName
=
"cpu_manager_state"
// Manager interface provides methods for Kubelet to manage pod cpus.
// Manager interface provides methods for Kubelet to manage pod cpus.
type
Manager
interface
{
type
Manager
interface
{
// Start is called during Kubelet initialization.
// Start is called during Kubelet initialization.
...
@@ -99,13 +103,16 @@ func NewManager(
...
@@ -99,13 +103,16 @@ func NewManager(
reconcilePeriod
time
.
Duration
,
reconcilePeriod
time
.
Duration
,
machineInfo
*
cadvisorapi
.
MachineInfo
,
machineInfo
*
cadvisorapi
.
MachineInfo
,
nodeAllocatableReservation
v1
.
ResourceList
,
nodeAllocatableReservation
v1
.
ResourceList
,
stateFileDirecory
string
,
)
(
Manager
,
error
)
{
)
(
Manager
,
error
)
{
var
policy
Policy
var
policy
Policy
var
stateHandle
state
.
State
switch
policyName
(
cpuPolicyName
)
{
switch
policyName
(
cpuPolicyName
)
{
case
PolicyNone
:
case
PolicyNone
:
policy
=
NewNonePolicy
()
policy
=
NewNonePolicy
()
stateHandle
=
state
.
NewMemoryState
()
case
PolicyStatic
:
case
PolicyStatic
:
topo
,
err
:=
topology
.
Discover
(
machineInfo
)
topo
,
err
:=
topology
.
Discover
(
machineInfo
)
...
@@ -134,16 +141,18 @@ func NewManager(
...
@@ -134,16 +141,18 @@ func NewManager(
reservedCPUsFloat
:=
float64
(
reservedCPUs
.
MilliValue
())
/
1000
reservedCPUsFloat
:=
float64
(
reservedCPUs
.
MilliValue
())
/
1000
numReservedCPUs
:=
int
(
math
.
Ceil
(
reservedCPUsFloat
))
numReservedCPUs
:=
int
(
math
.
Ceil
(
reservedCPUsFloat
))
policy
=
NewStaticPolicy
(
topo
,
numReservedCPUs
)
policy
=
NewStaticPolicy
(
topo
,
numReservedCPUs
)
stateHandle
=
state
.
NewFileState
(
path
.
Join
(
stateFileDirecory
,
CPUManagerStateFileName
),
policy
.
Name
())
default
:
default
:
glog
.
Errorf
(
"[cpumanager] Unknown policy
\"
%s
\"
, falling back to default policy
\"
%s
\"
"
,
cpuPolicyName
,
PolicyNone
)
glog
.
Errorf
(
"[cpumanager] Unknown policy
\"
%s
\"
, falling back to default policy
\"
%s
\"
"
,
cpuPolicyName
,
PolicyNone
)
policy
=
NewNonePolicy
()
policy
=
NewNonePolicy
()
stateHandle
=
state
.
NewMemoryState
()
}
}
manager
:=
&
manager
{
manager
:=
&
manager
{
policy
:
policy
,
policy
:
policy
,
reconcilePeriod
:
reconcilePeriod
,
reconcilePeriod
:
reconcilePeriod
,
state
:
state
.
NewMemoryState
()
,
state
:
state
Handle
,
machineInfo
:
machineInfo
,
machineInfo
:
machineInfo
,
nodeAllocatableReservation
:
nodeAllocatableReservation
,
nodeAllocatableReservation
:
nodeAllocatableReservation
,
}
}
...
...
pkg/kubelet/cm/cpumanager/policy_static.go
View file @
7e7301ff
...
@@ -109,9 +109,45 @@ func (p *staticPolicy) Name() string {
...
@@ -109,9 +109,45 @@ func (p *staticPolicy) Name() string {
}
}
func
(
p
*
staticPolicy
)
Start
(
s
state
.
State
)
{
func
(
p
*
staticPolicy
)
Start
(
s
state
.
State
)
{
// Configure the shared pool to include all detected CPU IDs.
if
err
:=
p
.
validateState
(
s
);
err
!=
nil
{
allCPUs
:=
p
.
topology
.
CPUDetails
.
CPUs
()
glog
.
Errorf
(
"[cpumanager] static policy invalid state: %s
\n
"
,
err
.
Error
())
s
.
SetDefaultCPUSet
(
allCPUs
)
panic
(
"[cpumanager] - please drain node and remove policy state file"
)
}
}
func
(
p
*
staticPolicy
)
validateState
(
s
state
.
State
)
error
{
tmpAssignments
:=
s
.
GetCPUAssignments
()
tmpDefaultCPUset
:=
s
.
GetDefaultCPUSet
()
// Default cpuset cannot be empty when assignments exist
if
tmpDefaultCPUset
.
IsEmpty
()
{
if
len
(
tmpAssignments
)
!=
0
{
return
fmt
.
Errorf
(
"default cpuset cannot be empty"
)
}
// state is empty initialize
allCPUs
:=
p
.
topology
.
CPUDetails
.
CPUs
()
s
.
SetDefaultCPUSet
(
allCPUs
)
return
nil
}
// State has already been initialized from file (is not empty)
// 1 Check if the reserved cpuset is not part of default cpuset because:
// - kube/system reserved have changed (increased) - may lead to some containers not being able to start
// - user tampered with file
if
!
p
.
reserved
.
Intersection
(
tmpDefaultCPUset
)
.
Equals
(
p
.
reserved
)
{
return
fmt
.
Errorf
(
"not all reserved cpus:
\"
%s
\"
are present in defaultCpuSet:
\"
%s
\"
"
,
p
.
reserved
.
String
(),
tmpDefaultCPUset
.
String
())
}
// 2. Check if state for static policy is consistent
for
cID
,
cset
:=
range
tmpAssignments
{
// None of the cpu in DEFAULT cset should be in s.assignments
if
!
tmpDefaultCPUset
.
Intersection
(
cset
)
.
IsEmpty
()
{
return
fmt
.
Errorf
(
"container id: %s cpuset:
\"
%s
\"
overlaps with default cpuset
\"
%s
\"
"
,
cID
,
cset
.
String
(),
tmpDefaultCPUset
.
String
())
}
}
return
nil
}
}
// assignableCPUs returns the set of unassigned CPUs minus the reserved set.
// assignableCPUs returns the set of unassigned CPUs minus the reserved set.
...
...
pkg/kubelet/cm/cpumanager/state/state_file.go
View file @
7e7301ff
...
@@ -18,6 +18,7 @@ package state
...
@@ -18,6 +18,7 @@ package state
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/golang/glog"
"io/ioutil"
"io/ioutil"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
...
@@ -26,6 +27,7 @@ import (
...
@@ -26,6 +27,7 @@ import (
)
)
type
stateFileData
struct
{
type
stateFileData
struct
{
PolicyName
string
`json:"policyName"`
DefaultCPUSet
string
`json:"defaultCpuSet"`
DefaultCPUSet
string
`json:"defaultCpuSet"`
Entries
map
[
string
]
string
`json:"entries,omitempty"`
Entries
map
[
string
]
string
`json:"entries,omitempty"`
}
}
...
@@ -35,19 +37,21 @@ var _ State = &stateFile{}
...
@@ -35,19 +37,21 @@ var _ State = &stateFile{}
type
stateFile
struct
{
type
stateFile
struct
{
sync
.
RWMutex
sync
.
RWMutex
stateFilePath
string
stateFilePath
string
policyName
string
cache
State
cache
State
}
}
// NewFileState creates new State for keeping track of cpu/pod assignment with file backend
// NewFileState creates new State for keeping track of cpu/pod assignment with file backend
func
NewFileState
(
filePath
string
)
State
{
func
NewFileState
(
filePath
string
,
policyName
string
)
State
{
stateFile
:=
&
stateFile
{
stateFile
:=
&
stateFile
{
stateFilePath
:
filePath
,
stateFilePath
:
filePath
,
cache
:
NewMemoryState
(),
cache
:
NewMemoryState
(),
policyName
:
policyName
,
}
}
if
err
:=
stateFile
.
tryRestoreState
();
err
!=
nil
{
if
err
:=
stateFile
.
tryRestoreState
();
err
!=
nil
{
// could not restore state, init new state file
// could not restore state, init new state file
glog
.
Infof
(
"[cpumanager] state file: initializing empty state file"
)
glog
.
Infof
(
"[cpumanager] state file: initializing empty state file
- reason:
\"
%s
\"
"
)
stateFile
.
cache
.
ClearState
()
stateFile
.
cache
.
ClearState
()
stateFile
.
storeState
()
stateFile
.
storeState
()
}
}
...
@@ -85,6 +89,10 @@ func (sf *stateFile) tryRestoreState() error {
...
@@ -85,6 +89,10 @@ func (sf *stateFile) tryRestoreState() error {
return
err
return
err
}
}
if
sf
.
policyName
!=
readState
.
PolicyName
{
return
fmt
.
Errorf
(
"policy configured
\"
%s
\"
!= policy from state file
\"
%s
\"
"
,
sf
.
policyName
,
readState
.
PolicyName
)
}
if
tmpDefaultCPUSet
,
err
=
cpuset
.
Parse
(
readState
.
DefaultCPUSet
);
err
!=
nil
{
if
tmpDefaultCPUSet
,
err
=
cpuset
.
Parse
(
readState
.
DefaultCPUSet
);
err
!=
nil
{
glog
.
Warningf
(
"[cpumanager] state file: could not parse state file - [defaultCpuSet:
\"
%s
\"
]"
,
readState
.
DefaultCPUSet
)
glog
.
Warningf
(
"[cpumanager] state file: could not parse state file - [defaultCpuSet:
\"
%s
\"
]"
,
readState
.
DefaultCPUSet
)
return
err
return
err
...
@@ -113,6 +121,7 @@ func (sf *stateFile) storeState() {
...
@@ -113,6 +121,7 @@ func (sf *stateFile) storeState() {
var
err
error
var
err
error
data
:=
stateFileData
{
data
:=
stateFileData
{
PolicyName
:
sf
.
policyName
,
DefaultCPUSet
:
sf
.
cache
.
GetDefaultCPUSet
()
.
String
(),
DefaultCPUSet
:
sf
.
cache
.
GetDefaultCPUSet
()
.
String
(),
Entries
:
map
[
string
]
string
{},
Entries
:
map
[
string
]
string
{},
}
}
...
...
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