-
Notifications
You must be signed in to change notification settings - Fork 127
/
scheduling.go
67 lines (62 loc) · 2.51 KB
/
scheduling.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package types
import (
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)
type AwayNodeType struct {
// Priority is the priority class priority that the scheduler should use
// when scheduling "away" jobs of this priority class on the the node type
// referenced by WellKnownNodeTypeName; it overrides the Priority field of
// PriorityClass.
Priority int32 `validate:"gte=0"`
// WellKnownNodeTypeName is the Name of the WellKnownNodeType in question.
WellKnownNodeTypeName string `validate:"required"`
}
type PriorityClass struct {
Priority int32 `validate:"gte=0"`
// If true, Armada may preempt jobs of this class to improve fairness.
Preemptible bool
// Limits resources assigned to jobs of this priority class.
// Specifically, jobs of this priority class are only scheduled if doing so does not exceed this limit.
MaximumResourceFractionPerQueue map[string]float64
// Per-pool override of MaximumResourceFractionPerQueue.
// If missing for a particular pool, MaximumResourceFractionPerQueue is used instead for that pool.
MaximumResourceFractionPerQueueByPool map[string]map[string]float64
// AwayNodeTypes is the set of node types that jobs of this priority class
// can be scheduled on as "away" jobs (i.e., with reduced priority).
//
// The scheduler first tries to schedule jobs of this priority class as
// "home" jobs, and then tries the elements of this slice in order.
AwayNodeTypes []AwayNodeType `validate:"dive"`
}
func (priorityClass PriorityClass) Equal(other PriorityClass) bool {
if priorityClass.Priority != other.Priority {
return false
}
if priorityClass.Preemptible != other.Preemptible {
return false
}
if !maps.Equal(priorityClass.MaximumResourceFractionPerQueue, other.MaximumResourceFractionPerQueue) {
return false
}
if len(priorityClass.MaximumResourceFractionPerQueueByPool) != len(other.MaximumResourceFractionPerQueueByPool) {
return false
}
for k, v := range priorityClass.MaximumResourceFractionPerQueueByPool {
if !maps.Equal(v, other.MaximumResourceFractionPerQueueByPool[k]) {
return false
}
}
return true
}
func AllowedPriorities(priorityClasses map[string]PriorityClass) []int32 {
allowedPriorities := make([]int32, 0, len(priorityClasses))
for _, priorityClass := range priorityClasses {
allowedPriorities = append(allowedPriorities, priorityClass.Priority)
for _, awayNodeType := range priorityClass.AwayNodeTypes {
allowedPriorities = append(allowedPriorities, awayNodeType.Priority)
}
}
slices.Sort(allowedPriorities)
return slices.Compact(allowedPriorities)
}