-
Notifications
You must be signed in to change notification settings - Fork 57
/
sort.go
39 lines (29 loc) · 1006 Bytes
/
sort.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
package controller
import "k8s.io/api/core/v1"
// nodeIndexBundle bundles an original index to a node so that it can be tracked during sorting
type nodeIndexBundle struct {
node *v1.Node
index int
}
// nodesByOldestCreationTime Sort functions for sorting by creation time
type nodesByOldestCreationTime []nodeIndexBundle
func (n nodesByOldestCreationTime) Len() int {
return len(n)
}
func (n nodesByOldestCreationTime) Less(i, j int) bool {
return n[i].node.CreationTimestamp.Before(&n[j].node.CreationTimestamp)
}
func (n nodesByOldestCreationTime) Swap(i, j int) {
n[i], n[j] = n[j], n[i]
}
// nodesByNewestCreationTime Sort functions for sorting by creation time
type nodesByNewestCreationTime []nodeIndexBundle
func (n nodesByNewestCreationTime) Len() int {
return len(n)
}
func (n nodesByNewestCreationTime) Less(i, j int) bool {
return n[j].node.CreationTimestamp.Before(&n[i].node.CreationTimestamp)
}
func (n nodesByNewestCreationTime) Swap(i, j int) {
n[i], n[j] = n[j], n[i]
}