Skip to content

Fix Radius service discovery to match the recipe's ClusterIP Service - #18797

Merged
Mitch Denny (mitchdenny) merged 7 commits into
microsoft:mainfrom
nellshamrell:enhance-deployment-test
Jul 30, 2026
Merged

Mitch Denny (mitchdenny) merged 7 commits into
microsoft:mainfrom
nellshamrell:enhance-deployment-test

Conversation

@nellshamrell

Copy link
Copy Markdown
Contributor

Description

Aspire's Radius publisher (src/Aspire.Hosting.Radius) delegates Kubernetes Service creation to an external recipe (kubernetes-containers.bicep, radius-project/resource-types-contrib). Unlike the Kubernetes publisher — which owns both the Service and the addresses it emits — Radius does not create the Service itself, so the service-discovery values Aspire emits into consumer containers (the services__* env vars) must exactly match what the recipe creates. They didn't, so cross-container calls could not resolve in-cluster: for example, deploying the Aspire Starter template to a Radius-enabled cluster and opening the Blazor /weather page failed because webfrontend → apiservice never resolved.

This change makes the emitted service-discovery values match the recipe's ClusterIP Service.

What changed (user-visible behavior)

For resources deployed via a Radius compute environment, the services__* values now address the Service the recipe actually creates:

  • Host is {name}-{name}.{namespace}.svc.cluster.local — the recipe names the Service ${normalizedName}-${containerName}, and for an Aspire-emitted container both segments equal the resource name (previously Aspire emitted the bare {name}).
  • Port is the container port (the recipe Service listens on port == targetPort == containerPort), not the proxy/host port (previously the http default port, which was omitted).
  • A containerized project's default HTTP endpoint now declares a container port (8080, matching the Kubernetes publisher) so the recipe creates a Service for it; the synthetic default HTTPS endpoint is skipped (no in-cluster TLS termination).
  • Endpoints that resolve to the same (container port, protocol) are de-duplicated so the recipe never emits a Service with duplicate ports.

Implementation

  • New internal RadiusServiceDiscovery helper is the single source of truth for the recipe Service name and port. Port resolution delegates to the framework's ResourceExtensions.ResolveEndpoints() — the same primitive the Kubernetes publisher uses — so the container port emitted into the Bicep and the port emitted into services__* URLs cannot disagree.
  • RadiusEnvironmentResource.GetHostAddressExpression emits the {name}-{name} FQDN; a new GetEndpointPropertyExpression override sources Url/Port/HostAndPort/TargetPort from the same resolved container port.
  • RadiusInfrastructureBuilder.ResolvePorts resolves ports through the shared helper and de-duplicates by (container port, protocol), mirroring the Kubernetes publisher's ToService dedup.
  • Reading the synthetic DefaultHttpsEndpoint requires internals access, granted via InternalsVisibleTo on Aspire.Hosting (mirroring Aspire.Hosting.Kubernetes).

This branch also includes an earlier commit adding a Radius Azure-resource gap test and Redis-cache diagnostics to the Radius E2E test.

Validation

  • Radius project builds clean; 196/196 Aspire.Hosting.Radius.Tests pass (excluding quarantined/outerloop). New unit tests cover the name/port resolver, per-endpoint-property emission, the port dedup, and the container-name rename guard.
  • Aspire.Deployment.EndToEnd.Tests compiles. The RadiusStarterDeploymentTests /weather and direct-apiservice assertions are un-skipped and now also assert the apiservice-apiservice Service and its container port. The live AKS deploy runs via the deploy-test pipeline, not locally.

Fixes # (issue)

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?
        • Yes
        • No
    • No

Copilot AI review requested due to automatic review settings July 15, 2026 21:54
@github-actions

Copy link
Copy Markdown
Contributor

🚀 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 -- 18797

Or

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

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Aligns Radius service discovery with the Kubernetes ClusterIP Services created by its external recipe.

Changes:

  • Uses recipe Service names and container ports for discovery.
  • Adds endpoint deduplication and container-name validation.
  • Expands unit and deployment coverage, including Radius diagnostics.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/Aspire.Hosting.Radius.Tests/RadiusEnvironmentResourceTests.cs Tests Radius endpoint expressions.
tests/Aspire.Hosting.Radius.Tests/Publishing/RadiusServiceDiscoveryTests.cs Tests Service naming and port resolution.
tests/Aspire.Hosting.Radius.Tests/Publishing/ContainerEnvironmentEmissionTests.cs Verifies discovery URLs and port deduplication.
tests/Aspire.Hosting.Radius.Tests/Publishing/ConfigureRadiusInfrastructureTests.cs Tests container-name validation.
tests/Aspire.Deployment.EndToEnd.Tests/README.md Documents Radius deployment coverage.
tests/Aspire.Deployment.EndToEnd.Tests/RadiusStarterDeploymentTests.cs Adds live connectivity diagnostics.
tests/Aspire.Deployment.EndToEnd.Tests/RadiusAzureResourcesDeploymentTests.cs Adds Azure-reference gap coverage.
src/Aspire.Hosting/Aspire.Hosting.csproj Grants Radius internal access.
src/Aspire.Hosting.Radius/RadiusEnvironmentResource.cs Emits recipe-compatible endpoint values.
src/Aspire.Hosting.Radius/Publishing/RadiusServiceDiscovery.cs Centralizes Service naming and ports.
src/Aspire.Hosting.Radius/Publishing/RadiusInfrastructureBuilder.cs Resolves ports, deduplicates, and validates names.
src/Aspire.Hosting.Radius/Publishing/Constructs/RadiusContainerConstruct.cs Exposes the immutable container map key internally.

Nell Shamrell-Harrington (nellshamrell) added a commit to nellshamrell/aspire that referenced this pull request Jul 15, 2026
…iew feedback

Addresses review findings on PR microsoft#18797:
- Fail fast when the doubled '{name}-{name}' recipe Service name would exceed
  the 63-character Kubernetes DNS-label limit.
- Reject non-literal container-name renames and container-port changes/removals
  in ConfigureRadiusInfrastructure callbacks, since service discovery is emitted
  before callbacks run and would otherwise silently point at a stale name/port.
- Strengthen the E2E Step 29 assertion to verify the full recipe contract
  (type == ClusterIP, port == targetPort == 8080).
- Correct the stale Step 26 comment that claimed the recipe creates no Service.

Adds regression tests for the new publish-time validations.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Copilot AI review requested due to automatic review settings July 15, 2026 23:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Nell Shamrell-Harrington (nellshamrell) added a commit to nellshamrell/aspire that referenced this pull request Jul 16, 2026
Respond to Copilot review feedback on microsoft#18797:

- Key the pre-callback container-port snapshot by the stable app-model map key
  (resource name) and capture protocol as well as port, so a callback that swaps
  in a new construct or changes only the protocol is still validated.
- Reject non-literal container names/ports/protocols using a non-null Bicep
  Expression as the signal (an expression-backed BicepValue<int> reports a
  default LiteralValue of 0, not null).
- Detect removal/replacement of a whole container, not just port changes.
- Run the Kubernetes 63-char Service-name length check on the FINAL container
  set so a callback that adds the first port to a portless container is caught.
- Reword the container-name guard to attribute the restriction to Aspire
  service discovery, not the Radius v2 schema (which permits differing keys).
- Fix the ResolveServicePort XML-doc bullets to document that the first portless
  HTTP/HTTPS project endpoint defaults to 8080 while the synthetic default HTTPS
  endpoint returns null.
- Pin the recipe doc-link to an immutable commit SHA so the documented
  Service-name/port contract can be verified even if the recipe's main moves.
- Rewrite the Radius/Azure cloud-managed-resource gap test to assert the
  intended fail-fast behavior and mark it [ActiveIssue(microsoft#18802)]; pin its
  container image to aci-helloworld@sha256.

Add regression tests for protocol change, non-literal port, whole-container
removal, and post-callback port addition on a too-long name. Radius unit
tests: 204/204.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Copilot AI review requested due to automatic review settings July 16, 2026 00:35
Nell Shamrell-Harrington (nellshamrell) added a commit to nellshamrell/aspire that referenced this pull request Jul 16, 2026
…iew feedback

Addresses review findings on PR microsoft#18797:
- Fail fast when the doubled '{name}-{name}' recipe Service name would exceed
  the 63-character Kubernetes DNS-label limit.
- Reject non-literal container-name renames and container-port changes/removals
  in ConfigureRadiusInfrastructure callbacks, since service discovery is emitted
  before callbacks run and would otherwise silently point at a stale name/port.
- Strengthen the E2E Step 29 assertion to verify the full recipe contract
  (type == ClusterIP, port == targetPort == 8080).
- Correct the stale Step 26 comment that claimed the recipe creates no Service.

Adds regression tests for the new publish-time validations.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Nell Shamrell-Harrington (nellshamrell) added a commit to nellshamrell/aspire that referenced this pull request Jul 16, 2026
Respond to Copilot review feedback on microsoft#18797:

- Key the pre-callback container-port snapshot by the stable app-model map key
  (resource name) and capture protocol as well as port, so a callback that swaps
  in a new construct or changes only the protocol is still validated.
- Reject non-literal container names/ports/protocols using a non-null Bicep
  Expression as the signal (an expression-backed BicepValue<int> reports a
  default LiteralValue of 0, not null).
- Detect removal/replacement of a whole container, not just port changes.
- Run the Kubernetes 63-char Service-name length check on the FINAL container
  set so a callback that adds the first port to a portless container is caught.
- Reword the container-name guard to attribute the restriction to Aspire
  service discovery, not the Radius v2 schema (which permits differing keys).
- Fix the ResolveServicePort XML-doc bullets to document that the first portless
  HTTP/HTTPS project endpoint defaults to 8080 while the synthetic default HTTPS
  endpoint returns null.
- Pin the recipe doc-link to an immutable commit SHA so the documented
  Service-name/port contract can be verified even if the recipe's main moves.
- Rewrite the Radius/Azure cloud-managed-resource gap test to assert the
  intended fail-fast behavior and mark it [ActiveIssue(microsoft#18802)]; pin its
  container image to aci-helloworld@sha256.

Add regression tests for protocol change, non-literal port, whole-container
removal, and post-callback port addition on a too-long name. Radius unit
tests: 204/204.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings July 16, 2026 00:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Nell Shamrell-Harrington (nellshamrell) added a commit to nellshamrell/aspire that referenced this pull request Jul 16, 2026
Respond to the follow-up Copilot review on microsoft#18797:

- Skip the container-preservation check for empty (portless) port snapshots so a
  ConfigureRadiusInfrastructure callback can remove a portless container. A
  portless container has no ClusterIP Service and no `services__*` value can
  address it, so removing it is harmless and must not be rejected. Add a
  regression test asserting the removal succeeds.
- Correct three doc/comment locations that still attributed the container
  name==map-key equality to the Radius v2 schema/recipe. Radius permits distinct
  top-level and container-map names; equality is an Aspire service-discovery
  limitation. Reword RadiusServiceDiscovery remarks, RadiusContainerConstruct
  ContainerMapKey doc, and the ConfigureCallback_RenamingContainerName_Throws
  test comment accordingly.
- Update the deployment E2E README section for the Radius/Azure gap test to
  describe the new [ActiveIssue(microsoft#18802)]-skipped, fail-fast-asserting test and
  instruct maintainers to remove [ActiveIssue] when the gap is closed.

Radius unit tests: 205/205.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Copilot AI review requested due to automatic review settings July 16, 2026 21:22
…ius E2E

Add RadiusAzureResourcesDeploymentTests documenting the current gap where
publishing a Radius container that WithReferences a cloud-managed Azure
resource hangs resolving Azure Bicep outputs. Add Redis output-cache and
direct apiservice diagnostic endpoints to the Starter Radius E2E and assert
the cache path; the direct apiservice/weather assertions remain gated pending
confirmation of the Radius container Service DNS.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Aspire's Radius publisher delegates Kubernetes Service creation to an
external recipe (radius-project/resource-types-contrib
kubernetes-containers.bicep), but emitted service-discovery values did not
match what that recipe creates, so cross-container calls (e.g. a Blazor
/weather page calling apiservice) could not resolve in-cluster.

Align the emitted services__* values with the recipe contract:

- Host: the recipe names the ClusterIP Service {name}-{name}, not the bare
  resource name. GetHostAddressExpression now emits
  {name}-{name}.{ns}.svc.cluster.local via a shared RadiusServiceDiscovery
  helper (single source of truth for the Service name).
- Port: the recipe Service listens on the container port (port ==
  targetPort == containerPort), not the proxy/host port. Override
  GetEndpointPropertyExpression so Url/Port/HostAndPort/TargetPort all use
  the resolved container port from the same helper the Bicep container-port
  emission uses, so the URL and the generated Service can never disagree.
- Service existence: resolve ports through the framework's
  ResolveEndpoints() (the same primitive the Kubernetes publisher uses) so
  a containerized project's default HTTP endpoint gets the standard
  container port (8080) and the recipe creates a Service; the synthetic
  default HTTPS endpoint is skipped (no in-cluster TLS). Reading
  DefaultHttpsEndpoint requires internals access, granted via
  InternalsVisibleTo mirroring Aspire.Hosting.Kubernetes.
- Dedup: multiple endpoints can resolve to the same (containerPort,
  protocol); ResolvePorts now deduplicates them (first wins), matching the
  Kubernetes publisher's ToService dedup, so the recipe never emits
  duplicate Service ports.

Unit tests cover the resolver, per-property emission, the dedup, and the
container-name rename guard. The RadiusStarterDeploymentTests /weather and
direct apiservice assertions are un-skipped and now assert the
apiservice-apiservice Service and its container port. README updated.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
…iew feedback

Addresses review findings on PR microsoft#18797:
- Fail fast when the doubled '{name}-{name}' recipe Service name would exceed
  the 63-character Kubernetes DNS-label limit.
- Reject non-literal container-name renames and container-port changes/removals
  in ConfigureRadiusInfrastructure callbacks, since service discovery is emitted
  before callbacks run and would otherwise silently point at a stale name/port.
- Strengthen the E2E Step 29 assertion to verify the full recipe contract
  (type == ClusterIP, port == targetPort == 8080).
- Correct the stale Step 26 comment that claimed the recipe creates no Service.

Adds regression tests for the new publish-time validations.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Respond to Copilot review feedback on microsoft#18797:

- Key the pre-callback container-port snapshot by the stable app-model map key
  (resource name) and capture protocol as well as port, so a callback that swaps
  in a new construct or changes only the protocol is still validated.
- Reject non-literal container names/ports/protocols using a non-null Bicep
  Expression as the signal (an expression-backed BicepValue<int> reports a
  default LiteralValue of 0, not null).
- Detect removal/replacement of a whole container, not just port changes.
- Run the Kubernetes 63-char Service-name length check on the FINAL container
  set so a callback that adds the first port to a portless container is caught.
- Reword the container-name guard to attribute the restriction to Aspire
  service discovery, not the Radius v2 schema (which permits differing keys).
- Fix the ResolveServicePort XML-doc bullets to document that the first portless
  HTTP/HTTPS project endpoint defaults to 8080 while the synthetic default HTTPS
  endpoint returns null.
- Pin the recipe doc-link to an immutable commit SHA so the documented
  Service-name/port contract can be verified even if the recipe's main moves.
- Rewrite the Radius/Azure cloud-managed-resource gap test to assert the
  intended fail-fast behavior and mark it [ActiveIssue(microsoft#18802)]; pin its
  container image to aci-helloworld@sha256.

Add regression tests for protocol change, non-literal port, whole-container
removal, and post-callback port addition on a too-long name. Radius unit
tests: 204/204.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
Respond to the follow-up Copilot review on microsoft#18797:

- Skip the container-preservation check for empty (portless) port snapshots so a
  ConfigureRadiusInfrastructure callback can remove a portless container. A
  portless container has no ClusterIP Service and no `services__*` value can
  address it, so removing it is harmless and must not be rejected. Add a
  regression test asserting the removal succeeds.
- Correct three doc/comment locations that still attributed the container
  name==map-key equality to the Radius v2 schema/recipe. Radius permits distinct
  top-level and container-map names; equality is an Aspire service-discovery
  limitation. Reword RadiusServiceDiscovery remarks, RadiusContainerConstruct
  ContainerMapKey doc, and the ConfigureCallback_RenamingContainerName_Throws
  test comment accordingly.
- Update the deployment E2E README section for the Radius/Azure gap test to
  describe the new [ActiveIssue(microsoft#18802)]-skipped, fail-fast-asserting test and
  instruct maintainers to remove [ActiveIssue] when the gap is closed.

Radius unit tests: 205/205.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b43262f1-59bc-4b4b-a2b1-33b782363a43
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
@github-actions
github-actions Bot had a problem deploying to deployment-testing July 17, 2026 02:24 Failure
The constructor param doc claimed the Radius v2 schema requires the
properties.containers map key to equal the top-level name. Radius permits
them to differ; Aspire is what requires the match, because it derives
service discovery from the resource name. Align the doc with the
ContainerMapKey summary so the class no longer documents both claims.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b2cc32be-11a3-4f6a-aa39-a7d5cd44c407

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@mitchdenny Mitch Denny (mitchdenny) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed with the code-review skill. This correctly fixes Radius service discovery to target the recipe's ClusterIP Service — clean change with good coverage. I pushed one small doc-comment fix in RadiusContainerConstruct; CI is green.

The Radius deployment E2E can't fully exercise this yet, but only because of a pre-existing infra blocker (#18933): az aks create --node-vm-size Standard_D2s_v5 returns an opaque BadRequest that is region-independent and not quota-related (verified in centralus and southcentralus with fresh quota). That's unrelated to this change, so I'm not holding on it. Follow-up on the compute-env internal dependency is tracked in #18907.

LGTM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants