Skip to content

Commit

Permalink
rewrite build pod
Browse files Browse the repository at this point in the history
  • Loading branch information
kingeasternsun committed Jul 19, 2023
1 parent 4817c8e commit 8e08d07
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 166 deletions.
24 changes: 12 additions & 12 deletions pkg/scheduler/actions/allocate/allocate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down
30 changes: 15 additions & 15 deletions pkg/scheduler/actions/preempt/preempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)),
Expand Down
8 changes: 4 additions & 4 deletions pkg/scheduler/actions/reclaim/reclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
14 changes: 7 additions & 7 deletions pkg/scheduler/actions/shuffle/shuffle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions pkg/scheduler/plugins/binpack/binpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions pkg/scheduler/plugins/drf/hdrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/scheduler/plugins/predicates/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions pkg/scheduler/plugins/proportion/proportion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 8e08d07

Please sign in to comment.