Merge pull request #73758 from sjenning/priority-based-oom-score-adj

kubelet: set low oom_score_adj for containers in critical pods
pull/564/head
Kubernetes Prow Robot 2019-02-06 21:13:55 -08:00 committed by GitHub
commit 6796645672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -11,6 +11,7 @@ go_test(
srcs = ["policy_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/scheduling:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
],
@ -25,6 +26,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubelet/qos",
deps = [
"//pkg/apis/core/v1/helper/qos:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
],
)

View File

@ -17,8 +17,9 @@ limitations under the License.
package qos
import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
v1qos "k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
"k8s.io/kubernetes/pkg/kubelet/types"
)
const (
@ -41,6 +42,11 @@ 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.
return guaranteedOOMScoreAdj
}
switch v1qos.GetPodQOS(pod) {
case v1.PodQOSGuaranteed:
// Guaranteed containers should be the last to get killed.

View File

@ -20,8 +20,9 @@ import (
"strconv"
"testing"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/kubernetes/pkg/apis/scheduling"
)
const (
@ -135,6 +136,19 @@ var (
},
},
}
systemCritical = scheduling.SystemCriticalPriority
critical = v1.Pod{
Spec: v1.PodSpec{
Priority: &systemCritical,
Containers: []v1.Container{
{
Resources: v1.ResourceRequirements{},
},
},
},
}
)
type oomTest struct {
@ -188,6 +202,12 @@ func TestGetContainerOOMScoreAdjust(t *testing.T) {
lowOOMScoreAdj: 2,
highOOMScoreAdj: 2,
},
{
pod: &critical,
memoryCapacity: 4000000000,
lowOOMScoreAdj: -998,
highOOMScoreAdj: -998,
},
}
for _, test := range oomTests {
oomScoreAdj := GetContainerOOMScoreAdjust(test.pod, &test.pod.Spec.Containers[0], test.memoryCapacity)