Merge pull request #12780 from justinsb/stable_subnet_mapping

Stable-sort subnets by Name
This commit is contained in:
Kubernetes Prow Robot 2021-11-18 10:21:03 -08:00 committed by GitHub
commit 1736db6358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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))
}

View File

@ -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 {