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
53931fbc
Commit
53931fbc
authored
Dec 21, 2016
by
Dawn Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
assign -998 as the oom_score_adj for critical pods.
parent
1955ed61
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
policy.go
pkg/kubelet/qos/policy.go
+11
-1
policy_test.go
pkg/kubelet/qos/policy_test.go
+26
-0
No files found.
pkg/kubelet/qos/policy.go
View file @
53931fbc
...
@@ -16,14 +16,20 @@ limitations under the License.
...
@@ -16,14 +16,20 @@ limitations under the License.
package
qos
package
qos
import
"k8s.io/kubernetes/pkg/api/v1"
import
(
"k8s.io/kubernetes/pkg/api/v1"
kubepod
"k8s.io/kubernetes/pkg/kubelet/pod"
)
const
(
const
(
// PodInfraOOMAdj is very docker specific. For arbitrary runtime, it may not make
// PodInfraOOMAdj is very docker specific. For arbitrary runtime, it may not make
// sense to set sandbox level oom score, e.g. a sandbox could only be a namespace
// sense to set sandbox level oom score, e.g. a sandbox could only be a namespace
// without a process.
// without a process.
// TODO: Handle infra container oom score adj in a runtime agnostic way.
// TODO: Handle infra container oom score adj in a runtime agnostic way.
// TODO: Should handle critical pod oom score adj with a proper preemption priority.
// This is the workaround for https://github.com/kubernetes/kubernetes/issues/38322.
PodInfraOOMAdj
int
=
-
998
PodInfraOOMAdj
int
=
-
998
CriticalPodOOMAdj
int
=
-
998
KubeletOOMScoreAdj
int
=
-
999
KubeletOOMScoreAdj
int
=
-
999
DockerOOMScoreAdj
int
=
-
999
DockerOOMScoreAdj
int
=
-
999
KubeProxyOOMScoreAdj
int
=
-
999
KubeProxyOOMScoreAdj
int
=
-
999
...
@@ -38,6 +44,10 @@ const (
...
@@ -38,6 +44,10 @@ const (
// and 1000. Containers with higher OOM scores are killed if the system runs out of memory.
// and 1000. Containers with higher OOM scores are killed if the system runs out of memory.
// See https://lwn.net/Articles/391222/ for more information.
// See https://lwn.net/Articles/391222/ for more information.
func
GetContainerOOMScoreAdjust
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
memoryCapacity
int64
)
int
{
func
GetContainerOOMScoreAdjust
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
memoryCapacity
int64
)
int
{
if
kubepod
.
IsCriticalPod
(
pod
)
{
return
CriticalPodOOMAdj
}
switch
GetPodQOS
(
pod
)
{
switch
GetPodQOS
(
pod
)
{
case
Guaranteed
:
case
Guaranteed
:
// Guaranteed containers should be the last to get killed.
// Guaranteed containers should be the last to get killed.
...
...
pkg/kubelet/qos/policy_test.go
View file @
53931fbc
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
kubetypes
"k8s.io/kubernetes/pkg/kubelet/types"
)
)
const
(
const
(
...
@@ -135,6 +136,25 @@ var (
...
@@ -135,6 +136,25 @@ var (
},
},
},
},
}
}
criticalPodWithNoLimit
=
v1
.
Pod
{
ObjectMeta
:
v1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
kubetypes
.
CriticalPodAnnotationKey
:
""
,
},
},
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Resources
:
v1
.
ResourceRequirements
{
Requests
:
v1
.
ResourceList
{
v1
.
ResourceName
(
v1
.
ResourceMemory
)
:
resource
.
MustParse
(
strconv
.
Itoa
(
standardMemoryAmount
-
1
)),
v1
.
ResourceName
(
v1
.
ResourceCPU
)
:
resource
.
MustParse
(
"5m"
),
},
},
},
},
},
}
)
)
type
oomTest
struct
{
type
oomTest
struct
{
...
@@ -188,6 +208,12 @@ func TestGetContainerOOMScoreAdjust(t *testing.T) {
...
@@ -188,6 +208,12 @@ func TestGetContainerOOMScoreAdjust(t *testing.T) {
lowOOMScoreAdj
:
2
,
lowOOMScoreAdj
:
2
,
highOOMScoreAdj
:
2
,
highOOMScoreAdj
:
2
,
},
},
{
pod
:
&
criticalPodWithNoLimit
,
memoryCapacity
:
standardMemoryAmount
,
lowOOMScoreAdj
:
-
998
,
highOOMScoreAdj
:
-
998
,
},
}
}
for
_
,
test
:=
range
oomTests
{
for
_
,
test
:=
range
oomTests
{
oomScoreAdj
:=
GetContainerOOMScoreAdjust
(
test
.
pod
,
&
test
.
pod
.
Spec
.
Containers
[
0
],
test
.
memoryCapacity
)
oomScoreAdj
:=
GetContainerOOMScoreAdjust
(
test
.
pod
,
&
test
.
pod
.
Spec
.
Containers
[
0
],
test
.
memoryCapacity
)
...
...
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