Repository navigation
Add ergonomic Azure subnet service-delegation API - #18728
Conversation
Introduce fluent helpers on IResourceBuilder<AzureSubnetResource> so delegating a subnet no longer requires manually constructing an AzureSubnetServiceDelegationAnnotation with a duplicated service string: - WithServiceDelegation(serviceName, name?) appends a delegation annotation, defaulting the delegation name to the service name. - WithContainerInstanceDelegation() is a typed convenience wrapper that delegates to Microsoft.ContainerInstance/containerGroups (ACI). Update the public API baseline and add tests covering both helpers. Co-authored-by: Copilot App <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18728Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18728" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adds annotation-driven Azure subnet service-delegation helpers for generic services and Azure Container Instances.
Changes:
- Adds fluent delegation APIs with XML documentation and ATS exports.
- Adds focused annotation tests.
- Updates the generated public API baseline.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
AzureVirtualNetworkExtensions.cs |
Implements delegation helpers. |
AzureVirtualNetworkExtensionsTests.cs |
Tests helper annotation behavior. |
api/Aspire.Hosting.Azure.Network.cs |
Records the new public APIs. |
PR Testing ReportPR Information
Artifact Version Verification
Changes AnalyzedFiles Changed
Change Categories
BehaviorThe new helpers append an Test Scenarios ExecutedTesting method: dogfood PR CLI + PR package hive, file-based AppHost, Scenario 1: Artifact version verificationCoverage Type: Verification
Scenario 2:
|
| Scenario | Status | Notes |
|---|---|---|
| 1. Version verification | ✅ Passed | CLI 13.5.0-pr.18728.g1cf1eaaa matches head SHA |
2. WithContainerInstanceDelegation() |
✅ Passed | ACI serviceName + defaulted name in Bicep |
3. WithServiceDelegation explicit name |
✅ Passed | Custom name + serviceName in Bicep |
4. Empty serviceName (unhappy) |
✅ Passed | ArgumentException, exit code 6 |
| 5. Last-write-wins (boundary) | ✅ Passed | Only last delegation renders |
Overall Result
✅ PR VERIFIED
The new WithServiceDelegation / WithContainerInstanceDelegation helpers compile against the
PR package, produce the correct Bicep delegations output end-to-end, default the delegation
name to the service name, honor last-write-wins semantics, and guard invalid input. Behavior of
the existing WithDelegatedSubnet path is unchanged.
Notes / Observations
- The entire
Aspire.Hosting.Azure.Networksurface is[Experimental("ASPIREAZURE003")]; the
AppHost required#pragma warning disable ASPIREAZURE003. This is expected and consistent with
the rest of the package (not specific to this PR).
- WithServiceDelegation now uses ResourceAnnotationMutationBehavior.Replace so repeated calls keep a single delegation annotation (true last-write-wins in the app model, not just at Bicep emit time). This matches the repo's hosting-azure guidance for override-style annotations. - Route WithDelegatedSubnet's subnet delegation through WithServiceDelegation so all delegation producers share the Replace behavior and Replace never encounters pre-existing duplicates. Generated Bicep is unchanged. - Validate the delegation name (after defaulting to serviceName) so an explicitly empty name is rejected up front instead of emitting an invalid empty delegation name at deployment time. - Add tests: repeated-call last-write-wins, empty name throws, empty serviceName throws. Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
Exercise withServiceDelegation and withContainerInstanceDelegation in the Azure Network polyglot validation AppHosts (TypeScript, Go, Java, Python) so the generated SDK signatures (including the optional delegation name) and RPC dispatch are compiled and invoked, not just covered by C# unit tests. Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
The Azure SQL admin deployment script and AKS AddLoadBalancer both appended an AzureSubnetServiceDelegationAnnotation directly. On a user-supplied subnet that already carried a delegation, this left two delegation annotations, which later makes WithServiceDelegation/WithDelegatedSubnet throw (its Replace path calls SingleOrDefault()). Both producers now route through WithServiceDelegation (Replace), keeping each subnet to a single delegation annotation. AKS still captures the displaced service name for its deploy-time warning. The SQL publish-time FakeBuilder now honors Replace so routing through WithServiceDelegation actually dedupes. Adds tests covering user-delegated subnets for both producers. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 169faa4f-22f3-4188-977d-c50858dc7adb
…port Resolves conflicts from App Service delegated subnet support (#18738) with the new WithServiceDelegation/WithContainerInstanceDelegation helpers, and addresses review feedback: - WithDelegatedSubnet keeps main's guards (reject a second delegated subnet on the target, and reject delegating a subnet to a different service) and routes its annotation append through WithServiceDelegation for shared last-write-wins and duplicate normalization. - WithServiceDelegation collapses any pre-existing delegation annotations before appending, so Replace's SingleOrDefault never throws when a subnet already carries directly-appended delegations. - WithServiceDelegation remarks reworded: the single-delegation behavior is an Aspire modeling choice, not an Azure limitation (Azure allows one or more). - AKS AddLoadBalancer reads the existing delegation via LastOrDefault instead of SingleOrDefault so a subnet with multiple direct delegations does not throw. - Merged both sides' tests; added coverage for collapsing pre-existing delegations (vnet + AKS). Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe88a444-9650-4bac-9e2d-041d909884ab
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Status update: deployment E2E validated, no regressionsFollowing up on my earlier comment about holding this until deployment E2E was healthy again — #18854 has merged, so I merged Run: https://github.com/microsoft/aspire/actions/runs/30518594260 Result: 27 passed / 16 failed, and the job-by-job conclusions are identical to the Delegation-relevant tests — all green ✅These exercise two of the three delegation producers this PR reroutes through
Locally: build is clean (0 warnings / 0 errors) and the targeted unit suites pass 88/88 ( Remaining gap
|
|
Thanks for doing the full matrix comparison and closing the loop, Mitch. The job-for-job parity with Agreed that the remaining AGC path is an infrastructure-blocked validation gap rather than a reason to hold this PR. Once #18933 is resolved, we should rerun |
The constants class was added so app authors stop hand-writing Azure
delegation strings, but without [AspireValue] the values are never
snapped during ATS scanning, so guest SDKs (Python/TypeScript/Go/Java)
never receive them. The sibling AzureServiceTags class in
Aspire.Hosting.Azure.Network marks all of its constants this way.
The api/*.ats.txt baseline is regenerated, not hand-edited:
aspire sdk dump --format ci --output-directory <out> \
src/Aspire.Hosting.Azure/Aspire.Hosting.Azure.csproj
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 539ca445-ef46-4c0d-866e-26f84860e064
Mitch Denny (mitchdenny)
left a comment
There was a problem hiding this comment.
Approving.
Deployment verified across all four delegation constants:
| Constant | Proven by |
|---|---|
AppServiceEnvironments |
CI — AppServiceStoragePrivateEndpointDeploymentTests / AppServiceReactDeploymentTests assert the ARM delegation explicitly |
ContainerAppEnvironments |
CI — VnetSqlServerInfra / VnetKeyVaultInfra / VnetStorageBlobInfra (ARM rejects an ACA env in an undelegated subnet, so success implies a correct value) |
ContainerInstances |
CI — SQL admin deployment-script path in VnetSqlServerInfra* |
ApplicationGatewayForContainers |
Manual AKS run — every AKS job is blocked by #18933 before it reaches this path |
Deployment E2E run 30518594260 on the merged head was byte-for-byte identical to the main baseline (run 30512721600) — no regressions from this PR.
Because CI cannot currently reach the AGC path, I ran a manual AKS smoke test against live Azure (centralus):
Subnet Count State Svc
aks-nodes 0 Succeeded
alb-public 1 Succeeded Microsoft.ServiceNetworking/trafficControllers
aci 1 Succeeded Microsoft.ContainerInstance/containerGroups
Cluster Running (k8s 1.35.6), ingressProfile.gatewayApi.installation: Standard, Network Contributor granted to the AGC identity on the delegated subnet, ApplicationLoadBalancer CR live in-cluster. The displacement case — subnet pre-delegated to ACI, then AddLoadBalancer — correctly collapsed to exactly one delegation, as did three chained WithServiceDelegation calls.
I pushed one commit to this branch: AzureSubnetServiceDelegations was missing [AspireValue], so its values were never snapped during ATS scanning and never reached the Python/TypeScript/Go/Java guest SDKs — meaning the magic strings this class exists to eliminate would have remained hand-written in four of five languages. The sibling AzureServiceTags marks all 15 of its constants this way. The api/*.ats.txt baseline is regenerated via aspire sdk dump --format ci, not hand-edited.
Two non-blocking follow-ups worth a look at some point:
ArgumentException.ThrowIfNullOrEmpty(serviceName)accepts" ", which flows straight into Bicep asserviceName: ' 'and fails later as an opaque ARM error.ThrowIfNullOrWhiteSpacewould catch it at the call site. (Confirmed empirically.)AddLoadBalancerand the SQL admin-script path silently displace an existing delegation, whereasWithDelegatedSubnetthrows on the same conflict. The asymmetry is probably deliberate, but it's worth being intentional about.
Separately, #18933's root cause is a product defect rather than a test one: Standard_D2s_v5 is no longer offered in centralus, and it's hardcoded in three places (AksPipeline.cs:154, AzureKubernetesEnvironmentExtensions.cs:166 and :219). Any user calling AddAzureKubernetesEnvironment in that region fails unless they override both pools. Not this PR's problem — I'll file it separately.
Tests selector (audit mode)The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement. 11 / 100 test projects · 4 jobs, from 16 changed files. Selected test projects (11 / 100)
Selected jobs (4)
How these were chosen — grouped by what changed
🔧 🔧 🔧 🔧 🔧 🔧 🔧 🔧 🔧 🧪 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/Aspire.Hosting.Azure.Network/AzureVirtualNetworkExtensions.cs:329
- This changes existing
WithDelegatedSubnetbehavior despite the PR description saying it is unchanged. Previously the method searched all delegation annotations and rejected any conflicting service; usingLastOrDefault()now accepts an older conflicting annotation whenever the last annotation matches, then collapses it (as the new test explicitly demonstrates). Either preserve the existing conflict validation or document and justify this compatibility change in the PR description.
var existingDelegation = subnet.Resource.Annotations
.OfType<AzureSubnetServiceDelegationAnnotation>()
.LastOrDefault();
src/Aspire.Hosting.Azure.Network/AzureVirtualNetworkExtensions.cs:380
- The PR description and usage example promise
WithContainerInstanceDelegation(), but the current public surface only addsWithServiceDelegation; the convenience method is absent from the implementation, API baseline, and all four polyglot fixtures. As written, the documented example does not compile. Restore the helper with its C# and generated-SDK coverage, or update the stated scope and example if it was intentionally removed.
[AspireExport]
public static IResourceBuilder<AzureSubnetResource> WithServiceDelegation(
this IResourceBuilder<AzureSubnetResource> builder,
string serviceName,
string? name = null)
- Files reviewed: 16/16 changed files
- Comments generated: 0 new
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
|
📝 Documentation has been drafted in microsoft/aspire.dev#1519 targeting Added a "Delegate a subnet to any Azure service" section to the Azure Virtual Network reference page documenting the new Note This draft PR needs human review before merging. |
Description
Delegating an Azure subnet to a service currently requires manually constructing an annotation with a duplicated service-name string, which is not discoverable and is error-prone:
This adds first-class fluent helpers on
IResourceBuilder<AzureSubnetResource>:WithServiceDelegation(string serviceName, string? name = null)— generic helper that appends anAzureSubnetServiceDelegationAnnotation, defaulting the delegationnametoserviceNameso callers don't repeat the value. Follows the same last-write-wins semantics asWithDelegatedSubnet(the subnet emits only its most recent delegation).WithContainerInstanceDelegation()— typed convenience wrapper that delegates the subnet to Azure Container Instances (Microsoft.ContainerInstance/containerGroups).Usage:
Existing
WithDelegatedSubnetbehavior and generated output are unchanged. The public API baseline (api/Aspire.Hosting.Azure.Network.cs) was updated and verified byte-identical to GenAPI output viapack.Checklist
<remarks />and<code />elements on your triple slash comments?