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
f68f3ff7
Commit
f68f3ff7
authored
Mar 16, 2018
by
Derek Carr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cpu cfs quota flag with pod cgroups
parent
ca02c118
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
4 deletions
+47
-4
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
helpers_linux.go
pkg/kubelet/cm/helpers_linux.go
+6
-1
helpers_linux_test.go
pkg/kubelet/cm/helpers_linux_test.go
+34
-1
helpers_unsupported.go
pkg/kubelet/cm/helpers_unsupported.go
+1
-1
pod_container_manager_linux.go
pkg/kubelet/cm/pod_container_manager_linux.go
+3
-1
No files found.
cmd/kubelet/app/server.go
View file @
f68f3ff7
...
...
@@ -661,6 +661,7 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies) (err error) {
ExperimentalCPUManagerPolicy
:
s
.
CPUManagerPolicy
,
ExperimentalCPUManagerReconcilePeriod
:
s
.
CPUManagerReconcilePeriod
.
Duration
,
ExperimentalPodPidsLimit
:
s
.
PodPidsLimit
,
EnforceCPULimits
:
s
.
CPUCFSQuota
,
},
s
.
FailSwapOn
,
devicePluginEnabled
,
...
...
pkg/kubelet/cm/container_manager.go
View file @
f68f3ff7
...
...
@@ -111,6 +111,7 @@ type NodeConfig struct {
ExperimentalCPUManagerPolicy
string
ExperimentalCPUManagerReconcilePeriod
time
.
Duration
ExperimentalPodPidsLimit
int64
EnforceCPULimits
bool
}
type
NodeAllocatableConfig
struct
{
...
...
pkg/kubelet/cm/container_manager_linux.go
View file @
f68f3ff7
...
...
@@ -301,6 +301,7 @@ func (cm *containerManagerImpl) NewPodContainerManager() PodContainerManager {
subsystems
:
cm
.
subsystems
,
cgroupManager
:
cm
.
cgroupManager
,
podPidsLimit
:
cm
.
ExperimentalPodPidsLimit
,
enforceCPULimits
:
cm
.
EnforceCPULimits
,
}
}
return
&
podContainerManagerNoop
{
...
...
pkg/kubelet/cm/helpers_linux.go
View file @
f68f3ff7
...
...
@@ -103,7 +103,7 @@ func HugePageLimits(resourceList v1.ResourceList) map[int64]int64 {
}
// ResourceConfigForPod takes the input pod and outputs the cgroup resource config.
func
ResourceConfigForPod
(
pod
*
v1
.
Pod
)
*
ResourceConfig
{
func
ResourceConfigForPod
(
pod
*
v1
.
Pod
,
enforceCPULimits
bool
)
*
ResourceConfig
{
// sum requests and limits.
reqs
,
limits
:=
resource
.
PodRequestsAndLimits
(
pod
)
...
...
@@ -146,6 +146,11 @@ func ResourceConfigForPod(pod *v1.Pod) *ResourceConfig {
}
}
// quota is not capped when cfs quota is disabled
if
!
enforceCPULimits
{
cpuQuota
=
int64
(
-
1
)
}
// determine the qos class
qosClass
:=
v1qos
.
GetPodQOS
(
pod
)
...
...
pkg/kubelet/cm/helpers_linux_test.go
View file @
f68f3ff7
...
...
@@ -57,10 +57,12 @@ func TestResourceConfigForPod(t *testing.T) {
guaranteedShares
:=
MilliCPUToShares
(
100
)
guaranteedQuota
,
guaranteedPeriod
:=
MilliCPUToQuota
(
100
)
memoryQuantity
=
resource
.
MustParse
(
"100Mi"
)
cpuNoLimit
:=
int64
(
-
1
)
guaranteedMemory
:=
memoryQuantity
.
Value
()
testCases
:=
map
[
string
]
struct
{
pod
*
v1
.
Pod
expected
*
ResourceConfig
enforceCPULimits
bool
}{
"besteffort"
:
{
pod
:
&
v1
.
Pod
{
...
...
@@ -72,6 +74,7 @@ func TestResourceConfigForPod(t *testing.T) {
},
},
},
enforceCPULimits
:
true
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
minShares
},
},
"burstable-no-limits"
:
{
...
...
@@ -84,6 +87,7 @@ func TestResourceConfigForPod(t *testing.T) {
},
},
},
enforceCPULimits
:
true
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
burstableShares
},
},
"burstable-with-limits"
:
{
...
...
@@ -96,8 +100,22 @@ func TestResourceConfigForPod(t *testing.T) {
},
},
},
enforceCPULimits
:
true
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
burstableShares
,
CpuQuota
:
&
burstableQuota
,
CpuPeriod
:
&
burstablePeriod
,
Memory
:
&
burstableMemory
},
},
"burstable-with-limits-no-cpu-enforcement"
:
{
pod
:
&
v1
.
Pod
{
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Resources
:
getResourceRequirements
(
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"200m"
,
"200Mi"
)),
},
},
},
},
enforceCPULimits
:
false
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
burstableShares
,
CpuQuota
:
&
cpuNoLimit
,
CpuPeriod
:
&
burstablePeriod
,
Memory
:
&
burstableMemory
},
},
"burstable-partial-limits"
:
{
pod
:
&
v1
.
Pod
{
Spec
:
v1
.
PodSpec
{
...
...
@@ -111,6 +129,7 @@ func TestResourceConfigForPod(t *testing.T) {
},
},
},
enforceCPULimits
:
true
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
burstablePartialShares
},
},
"guaranteed"
:
{
...
...
@@ -123,11 +142,25 @@ func TestResourceConfigForPod(t *testing.T) {
},
},
},
enforceCPULimits
:
true
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
guaranteedShares
,
CpuQuota
:
&
guaranteedQuota
,
CpuPeriod
:
&
guaranteedPeriod
,
Memory
:
&
guaranteedMemory
},
},
"guaranteed-no-cpu-enforcement"
:
{
pod
:
&
v1
.
Pod
{
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Resources
:
getResourceRequirements
(
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
},
},
},
},
enforceCPULimits
:
false
,
expected
:
&
ResourceConfig
{
CpuShares
:
&
guaranteedShares
,
CpuQuota
:
&
cpuNoLimit
,
CpuPeriod
:
&
guaranteedPeriod
,
Memory
:
&
guaranteedMemory
},
},
}
for
testName
,
testCase
:=
range
testCases
{
actual
:=
ResourceConfigForPod
(
testCase
.
pod
)
actual
:=
ResourceConfigForPod
(
testCase
.
pod
,
testCase
.
enforceCPULimits
)
if
!
reflect
.
DeepEqual
(
actual
.
CpuPeriod
,
testCase
.
expected
.
CpuPeriod
)
{
t
.
Errorf
(
"unexpected result, test: %v, cpu period not as expected"
,
testName
)
}
...
...
pkg/kubelet/cm/helpers_unsupported.go
View file @
f68f3ff7
...
...
@@ -43,7 +43,7 @@ func MilliCPUToShares(milliCPU int64) int64 {
}
// ResourceConfigForPod takes the input pod and outputs the cgroup resource config.
func
ResourceConfigForPod
(
pod
*
v1
.
Pod
)
*
ResourceConfig
{
func
ResourceConfigForPod
(
pod
*
v1
.
Pod
,
enforceCPULimit
bool
)
*
ResourceConfig
{
return
nil
}
...
...
pkg/kubelet/cm/pod_container_manager_linux.go
View file @
f68f3ff7
...
...
@@ -49,6 +49,8 @@ type podContainerManagerImpl struct {
cgroupManager
CgroupManager
// Maximum number of pids in a pod
podPidsLimit
int64
// enforceCPULimits controls whether cfs quota is enforced or not
enforceCPULimits
bool
}
// Make sure that podContainerManagerImpl implements the PodContainerManager interface
...
...
@@ -79,7 +81,7 @@ func (m *podContainerManagerImpl) EnsureExists(pod *v1.Pod) error {
// Create the pod container
containerConfig
:=
&
CgroupConfig
{
Name
:
podContainerName
,
ResourceParameters
:
ResourceConfigForPod
(
pod
),
ResourceParameters
:
ResourceConfigForPod
(
pod
,
m
.
enforceCPULimits
),
}
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
kubefeatures
.
SupportPodPidsLimit
)
&&
m
.
podPidsLimit
>
0
{
containerConfig
.
ResourceParameters
.
PodPidsLimit
=
&
m
.
podPidsLimit
...
...
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