HiveD: fix bug in initial assignment validation (#3908)

* fix bug in initial assignment validation

* add tests for quota validation and lazy preemption
This commit is contained in:
Hanyu Zhao 2019-11-27 09:53:04 +08:00 коммит произвёл GitHub
Родитель da6bce75e4
Коммит 619401f782
2 изменённых файлов: 25 добавлений и 4 удалений

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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)
}