Skip to content

Enforce explicit compute environment binding#16411

Open
eerhardt wants to merge 4 commits intomicrosoft:mainfrom
eerhardt:ThrowForMultipleComputeEnvironments
Open

Enforce explicit compute environment binding#16411
eerhardt wants to merge 4 commits intomicrosoft:mainfrom
eerhardt:ThrowForMultipleComputeEnvironments

Conversation

@eerhardt
Copy link
Copy Markdown
Member

Throw if compute resources are unbound when multiple compute environments exist, preventing ambiguous deployments. Update summary comments to clarify behavior. Add tests to verify exception is thrown for unbound resources, no exception when all are bound, and auto-binding with a single environment.

This was the behavior originally in Allow multiple compute environment resources in an app model (microsoft/aspire#8820). However, Fix: Skip resources targeted to different compute environments (microsoft/aspire#14177) broke this behavior to no longer throw - and compute resources silently were ignored.

Throw if compute resources are unbound when multiple compute environments exist, preventing ambiguous deployments. Update summary comments to clarify behavior. Add tests to verify exception is thrown for unbound resources, no exception when all are bound, and auto-binding with a single environment.
Copilot AI review requested due to automatic review settings April 23, 2026 23:00
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16411

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16411"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores/strengthens compute-environment disambiguation in the hosting model by failing fast when multiple compute environments exist but one or more compute resources are left unbound, avoiding ambiguous (or inconsistent) deployment targeting.

Changes:

  • Add validation in DistributedApplication.EnsureComputeEnvironmentAnnotationsApplied to throw when multiple compute environments exist and any IComputeResource lacks a ComputeEnvironmentAnnotation.
  • Update the XML documentation on compute-environment annotation application/validation behavior.
  • Add unit tests covering: throw-on-unbound with multiple environments, no-throw when all bound, and auto-binding when a single environment exists.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Aspire.Hosting/DistributedApplication.cs Adds multi-environment validation (throw on unbound compute resources) and updates the documentation for compute-environment binding behavior.
tests/Aspire.Hosting.Tests/ComputeEnvironmentValidationTests.cs Introduces targeted unit tests for the multi/single environment binding and validation behavior.

Comment thread src/Aspire.Hosting/DistributedApplication.cs Outdated
Comment thread src/Aspire.Hosting/DistributedApplication.cs Outdated
Comment thread tests/Aspire.Hosting.Tests/ComputeEnvironmentValidationTests.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants