Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/kubelet/qos/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (
// 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.
func GetContainerOOMScoreAdjust(pod *v1.Pod, container *v1.Container, memoryCapacity int64) int {
if types.IsCriticalPod(pod) {
// Critical pods should be the last to get killed.
if types.IsNodeCriticalPod(pod) {
// Only node critical pod should be the last to get killed.
return guaranteedOOMScoreAdj
}

Expand Down
27 changes: 24 additions & 3 deletions pkg/kubelet/qos/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,24 @@ var (

systemCritical = scheduling.SystemCriticalPriority

critical = v1.Pod{
clusterCritical = v1.Pod{
Spec: v1.PodSpec{
Priority: &systemCritical,
PriorityClassName: scheduling.SystemClusterCritical,
Priority: &systemCritical,
Containers: []v1.Container{
{
Resources: v1.ResourceRequirements{},
},
},
},
}

systemNodeCritical = scheduling.SystemCriticalPriority + 1000

nodeCritical = v1.Pod{
Spec: v1.PodSpec{
PriorityClassName: scheduling.SystemNodeCritical,
Priority: &systemNodeCritical,
Containers: []v1.Container{
{
Resources: v1.ResourceRequirements{},
Expand Down Expand Up @@ -203,7 +218,13 @@ func TestGetContainerOOMScoreAdjust(t *testing.T) {
highOOMScoreAdj: 3,
},
{
pod: &critical,
pod: &clusterCritical,
memoryCapacity: 4000000000,
lowOOMScoreAdj: 1000,
highOOMScoreAdj: 1000,
},
{
pod: &nodeCritical,
memoryCapacity: 4000000000,
lowOOMScoreAdj: -997,
highOOMScoreAdj: -997,
Expand Down
5 changes: 5 additions & 0 deletions pkg/kubelet/types/pod_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,8 @@ func Preemptable(preemptor, preemptee *v1.Pod) bool {
func IsCriticalPodBasedOnPriority(priority int32) bool {
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)
}