Repository navigation
Description
Description:
At the moment, some linear scans are performed per route/destination, e.g.:
Double scan of BTLSPs per destination with expensive deepEquals check in backendTLSTargetMatched:
gateway/internal/gatewayapi/backendtlspolicy.go
Lines 498 to 510 in bdc06f6
| if target.SectionName != nil { | |
| for _, policy := range policies { | |
| if backendTLSTargetMatched(policy, target, backendNamespace, true) { | |
| // prefer policies that target this specific section over wildcard matches | |
| return policy | |
| } | |
| } | |
| } | |
| for _, policy := range policies { | |
| if backendTLSTargetMatched(policy, target, backendNamespace, false) { | |
| return policy | |
| } | |
| } |
Scan all ExtensionRefFilters per route rule with an extension filter and match by expensive unstructured.NestedString checks from GetKind/Name/... calls.
gateway/internal/gatewayapi/filters.go
Lines 1038 to 1041 in bdc06f6
| for _, res := range resources.ExtensionRefFilters { | |
| if res.GetKind() == string(extFilter.Kind) && res.GetName() == string(extFilter.Name) && res.GetNamespace() == filterNs { | |
| apiVers := res.GetAPIVersion() | |
List all RefGrants to a kind, whenever cross-namespace access is evaluated to a resource of that kind in reconciler. Maybe a more precise index can be added to perform more focused lookups, including namespaces.
gateway/internal/provider/kubernetes/controller.go
Lines 1664 to 1700 in bdc06f6
| func (r *gatewayAPIReconciler) findReferenceGrant(ctx context.Context, from, to ObjectKindNamespacedName) (*gwapiv1b1.ReferenceGrant, error) { | |
| refGrantList := new(gwapiv1b1.ReferenceGrantList) | |
| opts := &client.ListOptions{FieldSelector: fields.OneTermEqualSelector(targetRefGrantRouteIndex, to.kind)} | |
| if err := r.client.List(ctx, refGrantList, opts); err != nil { | |
| return nil, fmt.Errorf("failed to list ReferenceGrants: %w", err) | |
| } | |
| for i := range refGrantList.Items { | |
| refGrant := &refGrantList.Items[i] | |
| if refGrant.Namespace != to.namespace { | |
| continue | |
| } | |
| var fromAllowed bool | |
| for _, refGrantFrom := range refGrant.Spec.From { | |
| if string(refGrantFrom.Kind) == from.kind && string(refGrantFrom.Namespace) == from.namespace { | |
| fromAllowed = true | |
| break | |
| } | |
| } | |
| if !fromAllowed { | |
| continue | |
| } | |
| var toAllowed bool | |
| for _, refGrantTo := range refGrant.Spec.To { | |
| if string(refGrantTo.Kind) == to.kind && (refGrantTo.Name == nil || *refGrantTo.Name == "" || string(*refGrantTo.Name) == to.name) { | |
| toAllowed = true | |
| break | |
| } | |
| } | |
| if !toAllowed { | |
| continue | |
| } | |
These scans be optimized by building an index and possibly performing less expensive comparisons.
[optional Relevant Links:]
Any extra documentation required to understand the issue.
Activity