Skip to content

Commit

Permalink
Minor cleanup on launch template taint sorting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Oct 18, 2021
1 parent 58875ec commit d2663d1
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions pkg/cloudprovider/aws/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,21 @@ func (p *LaunchTemplateProvider) createLaunchTemplate(ctx context.Context, optio
return output.LaunchTemplate, nil
}

type taints []core.Taint

func (ts taints) Len() int {
return len(ts)
}

func (ts taints) Less(i, j int) bool {
ti, tj := ts[i], ts[j]
if ti.Key < tj.Key {
return true
}
if ti.Key == tj.Key && ti.Value < tj.Value {
return true
}
if ti.Value == tj.Value {
return ti.Effect < tj.Effect
}
return false
}

func (ts taints) Swap(i, j int) {
ts[i], ts[j] = ts[j], ts[i]
}

func sortedTaints(ts []core.Taint) []core.Taint {
sorted := taints(append(ts[:0:0], ts...)) // copy to avoid touching original
sort.Sort(sorted)
sorted := append(ts[:0:0], ts...) // copy to avoid touching original
sort.Slice(sorted, func(i, j int) bool {
ti, tj := sorted[i], sorted[j]
if ti.Key < tj.Key {
return true
}
if ti.Key == tj.Key && ti.Value < tj.Value {
return true
}
if ti.Value == tj.Value {
return ti.Effect < tj.Effect
}
return false
})
return sorted
}

Expand Down

0 comments on commit d2663d1

Please sign in to comment.