Add Kubernetes manifest ATS API#16883
Conversation
Add a polyglot-friendly Kubernetes manifest helper that creates custom manifests server-side and returns an opaque handle for configuration. Keep AdditionalResources as the C# customization escape hatch while excluding it from ATS generation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16883Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16883" |
There was a problem hiding this comment.
Pull request overview
Adds a polyglot-friendly way to attach arbitrary Kubernetes manifests to a published Kubernetes service by introducing a server-side KubernetesManifestResource handle and excluding the C#-specific AdditionalResources list from ATS export.
Changes:
- Mark
KubernetesResource.AdditionalResourcesas ATS-ignored and addKubernetesResource.AddManifest(...)for creating/configuring custom manifest resources server-side. - Add
KubernetesManifestResource+ YAML serialization support so custom manifests can be emitted into generated Helm templates. - Update polyglot AppHost samples and add a publisher test that validates a custom manifest is emitted.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/TypeScript/apphost.ts | Demonstrates the new addManifest polyglot API for emitting a custom KEDA-style manifest. |
| tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/Python/apphost.py | Updates Python sample to configure a custom manifest via add_manifest. |
| tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/Java/AppHost.java | Updates Java sample to configure a custom manifest via addManifest. |
| tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/Go/apphost.go | Updates Go sample to configure a custom manifest via AddManifest. |
| tests/Aspire.Hosting.Kubernetes.Tests/KubernetesPublisherTests.cs | Adds test coverage asserting a custom manifest template file is generated and contains expected YAML fragments. |
| src/Aspire.Hosting.Kubernetes/Yaml/KubernetesManifestResourceYamlConverter.cs | Introduces a YAML converter to serialize KubernetesManifestResource into the emitted Helm templates. |
| src/Aspire.Hosting.Kubernetes/KubernetesResource.cs | Adds AddManifest(...) API and excludes AdditionalResources from ATS export. |
| src/Aspire.Hosting.Kubernetes/KubernetesPublishingContext.cs | Registers the new YAML converter with the Kubernetes publishing serializer. |
| src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs | Implements the exported manifest handle API (WithNamespace/WithLabel/WithAnnotation/WithField) and value normalization. |
Normalize whole-number manifest fields before YAML serialization so polyglot number inputs do not emit schema-invalid floats for integer Kubernetes fields. Clarify the unsupported YAML deserialization message and add regression coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
IEvangelist
left a comment
There was a problem hiding this comment.
Reviewed the full diff. The changes look good — small, well-scoped addition of an internal ATS-exported AddManifest handle on KubernetesResource with a dedicated YAML converter and polyglot sample coverage.
The earlier reviewer concerns (whole-number double emitting as 3.0 due to FloatEmitter, missing double regression test, misleading ReadYaml exception message, and unnecessary public visibility) were all addressed by the author with appropriate fixes — numeric normalization to long via NormalizeFloatingPointValue/ConvertWholeNumberToLong, a regression test that parses the emitted YAML to assert the scalar is 3, a clearer deserialization message, and internal visibility on the resource/method.
No additional concrete bug, security, correctness, or convention issues to flag.
mitchdenny
left a comment
There was a problem hiding this comment.
Approving — well-scoped change, prior review feedback addressed. Three findings worth tracking:
Throw when manifest field paths would overwrite scalar intermediate values and document the scalar-only polyglot field limitation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🎬 CLI E2E Test Recordings — 78 recordings uploaded (commit View all recordings
📹 Recordings uploaded automatically from CI run #25750311678 |
Documents the new AddManifest API added in microsoft/aspire#16883, including polyglot examples (TypeScript, Python, Java, Go) and a configuration reference table. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pull request created: #927
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#927 targeting Added a new Add custom Kubernetes manifests section to Note This draft PR needs human review before merging. |
Description
The Kubernetes ATS SDK dump warned because
KubernetesResource.AdditionalResourcesexposedList<BaseKubernetesResource>, a C#-oriented customization model that is not an ATS-compatible polyglot contract. This change keepsAdditionalResourcesavailable as the C# escape hatch, but excludes it from ATS and adds a polyglot-friendly server-side manifest helper instead.KubernetesResource.AddManifest(...)now creates aKubernetesManifestResourceserver-side and returns an opaque handle that can be configured withWithNamespace,WithLabel,WithAnnotation, and scalarWithField(path, value)calls. This avoids serializing locally instantiated DTO/object graphs across ATS, where opaque resource references would not preserve handle semantics.We could also add well-known helper methods for specific Kubernetes resources that we decide are mandatory first-class scenarios, such as selected ConfigMap, Secret, or KEDA-oriented helpers. This PR does not add those yet because exporting every Kubernetes resource or sub-resource would effectively expose the Kubernetes serialization object model as public polyglot API. The generic manifest handle fixes the warning and unblocks custom-resource scenarios while preserving space to add curated, scenario-specific helpers later.
Updated the Kubernetes polyglot apphost samples for TypeScript, Python, Java, and Go, and added publisher coverage for emitting a custom KEDA-style manifest.
Fixes # (issue): N/A
Checklist
<remarks />and<code />elements on your triple slash comments?