-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.go
49 lines (38 loc) · 923 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
40
41
42
43
44
45
46
47
48
49
package api
import (
"sort"
"k8s.io/kubernetes/pkg/api/unversioned"
)
type tag struct {
Name string
Created unversioned.Time
}
type byCreationTimestamp []tag
func (t byCreationTimestamp) Len() int {
return len(t)
}
func (t byCreationTimestamp) Less(i, j int) bool {
return t[i].Created.Time.After(t[j].Created.Time)
}
func (t byCreationTimestamp) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
// SortStatusTags sorts the status tags of an image stream based on
// the latest created
func SortStatusTags(tags map[string]TagEventList) []string {
tagSlice := make([]tag, len(tags))
index := 0
for tag, list := range tags {
tagSlice[index].Name = tag
if len(list.Items) > 0 {
tagSlice[index].Created = list.Items[0].Created
}
index++
}
sort.Sort(byCreationTimestamp(tagSlice))
actual := make([]string, len(tagSlice))
for i, tag := range tagSlice {
actual[i] = tag.Name
}
return actual
}