Skip to content

Commit 013ff86

Browse files
authored
Merge pull request #6111 from praveenrewar/main
🌱 Make MachinesByCreationTimestamp private to machine collections
2 parents adb9a63 + 7e2721d commit 013ff86

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

docs/book/src/developer/providers/v1.1-to-v1.2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ in ClusterAPI are kept in sync with the versions used by `sigs.k8s.io/controller
1818

1919
### Deprecation
2020

21-
-
21+
* `util.MachinesByCreationTimestamp` has been deprecated and will be removed in a future release.
2222

2323
### Removals
2424

util/collections/machine_collection.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"github.com/blang/semver"
3434

3535
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
36-
"sigs.k8s.io/cluster-api/util"
3736
"sigs.k8s.io/cluster-api/util/conditions"
3837
"sigs.k8s.io/cluster-api/util/version"
3938
)
@@ -57,6 +56,18 @@ func (v machinesByVersion) Less(i, j int) bool {
5756
return comp == -1
5857
}
5958

59+
// machinesByCreationTimestamp sorts a list of Machine by creation timestamp, using their names as a tie breaker.
60+
type machinesByCreationTimestamp []*clusterv1.Machine
61+
62+
func (o machinesByCreationTimestamp) Len() int { return len(o) }
63+
func (o machinesByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
64+
func (o machinesByCreationTimestamp) Less(i, j int) bool {
65+
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
66+
return o[i].Name < o[j].Name
67+
}
68+
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
69+
}
70+
6071
// New creates an empty Machines.
6172
func New() Machines {
6273
return make(Machines)
@@ -107,7 +118,7 @@ func (s Machines) Difference(machines Machines) Machines {
107118

108119
// SortedByCreationTimestamp returns the machines sorted by creation timestamp.
109120
func (s Machines) SortedByCreationTimestamp() []*clusterv1.Machine {
110-
res := make(util.MachinesByCreationTimestamp, 0, len(s))
121+
res := make(machinesByCreationTimestamp, 0, len(s))
111122
for _, value := range s {
112123
res = append(res, value)
113124
}

util/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ func (k KubeAwareAPIVersions) Less(i, j int) bool {
486486
}
487487

488488
// MachinesByCreationTimestamp sorts a list of Machine by creation timestamp, using their names as a tie breaker.
489+
// Deprecated: This struct will be removed in a future release.
489490
type MachinesByCreationTimestamp []*clusterv1.Machine
490491

491492
func (o MachinesByCreationTimestamp) Len() int { return len(o) }

0 commit comments

Comments
 (0)