Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Make MachinesByCreationTimestamp private to machine collections #6111

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 and will be removed in a future release.

### 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 {
praveenrewar marked this conversation as resolved.
Show resolved Hide resolved
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