You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support existing Azure Kubernetes environments - #20921
Allow Aspire applications to deploy to a pre-provisioned AKS cluster using the shared Azure AsExisting APIs, following the Azure Container Apps and App Service approach.
Existing clusters are referenced without reconfiguring their node pools, networking, or add-ons. Aspire does not create or implicitly select a workload node pool for them. Supporting infrastructure remains in the application's resource group, while deployment credentials and workload cleanup target the cluster's actual identity. OIDC is only required when workloads use workload identity.
The implementation reuses existing API signatures and introduces no dependencies. The README documents prerequisites and warns that the cluster must be outside the application's resource group to survive aspire destroy.
dotnet build tests/Aspire.Deployment.EndToEnd.Tests/Aspire.Deployment.EndToEnd.Tests.csproj --no-restore - passed, no warnings or errors.
gh workflow run deployment-tests.yml --repo microsoft/aspire --ref mitchdenny-existing-aks-environments -f test_filter=AksExistingClusterDeploymentTests - passed, including the full CI build and live deployment test on commit 225b03c23ca9e170b7a749a2ff1c04cdd5605e19 (1 passed, 0 skipped).
The new E2E test creates an AKS cluster with Azure CLI and passes its complete resource ID as a deployment parameter. It verifies the deployed API response, unchanged cluster configuration, and absence of a second cluster in the application's resource group. It then runs aspire destroy, verifies that workloads are removed and the existing cluster survives, and requests cleanup of both test-owned resource groups.
The bootstrap explicitly verifies that OIDC and workload identity are disabled. It uses Kubernetes 1.33 with AKS Long-Term Support because newly created 1.34+ clusters enable OIDC by default and cannot disable it afterward. Regression coverage also verifies subscription inheritance for resource-group-only existing references, preview API selection for existing clusters with ALB, and preservation of annotation-based module scope for Sandbox groups and Foundry projects.
Checklist
Is this feature complete?
Yes. Ready to ship.
No. Follow-up changes expected.
Are you including unit tests for the changes and scenario tests if relevant?
Yes
No
Did you add public API?
Yes
If yes, did you have an API Review for it?
Yes
No
Did you add <remarks /> and <code /> elements on your triple slash comments?
Yes
No
No
Does the change make any security assumptions or guarantees?
Yes
If yes, have you done a threat model and had a security review?
The reason will be displayed to describe this comment to others. Learn more.
Found 2 correctness issues: partial existing-cluster scope resolution can target the wrong subscription, and existing clusters with an ALB retain a stable API version that cannot expose the required controller identity. Both were reproduced with focused regression probes. Validation: 92 AKS tests and 31 BicepUtilities tests passed; three unchanged snapshot tests failed due to local CRLF line endings. Confirmed the PR live deployment run passed on the reviewed commit, but it does not cover these edge cases.
The fixed local port makes this deployment test fail whenever port 18080 is already occupied, which is a known flaky-test pattern in this repository. Allocate an available port and pass it to both kubectl port-forward and curl; AksPersistentVolumeDeploymentTests.GetAvailablePort() demonstrates the existing approach.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
For existing Sandbox groups, conflicting scope precedence can direct role assignments and resource references to a different group than the primary deployment, causing deployment failures or incorrect permission grants.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Annotation-first scope resolution overrides explicit module scope for sandbox resources, causing cross-module references and role assignments to target the wrong resource or fail deployment.
Record module-scoped existing declarations in shared provisioning and materialize their source before resolving cross-template references. Cover conflicting Sandbox scopes without changing AKS independent-reference semantics.
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 14f4e734-0b32-464c-8c0c-37babdc5349c
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A group-only existing-cluster reference can remain pinned to the initial subscription after a callback override, leaving it inconsistent with cluster-role modules; scope resolution needs correction and regression coverage.
Keep the source declaration scoped to its annotation without capturing the module's initial subscription. Cross-template references inherit the finalized subscription after source configuration. Extend publish and consumer regressions with initial scopes overridden by callbacks.
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 14f4e734-0b32-464c-8c0c-37babdc5349c
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because existing-cluster configurations with an ALB subnet in another resource group can generate role assignments that Bicep rejects.
The full, unfiltered deployment matrix completed. No failure attributable to this PR was found. The workflow is red because one Sandbox test reproduces an independent failure on main; this is not a completely green run.
Result: failed, solely due to the Sandbox test described below.
No source, tests, snapshots, workflow, or environment configuration was changed. No fix or retry was applied.
Coverage
Measurement
Result
All workflow jobs
63: 61 succeeded, 1 failed, 1 skipped
Deployment matrix jobs
58: 57 succeeded, 1 failed
Actual test results across all 58 deployment jobs
71 total: 69 passed, 1 failed, 1 skipped
AKS coverage
All 14 AKS jobs / 15 tests passed, with no skips
Existing-AKS resource-ID scenario
Passed
Cross-resource-group AKS registry scenarios
Both tests passed
Other deployment coverage
ACA, App Service, Foundry, Front Door, Entra, resource scopes, run-mode role assignments, and other enabled scenarios passed
Every deployment job has a test summary; no deployment matrix entry was omitted or cancelled. The one skipped workflow job is the conditional issue-creation job, not a deployment job.
The Connector Namespace matrix job succeeded, but its single test was dynamically skipped because ASPIRE_DEPLOYMENT_TEST_ENABLE_CONNECTOR_NAMESPACE=false. The logged reason requires preview enrollment before opt-in. Connector Namespace deployment behavior is therefore unvalidated, not passed. No environment flag was changed to bypass that prerequisite.
Sole failure: Sandbox protected frontend port registration
The deployment reached the Sandbox data-plane operation POST .../sandboxes/<id>/ports/add, which returned HTTP 400 Bad Request during deploy-frontend-sandbox-container. This is a service response, not an assertion failure, build failure, Bicep compilation failure, provisioning timeout, or AKS failure.
The pipeline completed 25 of 27 steps. The anonymous Sandbox deployment and its storage role provisioning succeeded; the protected frontend port registration failed. The second test in the same job, RedeployProjectToAzureSandboxRetainsPreviousPublicUrl, passed.
Relationship to this PR: pre-existing, high confidence
The same test independently failed at the same ports/add operation with HTTP 400 in the same-day main job, at main commit cec61ac9b795bbfd9913f0c7196689b0d7a215d7, without this PR.
The previous main job, at commit 1d3c45f9a299c30d46fc3166148902d466043df2, also failed identically.
This scenario creates a new Sandbox group with AddAzureSandboxGroup("env"); it does not use an existing compute annotation or adopt an AKS cluster. The PR's scope/reference changes specifically affect existing-resource handling. The Sandbox port-registration/authentication code is not changed by the PR.
The directly relevant AKS deployments, including existing-cluster adoption, resource-ID handling, role grants, and cross-group registry access, all passed.
The strongest supported classification is a repeatable pre-existing Sandbox issue, not a regression introduced by this PR. It should not be dismissed as a random flake: independent runs repeatedly fail at the same operation.
What remains uncertain
The service error body is redacted in both the job output and the detailed CLI logs. The exact backend validation rule is consequently unknown. The failing frontend uses the default Entra-protected external endpoint, whereas the explicitly anonymous endpoint succeeds. This narrows the likely area to protected-port configuration or the preview service's handling of it, but does not prove a specific authentication, tenant, request-contract, or service defect.
No claim is made that this is definitely infrastructure-only rather than an existing Sandbox product/API-contract bug. Resolving that distinction requires the service-side rejection reason or a separately scoped Sandbox investigation.
Other previously seen failures
Foundry's previous “Project not found” failure, the custom-registry DNS failure, Entra authorization failure, and Front Door timeout did not occur in this run. They are not current failures and are not counted as such.
Evidence retained
Files are in this session's files/validation/ directory:
Added a "Use an existing AKS cluster" section to the AKS integration page (integrations/cloud/azure/aks/index.mdx). Triggered signals: integration_readme_changed (Aspire.Hosting.Azure.Kubernetes/README.md), pr_body_has_user_facing_section (AsExisting / AsExistingInResourceGroup usage), pr_body_has_cli_flag_mention.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Allow Aspire applications to deploy to a pre-provisioned AKS cluster using the shared Azure
AsExistingAPIs, following the Azure Container Apps and App Service approach.Existing clusters are referenced without reconfiguring their node pools, networking, or add-ons. Aspire does not create or implicitly select a
workloadnode pool for them. Supporting infrastructure remains in the application's resource group, while deployment credentials and workload cleanup target the cluster's actual identity. OIDC is only required when workloads use workload identity.The implementation reuses existing API signatures and introduces no dependencies. The README documents prerequisites and warns that the cluster must be outside the application's resource group to survive
aspire destroy.Fixes #17711
User-facing usage
AsExisting
Use an existing cluster in the current subscription scope. Pass a resource-group parameter, or
nullto use the application's resource group.AsExistingInResourceGroup
Use an existing cluster with an explicit resource group and subscription.
Validation
dotnet test --project tests/Aspire.Hosting.Azure.Kubernetes.Tests/Aspire.Hosting.Azure.Kubernetes.Tests.csproj --no-launch-profile -- --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'- passed, 126 tests.dotnet test --project tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj --no-launch-profile -- --filter-class '*.BicepUtilitiesTests' --filter-class '*.AzureBicepProvisionerTests' --filter-class '*.AzureBicepResourceTests' --filter-class '*.AzureProvisioningResourceTests' --filter-class '*.AzureBicepResourceScopeTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'- passed, 175 tests.dotnet build tests/Aspire.Deployment.EndToEnd.Tests/Aspire.Deployment.EndToEnd.Tests.csproj --no-restore- passed, no warnings or errors.gh workflow run deployment-tests.yml --repo microsoft/aspire --ref mitchdenny-existing-aks-environments -f test_filter=AksExistingClusterDeploymentTests- passed, including the full CI build and live deployment test on commit225b03c23ca9e170b7a749a2ff1c04cdd5605e19(1 passed, 0 skipped).The new E2E test creates an AKS cluster with Azure CLI and passes its complete resource ID as a deployment parameter. It verifies the deployed API response, unchanged cluster configuration, and absence of a second cluster in the application's resource group. It then runs
aspire destroy, verifies that workloads are removed and the existing cluster survives, and requests cleanup of both test-owned resource groups.The bootstrap explicitly verifies that OIDC and workload identity are disabled. It uses Kubernetes 1.33 with AKS Long-Term Support because newly created 1.34+ clusters enable OIDC by default and cannot disable it afterward. Regression coverage also verifies subscription inheritance for resource-group-only existing references, preview API selection for existing clusters with ALB, and preservation of annotation-based module scope for Sandbox groups and Foundry projects.
Checklist
<remarks />and<code />elements on your triple slash comments?