mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Merge pull request #99729 from ravisantoshgudimetla/low-oom-score
Only system-node-critical pods should be OOM Killed last
This commit is contained in:
commit
0691157ec4
@ -38,8 +38,8 @@ 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 types.IsCriticalPod(pod) {
|
if types.IsNodeCriticalPod(pod) {
|
||||||
// Critical pods should be the last to get killed.
|
// Only node critical pod should be the last to get killed.
|
||||||
return guaranteedOOMScoreAdj
|
return guaranteedOOMScoreAdj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,9 @@ var (
|
|||||||
|
|
||||||
systemCritical = scheduling.SystemCriticalPriority
|
systemCritical = scheduling.SystemCriticalPriority
|
||||||
|
|
||||||
critical = v1.Pod{
|
clusterCritical = v1.Pod{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
|
PriorityClassName: scheduling.SystemClusterCritical,
|
||||||
Priority: &systemCritical,
|
Priority: &systemCritical,
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
{
|
||||||
@ -149,6 +150,20 @@ var (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
systemNodeCritical = scheduling.SystemCriticalPriority + 1000
|
||||||
|
|
||||||
|
nodeCritical = v1.Pod{
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
PriorityClassName: scheduling.SystemNodeCritical,
|
||||||
|
Priority: &systemNodeCritical,
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Resources: v1.ResourceRequirements{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type oomTest struct {
|
type oomTest struct {
|
||||||
@ -203,7 +218,13 @@ func TestGetContainerOOMScoreAdjust(t *testing.T) {
|
|||||||
highOOMScoreAdj: 3,
|
highOOMScoreAdj: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pod: &critical,
|
pod: &clusterCritical,
|
||||||
|
memoryCapacity: 4000000000,
|
||||||
|
lowOOMScoreAdj: 1000,
|
||||||
|
highOOMScoreAdj: 1000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pod: &nodeCritical,
|
||||||
memoryCapacity: 4000000000,
|
memoryCapacity: 4000000000,
|
||||||
lowOOMScoreAdj: -997,
|
lowOOMScoreAdj: -997,
|
||||||
highOOMScoreAdj: -997,
|
highOOMScoreAdj: -997,
|
||||||
|
@ -184,3 +184,8 @@ func Preemptable(preemptor, preemptee *v1.Pod) bool {
|
|||||||
func IsCriticalPodBasedOnPriority(priority int32) bool {
|
func IsCriticalPodBasedOnPriority(priority int32) bool {
|
||||||
return priority >= scheduling.SystemCriticalPriority
|
return priority >= scheduling.SystemCriticalPriority
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNodeCriticalPod checks if the given pod is a system-node-critical
|
||||||
|
func IsNodeCriticalPod(pod *v1.Pod) bool {
|
||||||
|
return IsCriticalPod(pod) && (pod.Spec.PriorityClassName == scheduling.SystemNodeCritical)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user