← Back to Pull requests

feat(inference): support ListenerSet ParentRefs for inference dependency resolution #13377

Closed
Aaravanand00 closed this pull request without merging on Mar 26, 2026 22:06 UTC
View on GitHub
Aaravanand00 Aaravanand00 commented on Jan 23, 2026 07:46 UTC
Author

Description

Motivation

The inference plugin currently resolves dependencies only when an HTTPRoute references a Gateway directly. When a route references a ListenerSet as a ParentRef, the inference dependency resolution does not correctly resolve the underlying Gateway resources.

This PR adds support for resolving ListenerSet ParentRefs so that inference dependency resolution works correctly for configurations that reference ListenerSets.

What changed

Added logic to resolve ListenerSet ParentRefs referenced by HTTPRoute.

Extracted parent Gateways from the resolved ListenerSet and reused the existing inference resolution logic.

Added nil-safety guards in the ListenerSet resolution path to prevent potential panics.

Added a focused unit test (TestReferencedGateways_ListenerSet) to validate ListenerSet → Gateway resolution.

Preserved existing comments and maintained backward compatibility with Gateway-only ParentRefs.

Related issues

Fixes #11719

Change Type

/kind feature

Changelog

``release-note
NONE
``

Diff: 225 lines (+212 / -13) across 2 files Reviewer: npolshakova Review duration: 90140m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.37) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 225 lines diff across 2 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.72 · 5 substantive comment(s)
0.72
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.324
Real PR Conversation Timeline
9 items
npolshakova npolshakova commented on code on Feb 02, 2026 16:44 UTC
Code Review
pkg/kgateway/agentgatewaysyncer/backend/inferencepool/status.go:1
@@ -270,16 +298,83 @@ func referencedGateways(
 	return gws
 }
 
+// resolveListenerSetGateways resolves a ListenerSet ParentRef to its constituent Gateways
+func resolveListenerSetGateways(
+	pr gwv1.ParentReference,
+	routeNamespace string,
+	commonCol *collections.CommonCollections,
+) (map[types.NamespacedName]struct{}, error) {
+	gws := make(map[types.NamespacedName]struct{})
+
+	// Determine ListenerSet namespace
+	lsNamespace := routeNamespace
+	if pr.Namespace != nil {
+		lsNamespace = string(*pr.Namespace)
+	}
+
+	// Create a client for XListenerSet
+	lsClient := kclient.NewFiltered[*gwxv1a1.XListenerSet](
+		commonCol.Client,
+		kclient.Filter{ObjectFilter: commonCol.Client.ObjectFilter()},
+	)
+
+	// Get the ListenerSet object
+	ls := lsClient.Get(string(pr.Name), lsNamespace)
+	if ls == nil {
+		return gws, fmt.Errorf("ListenerSet %s/%s not found", lsNamespace, pr.Name)
+	}
+
+	// Extract Gateway from spec.parentRef
+	parentRef := ls.Spec.ParentRef
+	gwNamespace := lsNamespace
+	if parentRef.Namespace != nil {
+		gwNamespace = string(*parentRef.Namespace)
+	}
+	gws[types.NamespacedName{
+		Namespace: gwNamespace,
+		Name:      string(parentRef.Name),
+	}] = struct{}{}
+
+	return gws, nil
+}
+
 // parentGateways returns a map of all parent Gateways referenced by the given HTTPRoute.
-func parentGateways(rt *gwv1.HTTPRoute) map[types.NamespacedName]struct{} {
+func parentGateways(rt *gwv1.HTTPRoute, commonCol *collections.CommonCollections) map[types.NamespacedName]struct{} {

This doesn't need the full set of commmonCols

npolshakova npolshakova commented on code on Feb 02, 2026 16:44 UTC
Code Review
pkg/kgateway/agentgatewaysyncer/backend/inferencepool/status.go:1
@@ -270,16 +298,83 @@ func referencedGateways(
 	return gws
 }
 
+// resolveListenerSetGateways resolves a ListenerSet ParentRef to its constituent Gateways
+func resolveListenerSetGateways(
+	pr gwv1.ParentReference,
+	routeNamespace string,
+	commonCol *collections.CommonCollections,
+) (map[types.NamespacedName]struct{}, error) {
+	gws := make(map[types.NamespacedName]struct{})
+
+	// Determine ListenerSet namespace
+	lsNamespace := routeNamespace
+	if pr.Namespace != nil {
+		lsNamespace = string(*pr.Namespace)
+	}
+
+	// Create a client for XListenerSet
+	lsClient := kclient.NewFiltered[*gwxv1a1.XListenerSet](
+		commonCol.Client,
+		kclient.Filter{ObjectFilter: commonCol.Client.ObjectFilter()},
+	)
+
+	// Get the ListenerSet object
+	ls := lsClient.Get(string(pr.Name), lsNamespace)
+	if ls == nil {
+		return gws, fmt.Errorf("ListenerSet %s/%s not found", lsNamespace, pr.Name)
+	}
+
+	// Extract Gateway from spec.parentRef
+	parentRef := ls.Spec.ParentRef
+	gwNamespace := lsNamespace
+	if parentRef.Namespace != nil {
+		gwNamespace = string(*parentRef.Namespace)
+	}
+	gws[types.NamespacedName{
+		Namespace: gwNamespace,
+		Name:      string(parentRef.Name),
+	}] = struct{}{}
+
+	return gws, nil
+}
+
 // parentGateways returns a map of all parent Gateways referenced by the given HTTPRoute.
-func parentGateways(rt *gwv1.HTTPRoute) map[types.NamespacedName]struct{} {
+func parentGateways(rt *gwv1.HTTPRoute, commonCol *collections.CommonCollections) map[types.NamespacedName]struct{} {
 	gws := make(map[types.NamespacedName]struct{})
 	for _, pr := range rt.Spec.ParentRefs {
-		if pr.Group != nil && *pr.Group != gwv1.GroupName {
+		// Handle Gateway ParentRefs (existing logic)
+		if pr.Group != nil && string(*pr.Group) != gwv1.GroupName {
+			// Check if this is a ListenerSet ParentRef
+			if string(*pr.Group) == wellknown.XListenerSetGVK.Group &&
+				pr.Kind != nil && string(*pr.Kind) == wellknown.XListenerSetKind {
+				// Resolve ListenerSet to Gateways
+				resolvedGws, err := resolveListenerSetGateways(pr, rt.Namespace, commonCol)
+				if err != nil {
+					logger.Warn("failed to resolve ListenerSet ParentRef", "error", err, "listenerSet", pr.Name)
+					continue
+				}
+				for gw := range resolvedGws {
+					gws[gw] = struct{}{}
+				}
+			}
 			continue
 		}
 		if pr.Kind != nil && string(*pr.Kind) != wellknown.GatewayKind {
+			// Check if this is a ListenerSet ParentRef with default group
+			if string(*pr.Kind) == wellknown.XListenerSetKind {
+				// Resolve ListenerSet to Gateways
+				resolvedGws, err := resolveListenerSetGateways(pr, rt.Namespace, commonCol)
+				if err != nil {
+					logger.Warn("failed to resolve ListenerSet ParentRef", "error", err, "listenerSet", pr.Name)
+					continue
+				}
+				for gw := range resolvedGws {
+					gws[gw] = struct{}{}
+				}
+			}
 			continue
 		}
+		// Handle Gateway ParentRefs (existing logic)

Please remove AI generated comments.

npolshakova npolshakova commented on code on Feb 02, 2026 16:44 UTC
Code Review
pkg/kgateway/agentgatewaysyncer/backend/inferencepool/status_test.go:1
@@ -614,7 +614,7 @@ func TestReferencedGateways(t *testing.T) {
 			},
 		},
 	}
-	gws := referencedGateways([]ir.HttpRouteIR{route1, route2, route3}, poolNN)
+	gws := referencedGateways([]ir.HttpRouteIR{route1, route2, route3}, poolNN, nil)

Please add a test for the case where the listener set is used

npolshakova npolshakova requested changes on Feb 02, 2026 16:45 UTC
Changes Requested Reviewer

This PR needs to update the description to match the template

Aaravanand00 Aaravanand00 commented on Feb 06, 2026 19:52 UTC
Author

Hi @npolshakova, thanks for the review and guidance.

Here’s a concise summary of the approach I took to address the ListenerSet case.

Approach

  • Added explicit nil-safety handling in resolveListenerSetGateways to prevent panics when commonCol or the client is nil. This keeps the behavior defensive and aligned with existing patterns.

  • Added a focused unit test TestReferencedGateways_ListenerSet to cover the case where:

  • - an HTTPRoute references a ListenerSet, and
    - the ListenerSet in turn references a Gateway.
  • Used a minimal fake client setup (only required objects: Gateway, ListenerSet, and HTTPRoute) instead of the full CommonCollections, as suggested.

  • Verified that existing Gateway ParentRef resolution logic remains unchanged.
  • Verification

    The test was run locally using:

    go clean -testcache
    go test -v ./pkg/kgateway/agentgatewaysyncer/backend/inferencepool/ -run TestReferencedGateways_ListenerSet
     

    Attaching a screenshot of the local test run showing the test passing.
    <img width="1917" height="525" alt="Screenshot 2026-02-07 005723" src="https://github.com/user-attachments/assets/da1ef35b-0ded-4b63-9d16-dfcbc06d9163" />

    npolshakova npolshakova commented on code on Feb 06, 2026 20:20 UTC
    Code Review
    pkg/kgateway/agentgatewaysyncer/backend/inferencepool/status.go:1
    @@ -270,16 +298,83 @@ func referencedGateways(
     	return gws
     }
     
    +// resolveListenerSetGateways resolves a ListenerSet ParentRef to its constituent Gateways
    +func resolveListenerSetGateways(
    +	pr gwv1.ParentReference,
    +	routeNamespace string,
    +	commonCol *collections.CommonCollections,
    +) (map[types.NamespacedName]struct{}, error) {
    +	gws := make(map[types.NamespacedName]struct{})
    +
    +	// Determine ListenerSet namespace
    +	lsNamespace := routeNamespace
    +	if pr.Namespace != nil {
    +		lsNamespace = string(*pr.Namespace)
    +	}
    +
    +	// Create a client for XListenerSet
    +	lsClient := kclient.NewFiltered[*gwxv1a1.XListenerSet](
    +		commonCol.Client,
    +		kclient.Filter{ObjectFilter: commonCol.Client.ObjectFilter()},
    +	)
    +
    +	// Get the ListenerSet object
    +	ls := lsClient.Get(string(pr.Name), lsNamespace)
    +	if ls == nil {
    +		return gws, fmt.Errorf("ListenerSet %s/%s not found", lsNamespace, pr.Name)
    +	}
    +
    +	// Extract Gateway from spec.parentRef
    +	parentRef := ls.Spec.ParentRef
    +	gwNamespace := lsNamespace
    +	if parentRef.Namespace != nil {
    +		gwNamespace = string(*parentRef.Namespace)
    +	}
    +	gws[types.NamespacedName{
    +		Namespace: gwNamespace,
    +		Name:      string(parentRef.Name),
    +	}] = struct{}{}
    +
    +	return gws, nil
    +}
    +
     // parentGateways returns a map of all parent Gateways referenced by the given HTTPRoute.
    -func parentGateways(rt *gwv1.HTTPRoute) map[types.NamespacedName]struct{} {
    +func parentGateways(rt *gwv1.HTTPRoute, commonCol *collections.CommonCollections) map[types.NamespacedName]struct{} {
     	gws := make(map[types.NamespacedName]struct{})
     	for _, pr := range rt.Spec.ParentRefs {
    -		if pr.Group != nil && *pr.Group != gwv1.GroupName {
    +		// Handle Gateway ParentRefs (existing logic)
    +		if pr.Group != nil && string(*pr.Group) != gwv1.GroupName {
    +			// Check if this is a ListenerSet ParentRef
    +			if string(*pr.Group) == wellknown.XListenerSetGVK.Group &&
    +				pr.Kind != nil && string(*pr.Kind) == wellknown.XListenerSetKind {
    +				// Resolve ListenerSet to Gateways
    +				resolvedGws, err := resolveListenerSetGateways(pr, rt.Namespace, commonCol)
    +				if err != nil {
    +					logger.Warn("failed to resolve ListenerSet ParentRef", "error", err, "listenerSet", pr.Name)
    +					continue
    +				}
    +				for gw := range resolvedGws {
    +					gws[gw] = struct{}{}
    +				}
    +			}
     			continue
     		}
     		if pr.Kind != nil && string(*pr.Kind) != wellknown.GatewayKind {
    +			// Check if this is a ListenerSet ParentRef with default group
    +			if string(*pr.Kind) == wellknown.XListenerSetKind {
    +				// Resolve ListenerSet to Gateways
    +				resolvedGws, err := resolveListenerSetGateways(pr, rt.Namespace, commonCol)
    +				if err != nil {
    +					logger.Warn("failed to resolve ListenerSet ParentRef", "error", err, "listenerSet", pr.Name)
    +					continue
    +				}
    +				for gw := range resolvedGws {
    +					gws[gw] = struct{}{}
    +				}
    +			}
     			continue
     		}
    +		// Handle Gateway ParentRefs (existing logic)

    You latest change removed all comments in the file, including existing comments we want to keep. Please be more mindful when using AI and review changes in the diff or we will close these prs out without review for violating the AI policy.

    Aaravanand00 Aaravanand00 commented on Feb 07, 2026 06:20 UTC
    Reviewer

    Hi @npolshakova mam — sorry about that, and thanks for calling it out.

    You’re right: the previous change unintentionally removed existing comments along with the AI-generated ones. I’ve now reverted that and restored all original comments, keeping only the intended code changes.

    I’ve double-checked the diff to make sure no existing comments were altered or removed this time.

    Thanks for the patience and the guidance — appreciate the review.

    Aaravanand00 Aaravanand00 commented on Mar 07, 2026 09:09 UTC
    Author

    Hi @npolshakova mam ,

    While attempting to rebase and resolve conflicts for this PR, I investigated why the changes could not be applied on the current main.

    It turns out that the entire agentgateway control plane (including pkg/kgateway/agentgatewaysyncer/) was removed from the kgateway repository in commit 30cc52c45 as part of the v2.3.0-beta.2 changes. Approximately ~74k lines of code were removed when the control plane was migrated to the separate agentgateway repository.

    Because of this change:

    The files modified by this PR (pkg/kgateway/agentgatewaysyncer/backend/inferencepool/...) no longer exist in the kgateway codebase.
    The related types and infrastructure required by the inference pool logic have also been removed.

  • Re-applying these changes in kgateway would effectively reintroduce a subsystem that has already been migrated out of this repository.
  • From the current repository documentation:

    Starting with version 2.3.0, the control plane for agentgateway has been migrated to the agentgateway repository.

    Given this, it seems that this feature should likely be implemented in the agentgateway repository instead:

    https://github.com/agentgateway/agentgateway

    If that direction makes sense, I can close this PR and port the ListenerSet ParentRef support logic to the agentgateway repository? or what I can do

    Reviewers
    Assignees
    Aaravanand00 Aaravanand00
    Labels
    risk: low confidence: 83.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.9% (MEDIUM) · Higher = larger blast radius
    36.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.9% · Lower = rushed or shallow review
    83.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.9% · Safe to merge
    5.9%