Skip to content

Commit 4a06573

Browse files
committed
perf: skip ls translation
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
1 parent edc5df9 commit 4a06573

1 file changed

Lines changed: 43 additions & 38 deletions

File tree

internal/gatewayapi/envoyextensionpolicy.go

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -171,49 +171,54 @@ func (t *Translator) ProcessEnvoyExtensionPolicies(
171171
}
172172
}
173173

174-
// Process the policies targeting ListenerSet Listeners
175-
for i, currPolicy := range envoyExtensionPolicies {
176-
policyName := utils.NamespacedName(currPolicy)
177-
// Only resolve TargetRefs from targetRefs field since TargetSelectors can't specify sectionName.
178-
targetRefs := resolvePolicyTargetsFromReferences(currPolicy.Spec.PolicyTargetReferences, currPolicy.Namespace)
179-
for _, currTarget := range targetRefs {
180-
if isListenerSetListener(currTarget) {
181-
policy, found := handledPolicies[policyName]
182-
if !found {
183-
policy = policyCopies[i]
184-
res = append(res, policy)
185-
handledPolicies[policyName] = policy
186-
}
174+
// Only run the ListenerSet-specific translation when at least one ListenerSet exists.
175+
// When none are present, no policy can successfully attach to a ListenerSet (the target resolves to
176+
// nil and processing returns early), so these loops would be pure overhead.
177+
if len(resources.ListenerSets) > 0 {
178+
// Process the policies targeting ListenerSet Listeners
179+
for i, currPolicy := range envoyExtensionPolicies {
180+
policyName := utils.NamespacedName(currPolicy)
181+
// Only resolve TargetRefs from targetRefs field since TargetSelectors can't specify sectionName.
182+
targetRefs := resolvePolicyTargetsFromReferences(currPolicy.Spec.PolicyTargetReferences, currPolicy.Namespace)
183+
for _, currTarget := range targetRefs {
184+
if isListenerSetListener(currTarget) {
185+
policy, found := handledPolicies[policyName]
186+
if !found {
187+
policy = policyCopies[i]
188+
res = append(res, policy)
189+
handledPolicies[policyName] = policy
190+
}
187191

188-
t.processEnvoyExtensionPolicyForListenerSet(resources, xdsIR,
189-
gatewayMap, listenerSetMap, overrides, policy, currTarget)
192+
t.processEnvoyExtensionPolicyForListenerSet(resources, xdsIR,
193+
gatewayMap, listenerSetMap, overrides, policy, currTarget)
194+
}
190195
}
191196
}
192-
}
193197

194-
// Process the policies targeting ListenerSets
195-
for i, currPolicy := range envoyExtensionPolicies {
196-
policyName := utils.NamespacedName(currPolicy)
197-
targetRefs := resolvePolicyTargets(
198-
currPolicy.Spec.PolicyTargetReferences,
199-
resources.ListenerSets,
200-
resources.ReferenceGrants,
201-
egv1a1.GroupName,
202-
egv1a1.KindEnvoyExtensionPolicy,
203-
currPolicy.Namespace,
204-
t.GetNamespace,
205-
)
206-
for _, currTarget := range targetRefs {
207-
if isListenerSet(currTarget) {
208-
policy, found := handledPolicies[policyName]
209-
if !found {
210-
policy = policyCopies[i]
211-
res = append(res, policy)
212-
handledPolicies[policyName] = policy
213-
}
198+
// Process the policies targeting ListenerSets
199+
for i, currPolicy := range envoyExtensionPolicies {
200+
policyName := utils.NamespacedName(currPolicy)
201+
targetRefs := resolvePolicyTargets(
202+
currPolicy.Spec.PolicyTargetReferences,
203+
resources.ListenerSets,
204+
resources.ReferenceGrants,
205+
egv1a1.GroupName,
206+
egv1a1.KindEnvoyExtensionPolicy,
207+
currPolicy.Namespace,
208+
t.GetNamespace,
209+
)
210+
for _, currTarget := range targetRefs {
211+
if isListenerSet(currTarget) {
212+
policy, found := handledPolicies[policyName]
213+
if !found {
214+
policy = policyCopies[i]
215+
res = append(res, policy)
216+
handledPolicies[policyName] = policy
217+
}
214218

215-
t.processEnvoyExtensionPolicyForListenerSet(resources, xdsIR,
216-
gatewayMap, listenerSetMap, overrides, policy, currTarget)
219+
t.processEnvoyExtensionPolicyForListenerSet(resources, xdsIR,
220+
gatewayMap, listenerSetMap, overrides, policy, currTarget)
221+
}
217222
}
218223
}
219224
}

0 commit comments

Comments
 (0)