diff --git a/pkg/scheduler/actions/allocate/allocate_test.go b/pkg/scheduler/actions/allocate/allocate_test.go index 910a1eec64a..6acb4c2a7e1 100644 --- a/pkg/scheduler/actions/allocate/allocate_test.go +++ b/pkg/scheduler/actions/allocate/allocate_test.go @@ -87,8 +87,8 @@ func TestAllocate(t *testing.T) { }, }, Pods: []*v1.Pod{ - util.BuildPod("c1", "p1", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "p2", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "p1", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "p2", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G")), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("2", "4Gi"), make(map[string]string)), @@ -143,13 +143,13 @@ func TestAllocate(t *testing.T) { // due to change of TaskOrderFn Pods: []*v1.Pod{ // pending pod with owner1, under c1 - util.BuildPod("c1", "pg1-p-1", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "pg1-p-1", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G")), // pending pod with owner1, under c1 - util.BuildPod("c1", "pg1-p-2", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "pg1-p-2", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G")), // pending pod with owner2, under c2 - util.BuildPod("c2", "pg2-p-1", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPod("c2", "pg2-p-1", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), // pending pod with owner2, under c2 - util.BuildPod("c2", "pg2-p-2", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPod("c2", "pg2-p-2", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("2", "4G"), make(map[string]string)), @@ -210,9 +210,9 @@ func TestAllocate(t *testing.T) { Pods: []*v1.Pod{ // pending pod with owner1, under ns:c1/q:c1 - util.BuildPod("c1", "p1", "", v1.PodPending, util.BuildResourceList("3", "1G"), "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "p1", "", v1.PodPending, "pg1", util.PodResourceOption("3", "1G")), // pending pod with owner2, under ns:c1/q:c2 - util.BuildPod("c1", "p2", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "p2", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("2", "4G"), make(map[string]string)), @@ -350,8 +350,8 @@ func TestAllocateWithDynamicPVC(t *testing.T) { name: "resource not match", TestArg: cache.TestArg{ Pods: []*v1.Pod{ - util.BuildPodWithPVC("c1", "p1", "", v1.PodPending, util.BuildResourceList("1", "1G"), pvc, "pg1", make(map[string]string), make(map[string]string)), - util.BuildPodWithPVC("c1", "p2", "", v1.PodPending, util.BuildResourceList("1", "1G"), pvc1, "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "p1", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G"), util.PodPVCOption(pvc)), + util.BuildPod("c1", "p2", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G"), util.PodPVCOption(pvc)), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("1", "4Gi"), make(map[string]string)), @@ -370,8 +370,8 @@ func TestAllocateWithDynamicPVC(t *testing.T) { name: "node changed with enough resource", TestArg: cache.TestArg{ Pods: []*v1.Pod{ - util.BuildPodWithPVC("c1", "p1", "", v1.PodPending, util.BuildResourceList("1", "1G"), pvc, "pg1", make(map[string]string), make(map[string]string)), - util.BuildPodWithPVC("c1", "p2", "", v1.PodPending, util.BuildResourceList("1", "1G"), pvc1, "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "p1", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G"), util.PodPVCOption(pvc)), + util.BuildPod("c1", "p2", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G"), util.PodPVCOption(pvc1)), }, Nodes: []*v1.Node{ util.BuildNode("n2", util.BuildResourceList("2", "4Gi"), make(map[string]string)), diff --git a/pkg/scheduler/actions/preempt/preempt_test.go b/pkg/scheduler/actions/preempt/preempt_test.go index 35969adcbb1..2e5b855bff7 100644 --- a/pkg/scheduler/actions/preempt/preempt_test.go +++ b/pkg/scheduler/actions/preempt/preempt_test.go @@ -79,9 +79,9 @@ func TestPreempt(t *testing.T) { }, }, Pods: []*v1.Pod{ - util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptor1", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptor1", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1G")), }, // If there are enough idle resources on the node, then there is no need to preempt anything. Nodes: []*v1.Node{ @@ -139,10 +139,10 @@ func TestPreempt(t *testing.T) { }, // Both pg1 and pg2 jobs are pipelined, because enough pods are already running. Pods: []*v1.Pod{ - util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptee3", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptor2", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptee3", "n1", v1.PodRunning, "pg2", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptor2", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), }, // All resources on the node will be in use. Nodes: []*v1.Node{ @@ -201,10 +201,10 @@ func TestPreempt(t *testing.T) { }, }, Pods: []*v1.Pod{ - util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", map[string]string{schedulingv1beta1.PodPreemptable: "true"}, make(map[string]string)), - util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptor1", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptor2", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPreemptablePod("c1", "preemptee1", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptor1", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptor2", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("2", "2G"), make(map[string]string)), @@ -264,10 +264,10 @@ func TestPreempt(t *testing.T) { // There are 3 cpus and 3G of memory idle and 3 tasks running each consuming 1 cpu and 1G of memory. // Big task requiring 5 cpus and 5G of memory should preempt 2 of 3 running tasks to fit into the node. Pods: []*v1.Pod{ - util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", map[string]string{schedulingv1beta1.PodPreemptable: "true"}, make(map[string]string)), - util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", map[string]string{schedulingv1beta1.PodPreemptable: "true"}, make(map[string]string)), - util.BuildPod("c1", "preemptee3", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", map[string]string{schedulingv1beta1.PodPreemptable: "true"}, make(map[string]string)), - util.BuildPod("c1", "preemptor1", "", v1.PodPending, util.BuildResourceList("5", "5G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPreemptablePod("c1", "preemptee1", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPreemptablePod("c1", "preemptee2", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPreemptablePod("c1", "preemptee3", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptor1", "", v1.PodPending, "pg2", util.PodResourceOption("5", "5G")), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("6", "6G"), make(map[string]string)), diff --git a/pkg/scheduler/actions/reclaim/reclaim_test.go b/pkg/scheduler/actions/reclaim/reclaim_test.go index 5691ee1e810..32a26a8f2f6 100644 --- a/pkg/scheduler/actions/reclaim/reclaim_test.go +++ b/pkg/scheduler/actions/reclaim/reclaim_test.go @@ -85,10 +85,10 @@ func TestReclaim(t *testing.T) { }, }, Pods: []*v1.Pod{ - util.BuildPod("c1", "preemptee1", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", map[string]string{schedulingv1beta1.PodPreemptable: "true"}, make(map[string]string)), - util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptee3", "n1", v1.PodRunning, util.BuildResourceList("1", "1G"), "pg1", make(map[string]string), make(map[string]string)), - util.BuildPod("c1", "preemptor1", "", v1.PodPending, util.BuildResourceList("1", "1G"), "pg2", make(map[string]string), make(map[string]string)), + util.BuildPreemptablePod("c1", "preemptee1", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptee2", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptee3", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1G")), + util.BuildPod("c1", "preemptor1", "", v1.PodPending, "pg2", util.PodResourceOption("1", "1G")), }, Nodes: []*v1.Node{ util.BuildNode("n1", util.BuildResourceList("3", "3Gi"), make(map[string]string)), diff --git a/pkg/scheduler/actions/shuffle/shuffle_test.go b/pkg/scheduler/actions/shuffle/shuffle_test.go index 42b27dbdd30..88d2d2e4ae1 100644 --- a/pkg/scheduler/actions/shuffle/shuffle_test.go +++ b/pkg/scheduler/actions/shuffle/shuffle_test.go @@ -118,13 +118,13 @@ func TestShuffle(t *testing.T) { }, }, Pods: []*v1.Pod{ - util.BuildPodWithPriority("test", "pod1-1", "node1", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg1", make(map[string]string), make(map[string]string), &lowPriority), - util.BuildPodWithPriority("test", "pod1-2", "node1", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg1", make(map[string]string), make(map[string]string), &highPriority), - util.BuildPodWithPriority("test", "pod1-3", "node1", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg1", make(map[string]string), make(map[string]string), &highPriority), - util.BuildPodWithPriority("test", "pod2-1", "node1", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg2", make(map[string]string), make(map[string]string), &lowPriority), - util.BuildPodWithPriority("test", "pod2-2", "node2", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg2", make(map[string]string), make(map[string]string), &highPriority), - util.BuildPodWithPriority("test", "pod3-1", "node2", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg3", make(map[string]string), make(map[string]string), &lowPriority), - util.BuildPodWithPriority("test", "pod3-2", "node2", v1.PodRunning, util.BuildResourceList("1", "2G"), "pg3", make(map[string]string), make(map[string]string), &highPriority), + util.BuildPod("test", "pod1-1", "node1", v1.PodRunning, "pg1", util.PodResourceOption("1", "2G"), util.PodPriorityOption(lowPriority)), + util.BuildPod("test", "pod1-2", "node1", v1.PodRunning, "pg1", util.PodResourceOption("1", "2G"), util.PodPriorityOption(highPriority)), + util.BuildPod("test", "pod1-3", "node1", v1.PodRunning, "pg1", util.PodResourceOption("1", "2G"), util.PodPriorityOption(highPriority)), + util.BuildPod("test", "pod2-1", "node1", v1.PodRunning, "pg2", util.PodResourceOption("1", "2G"), util.PodPriorityOption(lowPriority)), + util.BuildPod("test", "pod2-2", "node2", v1.PodRunning, "pg2", util.PodResourceOption("1", "2G"), util.PodPriorityOption(highPriority)), + util.BuildPod("test", "pod3-1", "node2", v1.PodRunning, "pg3", util.PodResourceOption("1", "2G"), util.PodPriorityOption(lowPriority)), + util.BuildPod("test", "pod3-2", "node2", v1.PodRunning, "pg3", util.PodResourceOption("1", "2G"), util.PodPriorityOption(highPriority)), }, }, expected: 3, diff --git a/pkg/scheduler/plugins/binpack/binpack_test.go b/pkg/scheduler/plugins/binpack/binpack_test.go index 0105b3866ba..658c2d3581a 100644 --- a/pkg/scheduler/plugins/binpack/binpack_test.go +++ b/pkg/scheduler/plugins/binpack/binpack_test.go @@ -118,12 +118,10 @@ func TestNode(t *testing.T) { GPU := v1.ResourceName("nvidia.com/gpu") FOO := v1.ResourceName("example.com/foo") - p1 := util.BuildPod("c1", "p1", "n1", v1.PodPending, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p2 := util.BuildPod("c1", "p2", "n3", v1.PodPending, util.BuildResourceList("1.5", "0Gi"), "pg1", make(map[string]string), make(map[string]string)) - p3 := util.BuildPod("c1", "p3", "", v1.PodPending, util.BuildResourceList("2", "10Gi"), "pg1", make(map[string]string), make(map[string]string)) - addResource(p3.Spec.Containers[0].Resources.Requests, GPU, "2") - p4 := util.BuildPod("c1", "p4", "", v1.PodPending, util.BuildResourceList("3", "4Gi"), "pg1", make(map[string]string), make(map[string]string)) - addResource(p4.Spec.Containers[0].Resources.Requests, FOO, "3") + p1 := util.BuildPod("c1", "p1", "n1", v1.PodPending, "pg1", util.PodResourceOption("1", "1Gi")) + p2 := util.BuildPod("c1", "p2", "n3", v1.PodPending, "pg1", util.PodResourceOption("1.5", "0Gi")) + p3 := util.BuildPod("c1", "p3", "", v1.PodPending, "pg1", util.PodResourceWithGPUOption("2", "10Gi", "2")) + p4 := util.BuildPod("c1", "p4", "", v1.PodPending, "pg1", util.PodResourceWithGPUOption("3", "4Gi", "2")) n1 := util.BuildNode("n1", util.BuildResourceList("2", "4Gi"), make(map[string]string)) n2 := util.BuildNode("n2", util.BuildResourceList("4", "16Gi"), make(map[string]string)) diff --git a/pkg/scheduler/plugins/drf/hdrf_test.go b/pkg/scheduler/plugins/drf/hdrf_test.go index c4919f4042a..743feae193a 100644 --- a/pkg/scheduler/plugins/drf/hdrf_test.go +++ b/pkg/scheduler/plugins/drf/hdrf_test.go @@ -28,8 +28,7 @@ func makePods(num int, cpu, mem, podGroupName string) []*v1.Pod { for i := 0; i < num; i++ { pods = append(pods, util.BuildPod("default", fmt.Sprintf("%s-p%d", podGroupName, i), "", - v1.PodPending, util.BuildResourceList(cpu, mem), - podGroupName, make(map[string]string), make(map[string]string))) + v1.PodPending, podGroupName, util.PodResourceOption(cpu, mem))) } return pods } diff --git a/pkg/scheduler/plugins/predicates/predicates_test.go b/pkg/scheduler/plugins/predicates/predicates_test.go index 50541bae078..a3f73e1fb90 100644 --- a/pkg/scheduler/plugins/predicates/predicates_test.go +++ b/pkg/scheduler/plugins/predicates/predicates_test.go @@ -74,9 +74,9 @@ func TestEventHandler(t *testing.T) { schedulerCache := sc.(*cache.SchedulerCache) // pending pods - w1 := util.BuildPod("ns1", "worker-1", "", apiv1.PodPending, util.BuildResourceList("3", "3k"), "pg1", map[string]string{"role": "worker"}, map[string]string{"selector": "worker"}) - w2 := util.BuildPod("ns1", "worker-2", "", apiv1.PodPending, util.BuildResourceList("5", "5k"), "pg1", map[string]string{"role": "worker"}, map[string]string{}) - w3 := util.BuildPod("ns1", "worker-3", "", apiv1.PodPending, util.BuildResourceList("4", "4k"), "pg2", map[string]string{"role": "worker"}, map[string]string{}) + w1 := util.BuildWorkerPod("ns1", "worker-1", "", apiv1.PodPending, "pg1", util.PodResourceOption("3", "3k"), util.PodSelectorOption("selector", "worker")) + w2 := util.BuildWorkerPod("ns1", "worker-2", "", apiv1.PodPending, "pg1", util.PodResourceOption("5", "5k")) + w3 := util.BuildWorkerPod("ns1", "worker-3", "", apiv1.PodPending, "pg2", util.PodResourceOption("4", "4k")) w1.Spec.Affinity = getWorkerAffinity() w2.Spec.Affinity = getWorkerAffinity() w3.Spec.Affinity = getWorkerAffinity() diff --git a/pkg/scheduler/plugins/proportion/proportion_test.go b/pkg/scheduler/plugins/proportion/proportion_test.go index f7b4398b5c6..946e57ffa4e 100644 --- a/pkg/scheduler/plugins/proportion/proportion_test.go +++ b/pkg/scheduler/plugins/proportion/proportion_test.go @@ -121,9 +121,9 @@ func TestProportion(t *testing.T) { defer framework.CleanupPluginBuilders() // Running pods - w1 := util.BuildPod("ns1", "worker-1", "", apiv1.PodRunning, util.BuildResourceList("3", "3k"), "pg1", map[string]string{"role": "worker"}, map[string]string{"selector": "worker"}) - w2 := util.BuildPod("ns1", "worker-2", "", apiv1.PodRunning, util.BuildResourceList("5", "5k"), "pg1", map[string]string{"role": "worker"}, map[string]string{}) - w3 := util.BuildPod("ns1", "worker-3", "", apiv1.PodRunning, util.BuildResourceList("4", "4k"), "pg2", map[string]string{"role": "worker"}, map[string]string{}) + w1 := util.BuildWorkerPod("ns1", "worker-1", "", apiv1.PodRunning, "pg1", util.PodResourceOption("3", "3k"), util.PodSelectorOption("selector", "worker")) + w2 := util.BuildWorkerPod("ns1", "worker-2", "", apiv1.PodRunning, "pg1", util.PodResourceOption("5", "5k")) + w3 := util.BuildPod("ns1", "worker-3", "", apiv1.PodRunning, "pg2", util.PodResourceOption("4", "4k")) w1.Spec.Affinity = getWorkerAffinity() w2.Spec.Affinity = getWorkerAffinity() w3.Spec.Affinity = getWorkerAffinity() diff --git a/pkg/scheduler/plugins/tdm/tdm_test.go b/pkg/scheduler/plugins/tdm/tdm_test.go index 88c22486815..672dc9b3daa 100644 --- a/pkg/scheduler/plugins/tdm/tdm_test.go +++ b/pkg/scheduler/plugins/tdm/tdm_test.go @@ -118,9 +118,9 @@ func Test_TDM(t *testing.T) { framework.RegisterPluginBuilder(PluginName, New) defer framework.CleanupPluginBuilders() - p1 := util.BuildPod("c1", "p1", "", v1.PodPending, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p2 := util.BuildPod("c1", "p2", "", v1.PodPending, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p3 := util.BuildPod("c1", "p3", "", v1.PodPending, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) + p1 := util.BuildPod("c1", "p1", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1Gi")) + p2 := util.BuildPod("c1", "p2", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1Gi")) + p3 := util.BuildPod("c1", "p3", "", v1.PodPending, "pg1", util.PodResourceOption("1", "1Gi")) p1.Annotations[schedulingv2.RevocableZone] = "*" p3.Annotations[schedulingv2.RevocableZone] = "*" @@ -329,16 +329,16 @@ func Test_TDM_victimsFn(t *testing.T) { framework.RegisterPluginBuilder(PluginName, New) defer framework.CleanupPluginBuilders() - p1 := util.BuildPod("c1", "p1", "n1", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p2 := util.BuildPod("c1", "p2", "n1", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p3 := util.BuildPod("c1", "p3", "n1", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p4 := util.BuildPod("c1", "p4", "n1", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p5 := util.BuildPod("c1", "p5", "n1", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg1", make(map[string]string), make(map[string]string)) - p6 := util.BuildPod("c2", "p6", "n2", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg2", make(map[string]string), make(map[string]string)) - p7 := util.BuildPod("c2", "p7", "n2", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg2", make(map[string]string), make(map[string]string)) - p8 := util.BuildPod("c2", "p8", "n2", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg2", make(map[string]string), make(map[string]string)) - p9 := util.BuildPod("c2", "p9", "n2", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg2", make(map[string]string), make(map[string]string)) - p10 := util.BuildPod("c2", "p10", "n2", v1.PodRunning, util.BuildResourceList("1", "1Gi"), "pg2", make(map[string]string), make(map[string]string)) + p1 := util.BuildPod("c1", "p1", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1Gi")) + p2 := util.BuildPod("c1", "p2", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1Gi")) + p3 := util.BuildPod("c1", "p3", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1Gi")) + p4 := util.BuildPod("c1", "p4", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1Gi")) + p5 := util.BuildPod("c1", "p5", "n1", v1.PodRunning, "pg1", util.PodResourceOption("1", "1Gi")) + p6 := util.BuildPod("c2", "p6", "n2", v1.PodRunning, "pg2", util.PodResourceOption("1", "1Gi")) + p7 := util.BuildPod("c2", "p7", "n2", v1.PodRunning, "pg2", util.PodResourceOption("1", "1Gi")) + p8 := util.BuildPod("c2", "p8", "n2", v1.PodRunning, "pg2", util.PodResourceOption("1", "1Gi")) + p9 := util.BuildPod("c2", "p9", "n2", v1.PodRunning, "pg2", util.PodResourceOption("1", "1Gi")) + p10 := util.BuildPod("c2", "p10", "n2", v1.PodRunning, "pg2", util.PodResourceOption("1", "1Gi")) p1.Annotations[schedulingv2.PodPreemptable] = "true" p2.Annotations[schedulingv2.PodPreemptable] = "true" diff --git a/pkg/scheduler/util/test_utils.go b/pkg/scheduler/util/test_utils.go index b9b05315123..ae5ff357019 100644 --- a/pkg/scheduler/util/test_utils.go +++ b/pkg/scheduler/util/test_utils.go @@ -69,43 +69,68 @@ func BuildNode(name string, alloc v1.ResourceList, labels map[string]string) *v1 } } -// BuildPod builds a Burstable pod object -func BuildPod(namespace, name, nodeName string, p v1.PodPhase, req v1.ResourceList, groupName string, labels map[string]string, selector map[string]string) *v1.Pod { - return &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: types.UID(fmt.Sprintf("%v-%v", namespace, name)), - Name: name, - Namespace: namespace, - Labels: labels, - Annotations: map[string]string{ - schedulingv2.KubeGroupNameAnnotationKey: groupName, +type PodOption = func(*v1.Pod) + +func PodResourceOption(cpu string, memory string) PodOption { + return func(pod *v1.Pod) { + pod.Spec.Containers[0].Resources.Requests = BuildResourceList(cpu, memory) + } +} + +func PodResourceWithGPUOption(cpu, memory, gpu string) PodOption { + return func(pod *v1.Pod) { + pod.Spec.Containers[0].Resources.Requests = BuildResourceListWithGPU(cpu, memory, gpu) + } +} + +func PodLabelOption(k, v string) PodOption { + return func(pod *v1.Pod) { + pod.Labels[k] = v + } +} + +func PodSelectorOption(k, v string) PodOption { + return func(pod *v1.Pod) { + pod.Spec.NodeSelector[k] = v + } +} + +func PodPriorityOption(priority int32) PodOption { + return func(pod *v1.Pod) { + pod.Spec.Priority = &priority + } +} + +func PodPVCOption(pvc *v1.PersistentVolumeClaim) PodOption { + return func(pod *v1.Pod) { + pod.Spec.Containers[0].VolumeMounts = []v1.VolumeMount{ + { + Name: pvc.Name, + MountPath: "/data", }, - }, - Status: v1.PodStatus{ - Phase: p, - }, - Spec: v1.PodSpec{ - NodeName: nodeName, - NodeSelector: selector, - Containers: []v1.Container{ - { - Resources: v1.ResourceRequirements{ - Requests: req, + } + + pod.Spec.Volumes = []v1.Volume{ + { + Name: pvc.Name, + VolumeSource: v1.VolumeSource{ + PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ + ClaimName: pvc.Name, }, }, }, - }, + } } } -// BuildPodWithPVC builts Pod object with pvc volume -func BuildPodWithPVC(namespace, name, nodename string, p v1.PodPhase, req v1.ResourceList, pvc *v1.PersistentVolumeClaim, groupName string, labels map[string]string, selector map[string]string) *v1.Pod { - return &v1.Pod{ +// BuildPod builds a Burstable pod object +func BuildPod(namespace, name, nodeName string, p v1.PodPhase, groupName string, opts ...PodOption) *v1.Pod { + pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ UID: types.UID(fmt.Sprintf("%v-%v", namespace, name)), Name: name, Namespace: namespace, - Labels: labels, + Labels: map[string]string{}, Annotations: map[string]string{ schedulingv2.KubeGroupNameAnnotationKey: groupName, }, @@ -114,33 +139,32 @@ func BuildPodWithPVC(namespace, name, nodename string, p v1.PodPhase, req v1.Res Phase: p, }, Spec: v1.PodSpec{ - NodeName: nodename, - NodeSelector: selector, + NodeName: nodeName, + NodeSelector: map[string]string{}, Containers: []v1.Container{ { Resources: v1.ResourceRequirements{ - Requests: req, - }, - VolumeMounts: []v1.VolumeMount{ - { - Name: pvc.Name, - MountPath: "/data", - }, - }, - }, - }, - Volumes: []v1.Volume{ - { - Name: pvc.Name, - VolumeSource: v1.VolumeSource{ - PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ - ClaimName: pvc.Name, - }, + Requests: v1.ResourceList{}, }, }, }, }, } + + for _, opt := range opts { + opt(pod) + } + return pod +} + +func BuildPreemptablePod(namespace, name, nodeName string, p v1.PodPhase, groupName string, opts ...PodOption) *v1.Pod { + opts = append(opts, PodLabelOption(schedulingv2.PodPreemptable, "true")) + return BuildPod(namespace, name, nodeName, p, groupName, opts...) +} + +func BuildWorkerPod(namespace, name, nodeName string, p v1.PodPhase, groupName string, opts ...PodOption) *v1.Pod { + opts = append(opts, PodLabelOption("role", "worker")) + return BuildPod(namespace, name, nodeName, p, groupName, opts...) } // BuildDynamicPVC create pv pvc and storage class @@ -195,62 +219,8 @@ func BuildDynamicPVC(namespace, name string, req v1.ResourceList) (*v1.Persisten } // BuildBestEffortPod builds a BestEffort pod object -func BuildBestEffortPod(namespace, name, nodeName string, p v1.PodPhase, groupName string, labels map[string]string, selector map[string]string) *v1.Pod { - return &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: types.UID(fmt.Sprintf("%v-%v", namespace, name)), - Name: name, - Namespace: namespace, - Labels: labels, - Annotations: map[string]string{ - schedulingv2.KubeGroupNameAnnotationKey: groupName, - }, - }, - Status: v1.PodStatus{ - Phase: p, - }, - Spec: v1.PodSpec{ - NodeName: nodeName, - NodeSelector: selector, - Containers: []v1.Container{ - { - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{}, - }, - }, - }, - }, - } -} - -// BuildPodWithPriority builds a pod object with priority -func BuildPodWithPriority(namespace, name, nodeName string, p v1.PodPhase, req v1.ResourceList, groupName string, labels map[string]string, selector map[string]string, priority *int32) *v1.Pod { - return &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: types.UID(fmt.Sprintf("%v-%v", namespace, name)), - Name: name, - Namespace: namespace, - Labels: labels, - Annotations: map[string]string{ - schedulingv2.KubeGroupNameAnnotationKey: groupName, - }, - }, - Status: v1.PodStatus{ - Phase: p, - }, - Spec: v1.PodSpec{ - NodeName: nodeName, - NodeSelector: selector, - Priority: priority, - Containers: []v1.Container{ - { - Resources: v1.ResourceRequirements{ - Requests: req, - }, - }, - }, - }, - } +func BuildBestEffortPod(namespace, name, nodeName string, p v1.PodPhase, groupName string, opts ...PodOption) *v1.Pod { + return BuildPod(namespace, name, nodeName, p, groupName, opts...) } // FakeBinder is used as fake binder