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

Minor cleanup on launch template taint sorting logic #749

Merged
merged 1 commit into from
Oct 18, 2021
Merged
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
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