@@ -42,15 +42,18 @@ import (
42
42
"sigs.k8s.io/cluster-api/util/conversion"
43
43
)
44
44
45
+ // Sort functions in this file, use these constants to determine the sorting order
45
46
const (
47
+ // Used to sort elements in Ascending order
48
+ // Also used in cases, where the order is from older to newer occurances
46
49
ASCENDING = iota
50
+
51
+ // Used to sort elements in Descending order
52
+ // Also used in cases, where the order is from newer to older occurances
47
53
DESCENDING
48
- OLD_TO_NEW
49
- NEW_TO_OLD
50
54
)
51
55
52
- // MachineSetsByCreationTimestamp sorts a list of MachineSet by creation timestamp, using their names as a tie breaker.
53
- // type MachineSetsByCreationTimestamp []*clusterv1.MachineSet
56
+ // SortByCreationTimestamp sorts a list of MachineSet by creation timestamp, using their names as a tie breaker.
54
57
func SortByCreationTimestamp (a , b * clusterv1.MachineSet , order int ) int {
55
58
if b .CreationTimestamp .Equal (& a .CreationTimestamp ) {
56
59
if b .Name > a .Name {
@@ -81,28 +84,27 @@ func SortByCreationTimestamp(a, b *clusterv1.MachineSet, order int) int {
81
84
}
82
85
83
86
// SortBySize sorts a list of MachineSet by size in descending order, using their creation timestamp or name as a tie breaker.
84
- // By using the creation timestamp, this sorts from old to new machine sets if order is OLD_TO_NEW or new to old machine sets if order is NEW_TO_OLD .
87
+ // By using the creation timestamp, this sorts from old to new machine sets if order is ASCENDING or new to old machine sets if order is DESCENDING .
85
88
func SortBySize (a , b * clusterv1.MachineSet , order int ) int {
86
89
if * (a .Spec .Replicas ) == * (b .Spec .Replicas ) {
87
- if order == OLD_TO_NEW {
90
+ if order == ASCENDING {
88
91
if a .CreationTimestamp .Before (& b .CreationTimestamp ) {
89
92
return - 1
90
93
}
91
94
return 1
92
- } else {
93
- if b .CreationTimestamp .Before (& a .CreationTimestamp ) {
94
- return - 1
95
- }
96
- return 1
97
95
}
96
+ if b .CreationTimestamp .Before (& a .CreationTimestamp ) {
97
+ return - 1
98
+ }
99
+ return 1
98
100
}
99
101
if * (a .Spec .Replicas ) > * (b .Spec .Replicas ) {
100
102
return - 1
101
103
}
102
104
return 1
103
105
}
104
106
105
- // MachineSetsByDecreasingReplicas sorts the list of MachineSets in decreasing order of replicas,
107
+ // SortByDecreasingReplicas sorts the list of MachineSets in decreasing order of replicas,
106
108
// using creation time (ascending order) and name (alphabetical) as tie breakers.
107
109
func SortByDecreasingReplicas (a , b * clusterv1.MachineSet ) int {
108
110
if a .Spec .Replicas == nil {
0 commit comments