Fix port mismatch for bait-and-switch resources in Kubernetes publisher (13.2)#14627
Fix port mismatch for bait-and-switch resources in Kubernetes publisher (13.2)#14627mitchdenny wants to merge 6 commits intorelease/13.2from
Conversation
|
/deployment-test |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14627Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14627" |
|
🚀 Deployment tests starting on PR #14627... This will deploy to real Azure infrastructure. Results will be posted here when complete. |
There was a problem hiding this comment.
Pull request overview
This PR is a cherry-pick of #14590 targeting the release/13.2 branch. It fixes a port mismatch bug in the Kubernetes publisher that occurs when resources are replaced during the "bait-and-switch" pattern (e.g., when PublishAsDockerFile() replaces an ExecutableResource with an ExecutableContainerResource). The fix applies the same ResourceNameComparer pattern already used successfully by the Docker Compose, Azure App Service, and Azure Container Apps publishers.
Changes:
- Modified
KubernetesEnvironmentContextto useResourceNameComparerfor resource dictionary lookups by name instead of object identity - Added comprehensive test coverage with snapshot verification for the bait-and-switch scenario
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentContext.cs | Added ResourceNameComparer to the _kubernetesComponents dictionary to enable name-based resource lookups |
| tests/Aspire.Hosting.Kubernetes.Tests/KubernetesPublisherTests.cs | Added new test KubernetesMapsPortsForBaitAndSwitchResources to verify consistent port allocation |
| tests/Aspire.Hosting.Kubernetes.Tests/Snapshots/*.verified.yaml | Seven snapshot files verifying correct YAML generation with consistent port 8000 across all configurations |
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #22327060851 |
|
❌ Deployment E2E Tests failed Summary: 22 passed, 1 failed, 0 cancelled Passed Tests
Failed Tests
🎬 Terminal Recordings
|
Cherry-pick of #14590 targeting release/13.2 for deployment testing.
Description
The Kubernetes publisher uses a
Dictionarycache inKubernetesEnvironmentContextkeyed by object identity. WhenPublishAsDockerFile()replaces anExecutableResourcewith anExecutableContainerResource(the "bait and switch" pattern), other resources still holdEndpointReferenceobjects pointing to the original. The cache misses on the original vs replacement, creating twoKubernetesResourceobjects for the same logical resource, each allocating a different port from the sharedPortAllocator. This causes the referencing resource to get a different port than the one in the service/deployment YAML.The fix applies the same
ResourceNameComparerpattern already used by the Docker Compose, Azure App Service, and Azure Container Apps publishers.Fixes #9226
Based on community PR #14590 by @bbartels