Skip to content

Commit c14f8d5

Browse files
committed
chore(scheduler): add filter integration tests for missing part plugins: NodeResources plugin
1 parent 3a812ec commit c14f8d5

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

test/integration/scheduler/filters/filters_test.go

+110
Original file line numberDiff line numberDiff line change
@@ -2440,3 +2440,113 @@ func TestPodAffinityMatchLabelKeyEnablement(t *testing.T) {
24402440
}
24412441

24422442
}
2443+
2444+
func TestNodeResourcesFilter(t *testing.T) {
2445+
pause := imageutils.GetPauseImageName()
2446+
tests := []struct {
2447+
name string
2448+
node *v1.Node
2449+
existingPod *v1.Pod
2450+
incomingPod *v1.Pod
2451+
fit bool
2452+
}{
2453+
{
2454+
name: "pod does not fit due to insufficient node resources",
2455+
node: st.MakeNode().Name("insufficient-node").Capacity(
2456+
map[v1.ResourceName]string{
2457+
v1.ResourceCPU: "2",
2458+
v1.ResourceMemory: "2G",
2459+
}).Obj(),
2460+
existingPod: st.MakePod().Name("insufficient-existing-pod").
2461+
Res(map[v1.ResourceName]string{
2462+
v1.ResourceCPU: "1",
2463+
v1.ResourceMemory: "1G",
2464+
}).Container(pause).
2465+
Obj(),
2466+
incomingPod: st.MakePod().Name("insufficient-incoming-pod").
2467+
Res(map[v1.ResourceName]string{
2468+
v1.ResourceCPU: "3",
2469+
v1.ResourceMemory: "3G",
2470+
}).Container(pause).
2471+
Obj(),
2472+
fit: false,
2473+
},
2474+
{
2475+
name: "pod fits with sufficient node resources",
2476+
node: st.MakeNode().Name("sufficient-node").Capacity(
2477+
map[v1.ResourceName]string{
2478+
v1.ResourceCPU: "3",
2479+
v1.ResourceMemory: "3G",
2480+
}).Obj(),
2481+
existingPod: st.MakePod().Name("sufficient-existing-pod").
2482+
Res(map[v1.ResourceName]string{
2483+
v1.ResourceCPU: "1",
2484+
v1.ResourceMemory: "1G",
2485+
}).Container(pause).
2486+
Obj(),
2487+
incomingPod: st.MakePod().Name("sufficient-incoming-pod").
2488+
Res(map[v1.ResourceName]string{
2489+
v1.ResourceCPU: "1",
2490+
v1.ResourceMemory: "1G",
2491+
}).Container(pause).
2492+
Obj(),
2493+
fit: true,
2494+
},
2495+
{
2496+
name: "pod fits with sufficient node resources (no existing pod)",
2497+
node: st.MakeNode().Name("sufficient-node").Capacity(
2498+
map[v1.ResourceName]string{
2499+
v1.ResourceCPU: "3",
2500+
v1.ResourceMemory: "3G",
2501+
}).Obj(),
2502+
incomingPod: st.MakePod().Name("sufficient-incoming-pod").
2503+
Res(map[v1.ResourceName]string{
2504+
v1.ResourceCPU: "2",
2505+
v1.ResourceMemory: "2G",
2506+
}).Container(pause).
2507+
Obj(),
2508+
fit: true,
2509+
},
2510+
}
2511+
for _, tt := range tests {
2512+
t.Run(tt.name, func(t *testing.T) {
2513+
testCtx := initTest(t, "node-resources-filter")
2514+
cs := testCtx.ClientSet
2515+
ns := testCtx.NS.Name
2516+
2517+
if _, err := createNode(cs, tt.node); err != nil {
2518+
t.Fatalf("Failed to create node: %v", err)
2519+
}
2520+
2521+
// set namespace to pods
2522+
tt.incomingPod.SetNamespace(ns)
2523+
allPods := append([]*v1.Pod{tt.incomingPod}, tt.existingPod)
2524+
defer testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
2525+
2526+
if tt.existingPod != nil {
2527+
if _, err := runPausePod(testCtx.ClientSet, tt.existingPod); err != nil {
2528+
t.Fatalf("Failed to create existing pod: %v", err)
2529+
}
2530+
}
2531+
2532+
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
2533+
if err != nil {
2534+
t.Fatalf("Failed to create pod: %v", err)
2535+
}
2536+
2537+
if tt.fit {
2538+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
2539+
podScheduled(cs, testPod.Namespace, testPod.Name))
2540+
if err != nil {
2541+
t.Errorf("Test Failed: Expected pod %s/%s to be scheduled but got error: %v", testPod.Namespace, testPod.Name, err)
2542+
}
2543+
} else {
2544+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
2545+
podUnschedulable(cs, testPod.Namespace, testPod.Name))
2546+
if err != nil {
2547+
t.Errorf("Test Failed: Expected pod %s/%s to be unschedulable but got error: %v", testPod.Namespace, testPod.Name, err)
2548+
}
2549+
}
2550+
})
2551+
}
2552+
}

0 commit comments

Comments
 (0)