mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Revert "Kubelet admits critical pods even under memory pressure"
This reverts commit afd676d94c
.
This commit is contained in:
parent
a3ae8c2b21
commit
ffd7dda234
@ -54,7 +54,6 @@ go_test(
|
|||||||
"//pkg/api/v1:go_default_library",
|
"//pkg/api/v1:go_default_library",
|
||||||
"//pkg/kubelet/api/v1alpha1/stats:go_default_library",
|
"//pkg/kubelet/api/v1alpha1/stats:go_default_library",
|
||||||
"//pkg/kubelet/lifecycle:go_default_library",
|
"//pkg/kubelet/lifecycle:go_default_library",
|
||||||
"//pkg/kubelet/types:go_default_library",
|
|
||||||
"//pkg/quota:go_default_library",
|
"//pkg/quota:go_default_library",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||||
|
@ -33,7 +33,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/qos"
|
"k8s.io/kubernetes/pkg/kubelet/qos"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/server/stats"
|
"k8s.io/kubernetes/pkg/kubelet/server/stats"
|
||||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd
|
|||||||
// the node has memory pressure, admit if not best-effort
|
// the node has memory pressure, admit if not best-effort
|
||||||
if hasNodeCondition(m.nodeConditions, v1.NodeMemoryPressure) {
|
if hasNodeCondition(m.nodeConditions, v1.NodeMemoryPressure) {
|
||||||
notBestEffort := v1.PodQOSBestEffort != qos.GetPodQOS(attrs.Pod)
|
notBestEffort := v1.PodQOSBestEffort != qos.GetPodQOS(attrs.Pod)
|
||||||
if notBestEffort || kubetypes.IsCriticalPod(attrs.Pod) {
|
if notBestEffort {
|
||||||
return lifecycle.PodAdmitResult{Admit: true}
|
return lifecycle.PodAdmitResult{Admit: true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
statsapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/stats"
|
statsapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/stats"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
|
"k8s.io/kubernetes/pkg/util/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mockPodKiller is used to testing which pod is killed
|
// mockPodKiller is used to testing which pod is killed
|
||||||
@ -212,8 +213,6 @@ func TestMemoryPressure(t *testing.T) {
|
|||||||
// create a best effort pod to test admission
|
// create a best effort pod to test admission
|
||||||
bestEffortPodToAdmit, _ := podMaker("best-admit", newResourceList("", ""), newResourceList("", ""), "0Gi")
|
bestEffortPodToAdmit, _ := podMaker("best-admit", newResourceList("", ""), newResourceList("", ""), "0Gi")
|
||||||
burstablePodToAdmit, _ := podMaker("burst-admit", newResourceList("100m", "100Mi"), newResourceList("200m", "200Mi"), "0Gi")
|
burstablePodToAdmit, _ := podMaker("burst-admit", newResourceList("100m", "100Mi"), newResourceList("200m", "200Mi"), "0Gi")
|
||||||
criticalBestEffortPodToAdmit, _ := podMaker("critical-best-admit", newResourceList("", ""), newResourceList("", ""), "0Gi")
|
|
||||||
criticalBestEffortPodToAdmit.ObjectMeta.Annotations = map[string]string{kubetypes.CriticalPodAnnotationKey: ""}
|
|
||||||
|
|
||||||
// synchronize
|
// synchronize
|
||||||
manager.synchronize(diskInfoProvider, activePodsFunc)
|
manager.synchronize(diskInfoProvider, activePodsFunc)
|
||||||
@ -224,8 +223,8 @@ func TestMemoryPressure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to admit our pods (they should succeed)
|
// try to admit our pods (they should succeed)
|
||||||
expected := []bool{true, true, true}
|
expected := []bool{true, true}
|
||||||
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit, criticalBestEffortPodToAdmit} {
|
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit} {
|
||||||
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
||||||
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
||||||
}
|
}
|
||||||
@ -300,10 +299,9 @@ func TestMemoryPressure(t *testing.T) {
|
|||||||
t.Errorf("Manager chose to kill pod with incorrect grace period. Expected: %d, actual: %d", 0, observedGracePeriod)
|
t.Errorf("Manager chose to kill pod with incorrect grace period. Expected: %d, actual: %d", 0, observedGracePeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the best-effort pod without critical annotation should not admit,
|
// the best-effort pod should not admit, burstable should
|
||||||
// burstable and critical pods should
|
expected = []bool{false, true}
|
||||||
expected = []bool{false, true, true}
|
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit} {
|
||||||
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit, criticalBestEffortPodToAdmit} {
|
|
||||||
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
||||||
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
||||||
}
|
}
|
||||||
@ -325,9 +323,9 @@ func TestMemoryPressure(t *testing.T) {
|
|||||||
t.Errorf("Manager chose to kill pod: %v when no pod should have been killed", podKiller.pod.Name)
|
t.Errorf("Manager chose to kill pod: %v when no pod should have been killed", podKiller.pod.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the best-effort pod should not admit, burstable and critical pods should
|
// the best-effort pod should not admit, burstable should
|
||||||
expected = []bool{false, true, true}
|
expected = []bool{false, true}
|
||||||
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit, criticalBestEffortPodToAdmit} {
|
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit} {
|
||||||
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
||||||
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
||||||
}
|
}
|
||||||
@ -350,8 +348,8 @@ func TestMemoryPressure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// all pods should admit now
|
// all pods should admit now
|
||||||
expected = []bool{true, true, true}
|
expected = []bool{true, true}
|
||||||
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit, criticalBestEffortPodToAdmit} {
|
for i, pod := range []*v1.Pod{bestEffortPodToAdmit, burstablePodToAdmit} {
|
||||||
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: pod}); expected[i] != result.Admit {
|
||||||
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
t.Errorf("Admit pod: %v, expected: %v, actual: %v", pod, expected[i], result.Admit)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/secret"
|
"k8s.io/kubernetes/pkg/kubelet/secret"
|
||||||
|
"k8s.io/kubernetes/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Manager stores and manages access to pods, maintaining the mappings
|
// Manager stores and manages access to pods, maintaining the mappings
|
||||||
|
@ -28,15 +28,6 @@ const ConfigMirrorAnnotationKey = "kubernetes.io/config.mirror"
|
|||||||
const ConfigFirstSeenAnnotationKey = "kubernetes.io/config.seen"
|
const ConfigFirstSeenAnnotationKey = "kubernetes.io/config.seen"
|
||||||
const ConfigHashAnnotationKey = "kubernetes.io/config.hash"
|
const ConfigHashAnnotationKey = "kubernetes.io/config.hash"
|
||||||
|
|
||||||
// This key needs to sync with the key used by the rescheduler, which currently
|
|
||||||
// lives in contrib. Its presence indicates 2 things, as far as the kubelet is
|
|
||||||
// concerned:
|
|
||||||
// 1. Resource related admission checks will prioritize the admission of
|
|
||||||
// pods bearing the key, over pods without the key, regardless of QoS.
|
|
||||||
// 2. The OOM score of pods bearing the key will be <= pods without
|
|
||||||
// the key (where the <= part is determied by QoS).
|
|
||||||
const CriticalPodAnnotationKey = "scheduler.alpha.kubernetes.io/critical-pod"
|
|
||||||
|
|
||||||
// PodOperation defines what changes will be made on a pod configuration.
|
// PodOperation defines what changes will be made on a pod configuration.
|
||||||
type PodOperation int
|
type PodOperation int
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user