Skip to content

Commit

Permalink
[YUNIKORN-2661] Fix hard-coded boolean in setLimit (#883)
Browse files Browse the repository at this point in the history
Closes: #883

Signed-off-by: Peter Bacsko <[email protected]>
(cherry picked from commit 1aafed0)
  • Loading branch information
pbacsko committed Jun 24, 2024
1 parent 3466272 commit 4834b19
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/scheduler/ugm/queue_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (qt *QueueTracker) setLimit(hierarchy []string, maxResource *resources.Reso
if qt.childQueueTrackers[childName] == nil {
qt.childQueueTrackers[childName] = newQueueTracker(qt.queuePath, childName, trackType)
}
qt.childQueueTrackers[childName].setLimit(hierarchy[1:], maxResource, maxApps, useWildCard, trackType, false)
qt.childQueueTrackers[childName].setLimit(hierarchy[1:], maxResource, maxApps, useWildCard, trackType, doWildCardCheck)
} else if len(hierarchy) == 1 {
// don't override named user/group specific limits with wild card limits
if doWildCardCheck && !qt.useWildCard {
Expand Down
55 changes: 55 additions & 0 deletions pkg/scheduler/ugm/queue_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,61 @@ func TestNewQueueTracker(t *testing.T) {
assert.Assert(t, resources.IsZero(parent.resourceUsage))
}

func TestSetLimit(t *testing.T) {
manager := GetUserManager()
defer manager.ClearConfigLimits()
manager.userWildCardLimitsConfig = map[string]*LimitConfig{
path1: {
maxApplications: 3,
maxResources: resources.NewResource(),
},
}
root := newRootQueueTracker(user)
assert.Assert(t, !root.useWildCard)
assert.Equal(t, uint64(0), root.maxRunningApps)
assert.Assert(t, root.maxResources == nil)

// create tracker hierarchy
limit := resources.NewResourceFromMap(map[string]resources.Quantity{
"mem": 10,
"vcore": 10})
root.setLimit(strings.Split(queuePath1, configs.DOT), limit.Clone(), 9, true, user, true)

// check settings
parentQ := root.childQueueTrackers["parent"]
assert.Assert(t, parentQ.maxResources == nil)
assert.Equal(t, uint64(0), parentQ.maxRunningApps)
childQ := parentQ.childQueueTrackers["child1"]
assert.Assert(t, parentQ.maxResources == nil)
assert.Equal(t, uint64(9), childQ.maxRunningApps)
assert.Assert(t, resources.Equals(limit, childQ.maxResources))

// check if settings are overridden
newLimit := resources.NewResourceFromMap(map[string]resources.Quantity{
"mem": 20,
"vcore": 20})
root.setLimit(strings.Split(queuePath1, configs.DOT), newLimit.Clone(), 3, false, user, true) // override
assert.Assert(t, resources.Equals(newLimit, childQ.maxResources))
assert.Assert(t, !childQ.useWildCard)
newLimit2 := resources.NewResourceFromMap(map[string]resources.Quantity{
"mem": 30,
"vcore": 30})
root.setLimit(strings.Split(queuePath1, configs.DOT), newLimit2.Clone(), 2, true, user, true) // no override
assert.Assert(t, !childQ.useWildCard)
assert.Assert(t, resources.Equals(newLimit, childQ.maxResources))
assert.Equal(t, uint64(3), childQ.maxRunningApps)

root.setLimit(strings.Split(queuePath1, configs.DOT), newLimit2.Clone(), 4, true, user, false) // override -> changes qt.doWildCardCheck
assert.Assert(t, childQ.useWildCard)
assert.Assert(t, resources.Equals(newLimit2, childQ.maxResources))
assert.Equal(t, uint64(4), childQ.maxRunningApps)

root.setLimit(strings.Split(queuePath1, configs.DOT), newLimit.Clone(), 5, false, user, false) // override
assert.Assert(t, !childQ.useWildCard)
assert.Assert(t, resources.Equals(newLimit, childQ.maxResources))
assert.Equal(t, uint64(5), childQ.maxRunningApps)
}

func getQTResource(qt *QueueTracker) map[string]*resources.Resource {
resources := make(map[string]*resources.Resource)
usage := qt.getResourceUsageDAOInfo("")
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/ugm/user_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ func TestSetAndClearMaxLimits(t *testing.T) {

// clear limits
eventSystem.Reset()
userTracker.clearLimits(path1, true)
userTracker.clearLimits(path1, false)
assert.Assert(t, resources.Equals(userTracker.headroom(hierarchy1), lowerParentHeadroom))
assert.Assert(t, resources.Equals(userTracker.headroom(hierarchy5), lowerParentHeadroom))
assert.Assert(t, !userTracker.canRunApp(hierarchy1, TestApp4))
assert.Assert(t, !userTracker.canRunApp(hierarchy5, TestApp4))
userTracker.clearLimits(path5, true)
userTracker.clearLimits(path5, false)
assert.Assert(t, userTracker.headroom(hierarchy1) == nil)
assert.Assert(t, userTracker.headroom(hierarchy5) == nil)
assert.Assert(t, userTracker.canRunApp(hierarchy1, TestApp4))
Expand Down

0 comments on commit 4834b19

Please sign in to comment.