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

Stable-sort subnets by Name #12780

Merged
merged 1 commit into from
Nov 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/awstasks/network_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (e *NetworkLoadBalancer) Run(c *fi.Context) error {

func (e *NetworkLoadBalancer) Normalize() {
// We need to sort our arrays consistently, so we don't get spurious changes
sort.Stable(OrderSubnetMappingsByID(e.SubnetMappings))
sort.Stable(OrderSubnetMappingsByName(e.SubnetMappings))
sort.Stable(OrderListenersByPort(e.Listeners))
sort.Stable(OrderTargetGroupsByName(e.TargetGroups))
}
Expand Down
11 changes: 11 additions & 0 deletions upup/pkg/fi/cloudup/awstasks/subnet_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ func (a OrderSubnetMappingsByID) Less(i, j int) bool {
return v1 < v2
}

// OrderSubnetMappingsByName implements sort.Interface for []Subnet, based on Name
type OrderSubnetMappingsByName []*SubnetMapping

func (a OrderSubnetMappingsByName) Len() int { return len(a) }
func (a OrderSubnetMappingsByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a OrderSubnetMappingsByName) Less(i, j int) bool {
v1 := fi.StringValue(a[i].Subnet.Name)
v2 := fi.StringValue(a[j].Subnet.Name)
return v1 < v2
}

func subnetMappingSlicesEqualIgnoreOrder(l, r []*SubnetMapping) bool {
lBySubnet := make(map[string]*SubnetMapping)
for _, s := range l {
Expand Down