Skip to content

Commit

Permalink
Fix deprecated set lint
Browse files Browse the repository at this point in the history
  • Loading branch information
RadekManak committed Jan 27, 2023
1 parent c34f5d8 commit a781bd6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
20 changes: 10 additions & 10 deletions pkg/machineproviders/providers/openshift/machine/v1beta1/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func createBaseFailureDomainMapping(cpms *machinev1.ControlPlaneMachineSet, fail
// createMachineMapping inspects the state of the Machines on the cluster, selected by the ControlPlaneMachineSet, and
// creates a mapping of their indexes (if available) to their failure domain to allow the mapping to be customised
// to the state of the cluster.
func createMachineMapping(ctx context.Context, logger logr.Logger, cl client.Client, cpms *machinev1.ControlPlaneMachineSet) (map[int32]failuredomain.FailureDomain, sets.Int32, error) {
func createMachineMapping(ctx context.Context, logger logr.Logger, cl client.Client, cpms *machinev1.ControlPlaneMachineSet) (map[int32]failuredomain.FailureDomain, sets.Set[int32], error) {
selector, err := metav1.LabelSelectorAsSelector(&cpms.Spec.Selector)
if err != nil {
return nil, nil, fmt.Errorf("could not convert label selector to selector: %w", err)
Expand Down Expand Up @@ -193,8 +193,8 @@ func mapIndexesToFailureDomainsForMachines(logger logr.Logger, machineList *mach

// listDeletingIndexes creates a list of indexes for machines which are being deleted.
// Indexes in the list only have machines in them that are being deleted.
func listDeletingIndexes(machines []machinev1beta1.Machine) sets.Int32 {
indexes := sets.NewInt32()
func listDeletingIndexes(machines []machinev1beta1.Machine) sets.Set[int32] {
indexes := sets.New[int32]()

// Add all machines that are being deleted to the set.
for _, machine := range machines {
Expand All @@ -204,7 +204,7 @@ func listDeletingIndexes(machines []machinev1beta1.Machine) sets.Int32 {
continue
}

indexes.Insert(int32(index))
indexes = sets.Insert(indexes, int32(index))
}
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func listDeletingIndexes(machines []machinev1beta1.Machine) sets.Int32 {
// When processing the indexes, everything must be sorted to ensure the output is stable (note iterating over a map
// is randomised by golang).
// The base mapping should always be at least as long as the machine mapping for this to work.
func reconcileMappings(logger logr.Logger, base, machines map[int32]failuredomain.FailureDomain, deletingIndexes sets.Int32) map[int32]failuredomain.FailureDomain {
func reconcileMappings(logger logr.Logger, base, machines map[int32]failuredomain.FailureDomain, deletingIndexes sets.Set[int32]) map[int32]failuredomain.FailureDomain {
if len(base) < len(machines) {
// This is a programming error since user input doesn't affect this.
panic("base must have at least as many indexes as machines")
Expand Down Expand Up @@ -271,8 +271,8 @@ func reconcileMappings(logger logr.Logger, base, machines map[int32]failuredomai

// createUnmatchedIndexes creates a set of indexes that haven't been matched to a machine
// from the list of candidates.
func createUnmatchedIndexes(candidates map[int32]failuredomain.FailureDomain) sets.Int32 {
out := sets.NewInt32()
func createUnmatchedIndexes(candidates map[int32]failuredomain.FailureDomain) sets.Set[int32] {
out := sets.New[int32]()

for idx := range candidates {
out.Insert(idx)
Expand All @@ -285,7 +285,7 @@ func createUnmatchedIndexes(candidates map[int32]failuredomain.FailureDomain) se
// If the candidate index differs from the output index, swap these and then use the candidate.
// This matches and cements this index to a particular failure domain.
// Any unmatched indexes will be handled separately later.
func matchMachinesToCandidates(out, candidates map[int32]failuredomain.FailureDomain, unmatchedIndexes, deletingIndexes sets.Int32) {
func matchMachinesToCandidates(out, candidates map[int32]failuredomain.FailureDomain, unmatchedIndexes, deletingIndexes sets.Set[int32]) {
for _, idy := range sortedIndexes(out) {
// Ignore any indexes that only contain deleting machines.
// This allows other indexes to take precedence for keeping their failure domain stable.
Expand Down Expand Up @@ -315,7 +315,7 @@ func matchMachinesToCandidates(out, candidates map[int32]failuredomain.FailureDo
// - The failure domain from the machine mapping was removed from the base.
// - A new failure domain was added to the base mapping.
// - The machine mapping is balanced in a different weighting to the machine mapping.
func handleUnmatchedIndex(logger logr.Logger, idx int32, out, base, candidates map[int32]failuredomain.FailureDomain, unmatchedIndexes sets.Int32, maxPerFailureDomain int) {
func handleUnmatchedIndex(logger logr.Logger, idx int32, out, base, candidates map[int32]failuredomain.FailureDomain, unmatchedIndexes sets.Set[int32], maxPerFailureDomain int) {
switch {
case !indexExists(out, idx):
// There is no machine in this index presently,
Expand Down Expand Up @@ -385,7 +385,7 @@ func reconcileIndexes(reconciled, preferred map[int32]failuredomain.FailureDomai

// useCandidate is used when we have matched a candidate with a machine mapping. It removes it from the list of
// candidates and "matches" the index.
func useCandidate(candidates map[int32]failuredomain.FailureDomain, unmatchedIndexes sets.Int32, idx int32) {
func useCandidate(candidates map[int32]failuredomain.FailureDomain, unmatchedIndexes sets.Set[int32], idx int32) {
unmatchedIndexes.Delete(idx)
delete(candidates, idx)
}
Expand Down
Loading

0 comments on commit a781bd6

Please sign in to comment.