Skip to content

Commit

Permalink
Deprecate MachinesByCreationTimestamp and use private version of it i…
Browse files Browse the repository at this point in the history
…n collections
  • Loading branch information
praveenrewar committed Feb 14, 2022
1 parent 9d4d6b4 commit 016b43c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/book/src/developer/providers/v1.1-to-v1.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ in ClusterAPI are kept in sync with the versions used by `sigs.k8s.io/controller

### Deprecation

-
* `util.MachinesByCreationTimestamp` has been deprecated, as we are now using `util/collections.machinesByCreationTimestamp`

### Removals

Expand Down
15 changes: 13 additions & 2 deletions util/collections/machine_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/blang/semver"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/version"
)
Expand All @@ -57,6 +56,18 @@ func (v machinesByVersion) Less(i, j int) bool {
return comp == -1
}

// machinesByCreationTimestamp sorts a list of Machine by creation timestamp, using their names as a tie breaker.
type machinesByCreationTimestamp []*clusterv1.Machine

func (o machinesByCreationTimestamp) Len() int { return len(o) }
func (o machinesByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o machinesByCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

// New creates an empty Machines.
func New() Machines {
return make(Machines)
Expand Down Expand Up @@ -107,7 +118,7 @@ func (s Machines) Difference(machines Machines) Machines {

// SortedByCreationTimestamp returns the machines sorted by creation timestamp.
func (s Machines) SortedByCreationTimestamp() []*clusterv1.Machine {
res := make(util.MachinesByCreationTimestamp, 0, len(s))
res := make(machinesByCreationTimestamp, 0, len(s))
for _, value := range s {
res = append(res, value)
}
Expand Down
1 change: 1 addition & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ func (k KubeAwareAPIVersions) Less(i, j int) bool {
}

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

func (o MachinesByCreationTimestamp) Len() int { return len(o) }
Expand Down

0 comments on commit 016b43c

Please sign in to comment.