-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscheduler_selector.go
49 lines (42 loc) · 1.3 KB
/
scheduler_selector.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
package prophet
// Selector is an interface to select source and target container to schedule.
type Selector interface {
SelectSource(containers []*ContainerRuntime, filters ...Filter) *ContainerRuntime
SelectTarget(containers []*ContainerRuntime, filters ...Filter) *ContainerRuntime
}
type balanceSelector struct {
kind ResourceKind
filters []Filter
}
func newBalanceSelector(kind ResourceKind, filters []Filter) *balanceSelector {
return &balanceSelector{
kind: kind,
filters: filters,
}
}
func (s *balanceSelector) SelectSource(containers []*ContainerRuntime, filters ...Filter) *ContainerRuntime {
filters = append(filters, s.filters...)
var result *ContainerRuntime
for _, container := range containers {
if filterSource(container, filters) {
continue
}
if result == nil || result.ResourceScore(s.kind) < container.ResourceScore(s.kind) {
result = container
}
}
return result
}
func (s *balanceSelector) SelectTarget(containers []*ContainerRuntime, filters ...Filter) *ContainerRuntime {
filters = append(filters, s.filters...)
var result *ContainerRuntime
for _, container := range containers {
if filterTarget(container, filters) {
continue
}
if result == nil || result.ResourceScore(s.kind) > container.ResourceScore(s.kind) {
result = container
}
}
return result
}