mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #84415 from langyenan/fix-evict-admit
reject pods when under disk pressure
This commit is contained in:
commit
e948a67292
@ -137,8 +137,10 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd
|
||||
if kubelettypes.IsCriticalPod(attrs.Pod) {
|
||||
return lifecycle.PodAdmitResult{Admit: true}
|
||||
}
|
||||
// the node has memory pressure, admit if not best-effort
|
||||
if hasNodeCondition(m.nodeConditions, v1.NodeMemoryPressure) {
|
||||
|
||||
// Conditions other than memory pressure reject all pods
|
||||
nodeOnlyHasMemoryPressureCondition := hasNodeCondition(m.nodeConditions, v1.NodeMemoryPressure) && len(m.nodeConditions) == 1
|
||||
if nodeOnlyHasMemoryPressureCondition {
|
||||
notBestEffort := v1.PodQOSBestEffort != v1qos.GetPodQOS(attrs.Pod)
|
||||
if notBestEffort {
|
||||
return lifecycle.PodAdmitResult{Admit: true}
|
||||
|
@ -391,6 +391,52 @@ func TestMemoryPressure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeContainersByQOS(class v1.PodQOSClass) []v1.Container {
|
||||
resource := newResourceList("100m", "1Gi", "")
|
||||
switch class {
|
||||
case v1.PodQOSGuaranteed:
|
||||
return []v1.Container{newContainer("guaranteed-container", resource, resource)}
|
||||
case v1.PodQOSBurstable:
|
||||
return []v1.Container{newContainer("burtable-container", resource, nil)}
|
||||
case v1.PodQOSBestEffort:
|
||||
fallthrough
|
||||
default:
|
||||
return []v1.Container{newContainer("best-effort-container", nil, nil)}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdmitUnderNodeConditions(t *testing.T) {
|
||||
manager := &managerImpl{}
|
||||
pods := []*v1.Pod{
|
||||
newPod("guaranteed-pod", scheduling.DefaultPriorityWhenNoDefaultClassExists, makeContainersByQOS(v1.PodQOSGuaranteed), nil),
|
||||
newPod("burstable-pod", scheduling.DefaultPriorityWhenNoDefaultClassExists, makeContainersByQOS(v1.PodQOSBurstable), nil),
|
||||
newPod("best-effort-pod", scheduling.DefaultPriorityWhenNoDefaultClassExists, makeContainersByQOS(v1.PodQOSBestEffort), nil),
|
||||
}
|
||||
|
||||
expected := []bool{true, true, true}
|
||||
for i, pod := range pods {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
manager.nodeConditions = []v1.NodeConditionType{v1.NodeMemoryPressure}
|
||||
expected = []bool{true, true, false}
|
||||
for i, pod := range pods {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
manager.nodeConditions = []v1.NodeConditionType{v1.NodeMemoryPressure, v1.NodeDiskPressure}
|
||||
expected = []bool{false, false, false}
|
||||
for i, pod := range pods {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parseQuantity parses the specified value (if provided) otherwise returns 0 value
|
||||
func parseQuantity(value string) resource.Quantity {
|
||||
if len(value) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user