From 619401f7822bfb284b6f8a788123748e72ddb08e Mon Sep 17 00:00:00 2001 From: Hanyu Zhao Date: Wed, 27 Nov 2019 09:53:04 +0800 Subject: [PATCH] HiveD: fix bug in initial assignment validation (#3908) * fix bug in initial assignment validation * add tests for quota validation and lazy preemption --- pkg/algorithm/hived_algorithm.go | 9 ++++++++- pkg/algorithm/hived_algorithm_test.go | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/algorithm/hived_algorithm.go b/pkg/algorithm/hived_algorithm.go index 6bb7783..76d9bcc 100644 --- a/pkg/algorithm/hived_algorithm.go +++ b/pkg/algorithm/hived_algorithm.go @@ -266,7 +266,7 @@ func (h *HivedAlgorithm) DeleteAllocatedPod(pod *core.Pod) { // to all VCs can be fit into the configured physical cells. func (h *HivedAlgorithm) validateInitialAssignment() { totalQuota := map[CellChain]map[CellLevel]int32{} - for _, vcs := range h.vcSchedulers { + for vc, vcs := range h.vcSchedulers { for chain, ccl := range vcs.getNonReservedCellList() { if totalQuota[chain] == nil { totalQuota[chain] = map[CellLevel]int32{} @@ -274,6 +274,13 @@ func (h *HivedAlgorithm) validateInitialAssignment() { l := CellLevel(len(ccl)) totalQuota[chain][l] += int32(len(ccl[l])) } + for _, reserved := range h.reservedCells[vc] { + reservedChain := reserved.GetChain() + if totalQuota[reservedChain] == nil { + totalQuota[reservedChain] = map[CellLevel]int32{} + } + totalQuota[reservedChain][reserved.GetLevel()]++ + } } for chain, chainQuota := range totalQuota { if ccl := h.fullCellList[chain]; ccl == nil { diff --git a/pkg/algorithm/hived_algorithm_test.go b/pkg/algorithm/hived_algorithm_test.go index 29f1650..fd8fb15 100644 --- a/pkg/algorithm/hived_algorithm_test.go +++ b/pkg/algorithm/hived_algorithm_test.go @@ -62,7 +62,7 @@ func initNodes(h *HivedAlgorithm) { } } -var group1, group2, group3, group4, group5, group6, group7, group8, group9, group10, group11, group12, group13, group14, group15, group16 = &api.AffinityGroupSpec{ +var group1, group2, group3, group4, group5, group6, group7, group8, group9, group10, group11, group12, group13, group14, group15, group16, group17 = &api.AffinityGroupSpec{ Name: "group1", Members: []api.AffinityGroupMemberSpec{{PodNumber: 1, GpuNumber: 1}}, }, &api.AffinityGroupSpec{ @@ -110,6 +110,9 @@ var group1, group2, group3, group4, group5, group6, group7, group8, group9, grou }, &api.AffinityGroupSpec{ Name: "group16", Members: []api.AffinityGroupMemberSpec{{PodNumber: 1, GpuNumber: 2}}, +}, &api.AffinityGroupSpec{ + Name: "group17", + Members: []api.AffinityGroupMemberSpec{{PodNumber: 1, GpuNumber: 2}}, } var pss = map[types.UID]api.PodSchedulingSpec{ @@ -308,11 +311,19 @@ var pss = map[types.UID]api.PodSchedulingSpec{ }, "pod25": { // trigger intra-VC preemption VirtualCluster: "VC2", Priority: 1, - LazyPreemptionEnable: true, + LazyPreemptionEnable: false, ReservationId: "", GpuType: "CT1", GpuNumber: 2, AffinityGroup: group16, + }, "pod26": { // will preempt pod25 immediately (as lazy preemption is not enabled) + VirtualCluster: "VC2", + Priority: 2, + LazyPreemptionEnable: false, + ReservationId: "", + GpuType: "CT1", + GpuNumber: 2, + AffinityGroup: group17, }, } @@ -355,6 +366,7 @@ var expectedBindInfos = map[string]result{ var expectedPreemptInfos = map[string]common.Set{ "pod16": common.NewSet("pod5", "pod6"), "pod17": common.NewSet("pod5", "pod6"), + "pod26": common.NewSet("pod25"), } var allocatedPods []*core.Pod @@ -513,7 +525,9 @@ func testInvalidInitialAssignment(t *testing.T, sConfig *api.Config) { t.Errorf("Expected error in initial assignment validation, but got none") } }() - (*sConfig.VirtualClusters)["VC2"].VirtualCells[0].CellNumber = 1000 + (*sConfig.VirtualClusters)["VC1"].VirtualCells[0].CellType = "CT1-NODE" + (*sConfig.VirtualClusters)["VC1"].VirtualCells[1].CellType = "CT1-NODE.CT1" + (*sConfig.VirtualClusters)["VC1"].VirtualCells[1].CellNumber = 2 NewHivedAlgorithm(sConfig) }