Add proxyless endpoint on-demand allocation#17851
Conversation
Allow dynamic proxyless container endpoints to allocate a target-port fallback when an endpoint reference requires an allocated endpoint before container creation. Disable the on-demand allocator once container ports are built so later resolution continues to use DCP service updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17851Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17851" |
Log when a dynamic proxyless container endpoint is resolved before container creation and Aspire assigns the public port to match the target port. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the endpoint allocation cutoff lock with an atomic exchange so BuildContainerPorts remains the point where on-demand proxyless endpoint allocation stops. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the atomic OnDemandAllocatedEndpointProvider setter directly at the BuildContainerPorts cutoff instead of a dedicated clear wrapper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PR Testing ReportPR Information
CLI Version Verification
Changes AnalyzedFiles Changed
Change Categories
Test Scenarios ExecutedScenario 1: Late allocation remains dynamicObjective: Verify a proxyless container endpoint with a target port but no host port keeps DCP-owned dynamic host-port assignment when no endpoint reference is resolved before container creation. Steps:
Evidence:
Observations:
Expected Unhappy-Path Outcome: Post-start endpoint resolution should not retroactively force the target-port fallback. This was satisfied because the described URL remained on host port Scenario 2: Early endpoint resolution uses target-port fallbackObjective: Verify resolving a proxyless container endpoint during container configuration commits the public port to the target port before container creation. Steps:
Evidence:
Observations:
Scenario 3: Repeated early resolution is stableObjective: Verify multiple early resolutions of the same endpoint do not produce conflicting fallback values. Steps:
Evidence:
Observations:
Summary
Overall Result✅ PR VERIFIED The dogfood CLI for PR #17851 matches the PR head commit, and the targeted proxyless container endpoint scenarios passed. |
|
/backport to release/13.4 |
|
Started backporting to |
There was a problem hiding this comment.
Pull request overview
This pull request adds an on-demand allocation path for dynamic, proxyless container endpoints so endpoint references can be resolved deterministically before the container is created (avoiding deadlocks when container configuration/env-var callbacks require the port).
Changes:
- Introduces an internal on-demand endpoint allocation annotation and integrates it into endpoint resolution.
- Adjusts container creation ordering so environment/configuration callbacks can trigger early (fallback) host-port commitment before container ports are finalized.
- Expands DCP executor tests and DCP test Kubernetes service behavior to validate both “resolved early” and “resolved after service update” scenarios.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.Tests/Dcp/TestKubernetesService.cs | Updates the fake DCP service-port allocation to prefer container host-port when present for proxyless endpoints. |
| tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs | Adds coverage for early endpoint resolution fallback behavior and verifies port publishing semantics. |
| src/Aspire.Hosting/Dcp/DcpModelUtilities.cs | Adds on-demand allocation wiring for dynamic proxyless container endpoints and supports fallback port usage when allocating localhost endpoints. |
| src/Aspire.Hosting/Dcp/ContainerCreator.cs | Reorders container port building to occur after configuration/env callbacks and disables on-demand allocation after callbacks complete. |
| src/Aspire.Hosting/ApplicationModel/OnDemandEndpointAllocationAnnotation.cs | New internal annotation that provides a stoppable, resource-owned allocator hook. |
| src/Aspire.Hosting/ApplicationModel/EndpointReference.cs | Adds internal async allocation helper that consults on-demand allocators before awaiting normal allocation snapshots. |
| src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs | Adds a helper to synchronously read an already-set allocated endpoint for a given network. |
|
❌ CLI E2E Tests failed — 109 passed, 1 failed, 2 unknown (commit ❌ Failed Tests
View all recordings
📹 Recordings uploaded automatically from CI run #26851923598 |
Documents the on-demand port allocation behavior for dynamic proxyless container endpoints introduced in Aspire 13.5 (microsoft/aspire#17851). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pull request created: #1199
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1199 targeting Added a new subsection "Resolving proxyless container endpoints before container creation" to Note This draft PR needs human review before merging. |
Description
Proxyless container endpoints without an explicit host port normally defer host port assignment until DCP creates the container. That can deadlock or fail when an endpoint reference needs the allocated endpoint while container configuration is still being built, such as when a container exposes its own public port in an environment variable.
This change adds an on-demand allocation path for dynamic proxyless container endpoints. If an allocated endpoint is requested before container ports are finalized, Aspire commits the target port as the fallback host port and builds the container port spec with that host port. Once
BuildContainerPortsruns, the on-demand allocator is disabled so any later endpoint resolution is fulfilled by normal DCP service updates, preserving random host-port assignment when the endpoint was not needed before container creation.User-facing usage
AppHost code that references a proxyless container endpoint before the container is created can now resolve that endpoint deterministically:
If the endpoint is not resolved before container creation, DCP still assigns the host port dynamically.
Validation:
dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-method "*.EndpointPortsContainerProxylessNoPortTargetPortSet" --filter-method "*.EndpointPortsContainerProxylessNoPortTargetPortSetPublishesAllocatedEndpointAfterServiceUpdate" --filter-method "*.EndpointPortsContainerProxylessNoPortTargetPortSetUsesTargetPortFallbackWhenResolvedBeforeContainerCreation" --filter-method "*.EndpointPortsContainerProxylessNoPortTargetPortSetUsesTargetPortFallbackWhenHostAndPortResolvedBeforeContainerCreation" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?