Repository navigation
fix(backend): use correct port fallback for in-cluster agent resolution - #1525
Conversation
When a Service has no ports defined (e.g. Sandbox-created headless services), resolve_agent_url fell back to DEFAULT_OFF_CLUSTER_PORT (8080) regardless of context. In-cluster agents listen on port 8000, so the fallback should match the deployment context. Workaround for kubernetes-sigs/agent-sandbox#154 where the Sandbox controller creates headless Services without port definitions. Signed-off-by: cwiklik <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
huang195
left a comment
There was a problem hiding this comment.
Dobra robota. Targeted one-line fix in resolve_agent_url plus symmetric test coverage (in-cluster / off-cluster × service-missing / ports-empty). Scope is right — other DEFAULT_OFF_CLUSTER_PORT sites (agents.py:3073,3612) are for HTTPRoute/external access and intentionally differ, and they skip Sandboxes anyway.
Verified against the live Kind cluster: weather-agent.team1.svc.cluster.local:8080 → 503, :8000 → 200. This patch routes to the right port.
Areas reviewed: Python (1 file, 1 change), tests (4 cases)
Commits: 1, signed-off
CI: all green (E2E HyperShift awaits /run-e2e)
|
/run-e2e |
E2E HyperShift Tests PassedCommit: The If you push new commits, the label will be removed and you'll need to comment |
…back fix(backend): use correct port fallback for in-cluster agent resolution Signed-off-by: cwiklik <[email protected]>
…stant PR #1525 made `resolve_agent_url` fall back to DEFAULT_IN_CLUSTER_PORT (8000) for in-cluster callers when the Service has no ports (the Sandbox case). That contradicts the sandbox-builder change in `_build_sandbox_manifest`, which aligns the Sandbox pod's PORT and containerPort with service_port (default DEFAULT_OFF_CLUSTER_PORT = 8080) so that AGENT_ENDPOINT, the advertised agent card URL, and the actual listener all agree. With both changes in effect, the backend knocks on :8000 while the agent listens on :8080; envoy returns 503 and the UI shows "Agent card not available." Replace the hardcoded in-cluster fallback with a read of the owning Sandbox's pod template (`spec.podTemplate.spec.containers[0]` — containerPort first, then the PORT env var). Deployments are unaffected: their Service exposes ports, so the first lookup still wins and the new Sandbox lookup is skipped. A single DEFAULT_OFF_CLUSTER_PORT final fallback covers the case where both lookups fail (matches the sandbox-builder default and the external port used by Gateways/Ingresses). As a side benefit, this also handles Sandboxes created with a custom servicePorts[0].port — neither prior fix covered that case. Tests: - Replace the two :8000 assertions from #1525 with Sandbox-aware tests (containerPort path and PORT-env path) and a final-fallback test that asserts :8080 when neither Service nor Sandbox is found. The long-term fix is upstream kubernetes-sigs/agent-sandbox#154 (Sandbox controller populating its Service with ports); this is the in-tree workaround until then. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Summary
resolve_agent_urlto useDEFAULT_IN_CLUSTER_PORT(8000) as fallback when running in-cluster, instead of always usingDEFAULT_OFF_CLUSTER_PORT(8080)Root cause: The Sandbox controller creates headless Services with no
spec.ports(kubernetes-sigs/agent-sandbox#154). The backend'slookup_service_portfinds no ports on the Service and falls back to a default. Previously the default was always 8080 (off-cluster port), but in-cluster agents listen on 8000 — causing 503 errors when fetching the agent card.Behavior:
service.spec.ports[0].port(unchanged)Test plan
pytest tests/test_routes.py— 15 tests)Assisted-By: Claude Code