Skip to content

Fix port mismatch for bait-and-switch resources in Kubernetes publisher#14651

Closed
joperezr wants to merge 4 commits intorelease/13.2from
cherry-pick/k8s-bait-and-switch-fix
Closed

Fix port mismatch for bait-and-switch resources in Kubernetes publisher#14651
joperezr wants to merge 4 commits intorelease/13.2from
cherry-pick/k8s-bait-and-switch-fix

Conversation

@joperezr
Copy link
Member

Cherry-pick of #14590 into release/13.2.

The original PR was accidentally retargeted from main to release/13.2, which brought all main branch commits along. This PR contains only the original commits by @bbartels with the fix.

Description

The Kubernetes publisher uses a Dictionary<IResource, KubernetesResource> cache in KubernetesEnvironmentContext keyed by object identity. When PublishAsDockerFile() replaces an ExecutableResource with an ExecutableContainerResource (the 'bait and switch' pattern), other resources still hold EndpointReference objects pointing to the original. The cache misses on the original vs replacement, creating two KubernetesResource objects for the same logical resource, each allocating a different port from the shared PortAllocator. This causes the referencing resource to get a different port than the one in the service/deployment YAML.

The fix applies the same ResourceNameComparer pattern already used by the Docker Compose, Azure App Service, and Azure Container Apps publishers.

Fixes #9226

Copilot AI review requested due to automatic review settings February 24, 2026 17:31
@joperezr joperezr added this to the 13.2 milestone Feb 24, 2026
Copy link
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.

Copilot wasn't able to review any files in this pull request.

@github-actions
Copy link
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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14651

Or

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

@joperezr
Copy link
Member Author

Closing for now — the revert PR needs to merge first to avoid conflicts. Will recreate after that.

@joperezr joperezr closed this Feb 24, 2026
@dotnet-policy-service dotnet-policy-service bot modified the milestone: 13.2 Feb 24, 2026
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.

3 participants