mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
unit test: TestAdmitUnderNodeConditions
This commit is contained in:
parent
372bf95a4f
commit
22d8e054bc
@ -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
|
// parseQuantity parses the specified value (if provided) otherwise returns 0 value
|
||||||
func parseQuantity(value string) resource.Quantity {
|
func parseQuantity(value string) resource.Quantity {
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user