Skip to content
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
20 changes: 12 additions & 8 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ func (t *Translator) ProcessBackendTrafficPolicies(resources *resource.Resources
routes []RouteContext,
xdsIR resource.XdsIRMap,
) []*egv1a1.BackendTrafficPolicy {
res := make([]*egv1a1.BackendTrafficPolicy, 0, len(resources.BackendTrafficPolicies))

backendTrafficPolicies := resources.BackendTrafficPolicies
// BackendTrafficPolicies are already sorted by the provider layer

routeMapSize := len(routes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any lint for things like this? I known goland have some inline warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create an issue to track this, this's a good case for help-wanted.

gatewayMapSize := len(gateways)
policyMapSize := len(backendTrafficPolicies)

res := make([]*egv1a1.BackendTrafficPolicy, 0, policyMapSize)

// First build a map out of the routes and gateways for faster lookup since users might have thousands of routes or more.
routeMap := map[policyTargetRouteKey]*policyRouteTargetContext{}
routeMap := make(map[policyTargetRouteKey]*policyRouteTargetContext, routeMapSize)
for _, route := range routes {
key := policyTargetRouteKey{
Kind: string(route.GetRouteType()),
Expand All @@ -55,19 +59,19 @@ func (t *Translator) ProcessBackendTrafficPolicies(resources *resource.Resources
routeMap[key] = &policyRouteTargetContext{RouteContext: route}
}

gatewayMap := map[types.NamespacedName]*policyGatewayTargetContext{}
gatewayMap := make(map[types.NamespacedName]*policyGatewayTargetContext, gatewayMapSize)
for _, gw := range gateways {
key := utils.NamespacedName(gw)
gatewayMap[key] = &policyGatewayTargetContext{GatewayContext: gw}
}

// Map of Gateway to the routes attached to it
gatewayRouteMap := make(map[string]sets.Set[string])
gatewayRouteMap := make(map[string]sets.Set[string], gatewayMapSize)

handledPolicies := make(map[types.NamespacedName]*egv1a1.BackendTrafficPolicy)
handledPolicies := make(map[types.NamespacedName]*egv1a1.BackendTrafficPolicy, policyMapSize)

gatewayPolicyMap := make(map[types.NamespacedName]*egv1a1.BackendTrafficPolicy)
gatewayPolicyMerged := make(map[types.NamespacedName]sets.Set[string])
gatewayPolicyMap := make(map[types.NamespacedName]*egv1a1.BackendTrafficPolicy, gatewayMapSize)
gatewayPolicyMerged := make(map[types.NamespacedName]sets.Set[string], gatewayMapSize)

// Translate
// 1. First translate Policies targeting xRoutes
Expand Down