Skip to content

Commit a8fe1f8

Browse files
committed
chore(scheduler): add filter integration tests for missing part plugins: NodeResources plugin
1 parent 16abcd7 commit a8fe1f8

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

Diff for: test/integration/scheduler/filters/filters_test.go

+115
Original file line numberDiff line numberDiff line change
@@ -2623,3 +2623,118 @@ func TestPodAffinityMatchLabelKeyEnablement(t *testing.T) {
26232623
}
26242624

26252625
}
2626+
2627+
func TestNodeResourcesFilter(t *testing.T) {
2628+
pause := imageutils.GetPauseImageName()
2629+
tests := []struct {
2630+
name string
2631+
node *v1.Node
2632+
existingPod *v1.Pod
2633+
incomingPod *v1.Pod
2634+
fit bool
2635+
}{
2636+
{
2637+
name: "pod does not fit due to insufficient node resources",
2638+
node: st.MakeNode().Name("insufficient-node").Capacity(
2639+
map[v1.ResourceName]string{
2640+
v1.ResourceCPU: "2",
2641+
v1.ResourceMemory: "2G",
2642+
}).Obj(),
2643+
existingPod: st.MakePod().Name("insufficient-existing-pod").
2644+
Res(map[v1.ResourceName]string{
2645+
v1.ResourceCPU: "1",
2646+
v1.ResourceMemory: "1G",
2647+
}).Container(pause).
2648+
Obj(),
2649+
incomingPod: st.MakePod().Name("insufficient-incoming-pod").
2650+
Res(map[v1.ResourceName]string{
2651+
v1.ResourceCPU: "3",
2652+
v1.ResourceMemory: "3G",
2653+
}).Container(pause).
2654+
Obj(),
2655+
fit: false,
2656+
},
2657+
{
2658+
name: "pod fits with sufficient node resources",
2659+
node: st.MakeNode().Name("sufficient-node").Capacity(
2660+
map[v1.ResourceName]string{
2661+
v1.ResourceCPU: "3",
2662+
v1.ResourceMemory: "3G",
2663+
}).Obj(),
2664+
existingPod: st.MakePod().Name("sufficient-existing-pod").
2665+
Res(map[v1.ResourceName]string{
2666+
v1.ResourceCPU: "1",
2667+
v1.ResourceMemory: "1G",
2668+
}).Container(pause).
2669+
Obj(),
2670+
incomingPod: st.MakePod().Name("sufficient-incoming-pod").
2671+
Res(map[v1.ResourceName]string{
2672+
v1.ResourceCPU: "1",
2673+
v1.ResourceMemory: "1G",
2674+
}).Container(pause).
2675+
Obj(),
2676+
fit: true,
2677+
},
2678+
{
2679+
name: "pod fits with sufficient node resources (no existing pod)",
2680+
node: st.MakeNode().Name("sufficient-node").Capacity(
2681+
map[v1.ResourceName]string{
2682+
v1.ResourceCPU: "3",
2683+
v1.ResourceMemory: "3G",
2684+
}).Obj(),
2685+
incomingPod: st.MakePod().Name("sufficient-incoming-pod").
2686+
Res(map[v1.ResourceName]string{
2687+
v1.ResourceCPU: "2",
2688+
v1.ResourceMemory: "2G",
2689+
}).Container(pause).
2690+
Obj(),
2691+
fit: true,
2692+
},
2693+
}
2694+
for _, tt := range tests {
2695+
t.Run(tt.name, func(t *testing.T) {
2696+
testCtx := initTest(t, "node-resources-filter")
2697+
cs := testCtx.ClientSet
2698+
ns := testCtx.NS.Name
2699+
2700+
if _, err := createNode(cs, tt.node); err != nil {
2701+
t.Fatalf("Failed to create node: %v", err)
2702+
}
2703+
2704+
// set namespace to pods
2705+
tt.incomingPod.SetNamespace(ns)
2706+
var allPods []*v1.Pod
2707+
allPods = append(allPods, tt.incomingPod)
2708+
if tt.existingPod != nil {
2709+
tt.existingPod.SetNamespace(ns)
2710+
allPods = append(allPods, tt.existingPod)
2711+
}
2712+
defer testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
2713+
2714+
if tt.existingPod != nil {
2715+
if _, err := runPausePod(testCtx.ClientSet, tt.existingPod); err != nil {
2716+
t.Fatalf("Failed to create existing pod: %v", err)
2717+
}
2718+
}
2719+
2720+
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
2721+
if err != nil {
2722+
t.Fatalf("Failed to create pod: %v", err)
2723+
}
2724+
2725+
if tt.fit {
2726+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
2727+
podScheduled(cs, testPod.Namespace, testPod.Name))
2728+
if err != nil {
2729+
t.Errorf("Test Failed: Expected pod %s/%s to be scheduled but got error: %v", testPod.Namespace, testPod.Name, err)
2730+
}
2731+
} else {
2732+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
2733+
podUnschedulable(cs, testPod.Namespace, testPod.Name))
2734+
if err != nil {
2735+
t.Errorf("Test Failed: Expected pod %s/%s to be unschedulable but got error: %v", testPod.Namespace, testPod.Name, err)
2736+
}
2737+
}
2738+
})
2739+
}
2740+
}

0 commit comments

Comments
 (0)