mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
11d6b0df45
xRoute resource types contain a slice of parentRefs to services that they manipulate traffic for. All xRoutes that have a parentRef to given Service will be merged together to generate a ComputedRoutes resource name-aligned with that Service. This means that a write of an xRoute with 2 parent ref pointers will cause at most 2 reconciles for ComputedRoutes. If that xRoute's list of parentRefs were ever to be reduced, or otherwise lose an item, that subsequent map event will only emit events for the current set of refs. The removed ref will not cause the generated ComputedRoutes related to that service to be re-reconciled to omit the influence of that xRoute. To combat this, we will store on the ComputedRoutes resource a BoundResources []*pbresource.Reference field with references to all resources that were used to influence the generated output. When the routes controller reconciles, it will use a bimapper to index this influence, and the dependency mappers for the xRoutes will look themselves up in that index to discover additional (former) ComputedRoutes that need to be notified as well.
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package resource
|
|
|
|
import "github.com/hashicorp/consul/proto-public/pbresource"
|
|
|
|
func LessReference(a, b *pbresource.Reference) bool {
|
|
return compareReference(a, b) < 0
|
|
}
|
|
|
|
func compareReference(a, b *pbresource.Reference) int {
|
|
if a == nil || b == nil {
|
|
panic("nil references cannot be compared")
|
|
}
|
|
|
|
diff := compareType(a.Type, b.Type)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
diff = compareTenancy(a.Tenancy, b.Tenancy)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
diff = compareString(a.Name, b.Name)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
return compareString(a.Section, b.Section)
|
|
}
|
|
|
|
func compareType(a, b *pbresource.Type) int {
|
|
if a == nil || b == nil {
|
|
panic("nil types cannot be compared")
|
|
}
|
|
diff := compareString(a.Group, b.Group)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
diff = compareString(a.GroupVersion, b.GroupVersion)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
return compareString(a.Kind, b.Kind)
|
|
}
|
|
|
|
func compareTenancy(a, b *pbresource.Tenancy) int {
|
|
if a == nil || b == nil {
|
|
panic("nil tenancies cannot be compared")
|
|
}
|
|
diff := compareString(a.Partition, b.Partition)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
diff = compareString(a.PeerName, b.PeerName)
|
|
if diff != 0 {
|
|
return diff
|
|
}
|
|
return compareString(a.Namespace, b.Namespace)
|
|
}
|
|
|
|
func compareString(a, b string) int {
|
|
switch {
|
|
case a < b:
|
|
return -1
|
|
case a > b:
|
|
return 1
|
|
default:
|
|
return 0
|
|
}
|
|
}
|