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