Skip to content

Commit 783cfbd

Browse files
manirajv06pbacsko
authored andcommitted
[YUNIKORN-3188] Skip ph released allocations in daemon set preemption (#1057)
Closes: #1057 Signed-off-by: mani <manirajv06@gmail.com> (cherry picked from commit 63eae06)
1 parent 70fc74f commit 783cfbd

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

pkg/scheduler/objects/application.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,8 @@ func (sa *Application) tryRequiredNodePreemption(reserve *reservation, ask *Allo
14381438
zap.Int("requiredNode allocations", result.requiredNodeAllocations),
14391439
zap.Int("allocations already preempted", result.alreadyPreemptedAllocations),
14401440
zap.Int("higher priority allocations", result.higherPriorityAllocations),
1441-
zap.Int("allocations with non-matching resources", result.atLeastOneResNotMatched))
1441+
zap.Int("allocations with non-matching resources", result.atLeastOneResNotMatched),
1442+
zap.Int("released placeholder allocations", result.releasedPhAllocations))
14421443
return false
14431444
}
14441445

pkg/scheduler/objects/required_node_preemptor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type filteringResult struct {
3434
atLeastOneResNotMatched int // number of allocations where there's no single resource type that would match
3535
higherPriorityAllocations int // number of allocations with higher priority
3636
alreadyPreemptedAllocations int // number of allocations already preempted
37+
releasedPhAllocations int // number of ph allocations released
3738
}
3839

3940
func NewRequiredNodePreemptor(node *Node, requiredAsk *Allocation) *PreemptionContext {
@@ -73,6 +74,13 @@ func (p *PreemptionContext) filterAllocations() filteringResult {
7374
result.atLeastOneResNotMatched++
7475
continue
7576
}
77+
78+
// skip placeholder tasks which are marked released
79+
if allocation.IsReleased() {
80+
result.releasedPhAllocations++
81+
continue
82+
}
83+
7684
p.allocations = append(p.allocations, allocation)
7785
}
7886

pkg/scheduler/objects/required_node_preemptor_test.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestFilterAllocations(t *testing.T) {
4242
p := NewRequiredNodePreemptor(node, requiredAsk)
4343
asks := prepareAllocationAsks(t, node)
4444
result := p.filterAllocations()
45-
verifyFilterResult(t, 10, 0, 10, 0, 0, result)
45+
verifyFilterResult(t, 10, 0, 10, 0, 0, 0, result)
4646
filteredAllocations := p.getAllocations()
4747

4848
// allocations are not even considered as there is no match. of course, no victims
@@ -55,7 +55,7 @@ func TestFilterAllocations(t *testing.T) {
5555
p1 := NewRequiredNodePreemptor(node, requiredAsk1)
5656
asks = prepareAllocationAsks(t, node)
5757
result = p1.filterAllocations()
58-
verifyFilterResult(t, 10, 0, 0, 10, 0, result)
58+
verifyFilterResult(t, 10, 0, 0, 10, 0, 0, result)
5959
filteredAllocations = p.getAllocations()
6060

6161
// allocations are not even considered as there is no match. of course, no victims
@@ -68,38 +68,44 @@ func TestFilterAllocations(t *testing.T) {
6868
p2 := NewRequiredNodePreemptor(node, requiredAsk2)
6969
asks = prepareAllocationAsks(t, node)
7070
result = p2.filterAllocations()
71-
verifyFilterResult(t, 10, 0, 0, 0, 0, result)
71+
verifyFilterResult(t, 10, 0, 0, 0, 0, 0, result)
7272
filteredAllocations = p2.getAllocations()
7373
assert.Equal(t, len(filteredAllocations), 10)
7474
removeAllocationAsks(node, asks)
7575

7676
// case 4: allocation has been preempted
77-
requiredAsk3 := createAllocationAsk("ask12", "app1", true, true, 20,
78-
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
79-
p3 := NewRequiredNodePreemptor(node, requiredAsk3)
77+
p3 := NewRequiredNodePreemptor(node, requiredAsk2)
8078
asks = prepareAllocationAsks(t, node)
8179
node.GetAllocation("ask5").MarkPreempted() // "ask5" would be the first and only victim without this
8280
result = p3.filterAllocations()
8381
p3.sortAllocations()
8482

85-
verifyFilterResult(t, 10, 0, 0, 0, 1, result)
83+
verifyFilterResult(t, 10, 0, 0, 0, 1, 0, result)
8684
filteredAllocations = p3.getAllocations()
8785
assert.Equal(t, len(filteredAllocations), 9) // "ask5" is no longer considered as a victim
8886
removeAllocationAsks(node, asks)
8987

9088
// case 5: existing required node allocation
91-
requiredAsk4 := createAllocationAsk("ask12", "app1", true, true, 20,
92-
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
93-
p4 := NewRequiredNodePreemptor(node, requiredAsk4)
94-
_ = prepareAllocationAsks(t, node)
95-
allocReqNode := createAllocation("ask11", "app1", node.NodeID, true, true, 5, true,
96-
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
97-
assert.Assert(t, node.TryAddAllocation(allocReqNode))
89+
p4 := NewRequiredNodePreemptor(node, requiredAsk2)
90+
results := prepareAllocationAsks(t, node)
91+
results[8].requiredNode = "node-3"
9892

9993
result = p4.filterAllocations()
100-
verifyFilterResult(t, 11, 1, 0, 0, 0, result)
94+
verifyFilterResult(t, 10, 1, 0, 0, 0, 0, result)
10195
filteredAllocations = p4.getAllocations()
102-
assert.Equal(t, len(filteredAllocations), 10)
96+
assert.Equal(t, len(filteredAllocations), 9)
97+
removeAllocationAsks(node, asks)
98+
99+
// case 6: release ph allocation
100+
p5 := NewRequiredNodePreemptor(node, requiredAsk2)
101+
results = prepareAllocationAsks(t, node)
102+
results[9].released = true
103+
104+
result = p5.filterAllocations()
105+
verifyFilterResult(t, 10, 0, 0, 0, 0, 1, result)
106+
filteredAllocations = p5.getAllocations()
107+
assert.Equal(t, len(filteredAllocations), 9)
108+
removeAllocationAsks(node, asks)
103109
}
104110

105111
func TestGetVictims(t *testing.T) {
@@ -160,11 +166,12 @@ func TestGetVictims(t *testing.T) {
160166
removeAllocationAsks(node, asks)
161167
}
162168

163-
func verifyFilterResult(t *testing.T, totalAllocations, requiredNodeAllocations, resourceNotEnough, higherPriorityAllocations, alreadyPreemptedAllocations int, result filteringResult) {
169+
func verifyFilterResult(t *testing.T, totalAllocations, requiredNodeAllocations, resourceNotEnough, higherPriorityAllocations, alreadyPreemptedAllocations int, releasedPhAllocations int, result filteringResult) {
164170
t.Helper()
165171
assert.Equal(t, totalAllocations, result.totalAllocations)
166172
assert.Equal(t, requiredNodeAllocations, result.requiredNodeAllocations)
167173
assert.Equal(t, resourceNotEnough, result.atLeastOneResNotMatched)
168174
assert.Equal(t, higherPriorityAllocations, result.higherPriorityAllocations)
169175
assert.Equal(t, alreadyPreemptedAllocations, result.alreadyPreemptedAllocations)
176+
assert.Equal(t, releasedPhAllocations, result.releasedPhAllocations)
170177
}

0 commit comments

Comments
 (0)