Skip to content

Add ATS support for Kubernetes PVC configuration callbacks - #21124

Merged
Mitch Denny (mitchdenny) merged 4 commits into
mainfrom
mitchdenny-kubernetes-pvc-customization
Oct 28, 2026
Merged

Mitch Denny (mitchdenny) merged 4 commits into
mainfrom
mitchdenny-kubernetes-pvc-customization

Conversation

@mitchdenny

Copy link
Copy Markdown
Member

Description

TypeScript AppHosts currently cannot customize generated Kubernetes persistent volume claims beyond the dedicated fluent methods. This exports the existing WithConfiguration callback through ATS so TypeScript can customize labels, annotations, storage class, volume name/mode, access modes, and resource requests.

The exported model is deliberately bounded to the scenarios exercised by the existing PVC tests, rather than exposing the entire Kubernetes manifest hierarchy. Callbacks use the existing remote-object infrastructure and run in registration order after fluent settings and environment defaults have been applied. C# behavior is unchanged.

Selectors, data sources, volume attributes classes, resource limits, and claim identity customization remain C#-only. Raw-block workload bindings are not introduced.

Fixes #20530

User-facing usage

C# AppHost (existing API):

var data = k8s.AddPersistentVolume("data")
    .WithConfiguration(claim =>
    {
        claim.Metadata.Labels["example.com/retention"] = "retain";
        claim.Spec.VolumeMode = "Filesystem";
        claim.Spec.StorageClassName = "";
    });

TypeScript AppHost:

const data = await k8s.addPersistentVolume("data");
await data.withConfiguration(async (claim) => {
    const metadata = await claim.metadata.get();
    await metadata.labels.set("example.com/retention", "retain");

    const spec = await claim.spec.get();
    await spec.volumeMode.set("Filesystem");
    await spec.storageClassName.set("");
});

An empty storage class requests a classless volume; null omits the field so Kubernetes can assign its default StorageClass. Existing parameterized fluent methods continue to produce Helm expressions.

Coverage and validation

Adds bounded capability/code-generation assertions, a TypeScript declaration snapshot, polyglot fixture usage, and a live TypeScript publish scenario. Generated-manifest snapshots cover ordered callback mutations, empty versus omitted storage classes, preserved Helm expressions, and unchanged StatefulSet volume bindings. The live scenario also verifies that callback exceptions fail publishing and surface the error.

Commands run successfully:

# Passed: 151 tests.
dotnet test --project tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests.csproj --no-launch-profile -- --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

# Passed: 16 publisher regression tests.
dotnet test --project tests/Aspire.Hosting.Kubernetes.Tests/Aspire.Hosting.Kubernetes.Tests.csproj --no-launch-profile -- --filter-method '*.PublishAsync_WithFirstClassPersistentVolume*' --filter-method '*.PublishAsync_PersistentVolume*' --filter-method '*.PublishAsync_WithPvcStorageType_GeneratesValidPersistentVolumeClaim' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

# Passed: 6 extension tests.
dotnet test --project tests/Aspire.Hosting.Kubernetes.Tests/Aspire.Hosting.Kubernetes.Tests.csproj --no-launch-profile -- --filter-class '*.KubernetesPersistentVolumeExtensionsTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

# Passed: 1 live Docker scenario; ASPIRE_E2E_ARCHIVE pointed at a locally built Linux arm64 archive.
dotnet test --project tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj --no-launch-profile -- --filter-method '*.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

# Passed: Kubernetes TypeScript validation AppHost against the newly generated SDK, inside Docker.
npx --yes @typescript/native-preview --noEmit --project tsconfig.json

The E2E archive used self-contained managed Dashboard/TerminalHost payloads because the macOS host could not cross-compile Linux Native AOT. Native AOT payload behavior was not validated. No new package version or production dependency is required; the E2E test project adds the existing centrally managed Verify dependency for manifest snapshots.

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

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a26931a2-c0da-4434-adff-bf912b86dbe6
@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 -- 21124

Or

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

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 19, 2026 06:11
@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Oct 19, 2026
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

Exported getters promise strings but return null for unset claim fields, allowing type-checked callbacks to fail during publishing.

1 open issue
What changed in this PR

Enables TypeScript AppHosts to customize Kubernetes persistent volume claims through the existing configuration callback.

Changes:

  • Exports a bounded claim model through ATS.
  • Documents supported customization and limitations.
  • Adds generated declarations, publish tests, and manifest snapshots.
File Description
tests/​PolyglotAppHosts/​Aspire.Hosting.Kubernetes/​TypeScript/​apphost.mts Exercises callback customization.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​Snapshots/​AtsTypeScriptCodeGeneratorTests.Generate_KubernetesPersistentVolume_WithConfigurationExposesBoundedClaimModel.verified.ts Records exported declarations.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​AtsTypeScriptCodeGeneratorTests.cs Checks bounded capabilities and declarations.
tests/​Aspire.Cli.EndToEnd.Tests/​TypeScriptPublishTests.cs Tests publishing and callback failures.
tests/​Aspire.Cli.EndToEnd.Tests/​Snapshots/​TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#04.verified.yaml Verifies StatefulSet volume bindings.
tests/​Aspire.Cli.EndToEnd.Tests/​Snapshots/​TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#03.verified.yaml Records Helm values.
tests/​Aspire.Cli.EndToEnd.Tests/​Snapshots/​TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#02.verified.yaml Verifies preserved Helm expressions.
tests/​Aspire.Cli.EndToEnd.Tests/​Snapshots/​TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#01.verified.yaml Verifies omitted storage class.
tests/​Aspire.Cli.EndToEnd.Tests/​Snapshots/​TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#00.verified.yaml Verifies ordered callback mutations.
tests/​Aspire.Cli.EndToEnd.Tests/​Aspire.Cli.EndToEnd.Tests.csproj Enables snapshot testing.
src/​Aspire.Hosting.Kubernetes/​Resources/​VolumeResourceRequirementsV1.cs Exports resource requests.
src/​Aspire.Hosting.Kubernetes/​Resources/​PersistentVolumeClaimV1.cs Exports the claim and specification.
src/​Aspire.Hosting.Kubernetes/​Resources/​PersistentVolumeClaimSpecV1.cs Exports selected claim settings.
src/​Aspire.Hosting.Kubernetes/​Resources/​ObjectMetaV1.cs Exports labels and annotations.
src/​Aspire.Hosting.Kubernetes/​Resources/​BaseKubernetesResource.cs Exports metadata access.
src/​Aspire.Hosting.Kubernetes/​README.md Documents examples and limitations.
src/​Aspire.Hosting.Kubernetes/​KubernetesPersistentVolumeExtensions.cs Exports the configuration callback.

Review effort: Balanced

@mitchdenny
Mitch Denny (mitchdenny) marked this pull request as ready for review October 21, 2026 05:54
…-pvc-customization

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a26931a2-c0da-4434-adff-bf912b86dbe6

# Conflicts:
#	src/Aspire.Hosting.Kubernetes/README.md
#	tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

The unresolved nullability mismatch lets volumeMode and volumeName getters return null despite non-nullable TypeScript signatures.

1 open issue

Review effort: Balanced

@IEvangelist

Copy link
Copy Markdown
Member

PR Testing Report

PR Information

Artifact Version Verification

  • Expected Commit: 6e1c2d2
  • Installed Version: 17.0.0-pr.21124.g6e1c2d24 (dogfood CLI + PR hive)
  • Status: ✅ Verified

Changes Analyzed

  • Hosting: KubernetesPersistentVolumeExtensions.WithConfiguration switched from AspireExportIgnore to AspireExport; [AspireExport] added to BaseKubernetesResource.Metadata, ObjectMetaV1 (+ Labels, Annotations), PersistentVolumeClaim(.Spec), PersistentVolumeClaimSpecV1 (storageClassName, volumeMode, volumeName, accessModes, resources), VolumeResourceRequirementsV1.Requests.
  • Tests: TypeScript codegen snapshot, TypeScript E2E publish test + 5 YAML snapshots, polyglot apphost.mts.
  • Docs: Kubernetes README.

Test Scenarios Executed

Fresh aspire init --language typescript + aspire add Aspire.Hosting.Kubernetes + aspire restore against the PR hive. The generated .aspire/modules/aspire.mts exposes withConfiguration(configure: (obj: PersistentVolumeClaim) => Promise<void>).

1. Claim customization via callbacks - ✅ Passed (happy path)

aspire publish with the PR's E2E AppHost: labels, annotations, storageClassName="", volumeName, volumeMode, accessModes (clear/add), 20Gi request. In-callback asserts passed (callback sees fluent withStorageClass/withPersistentVolumeName values; second callback sees first callback's changes - registration order). Published data.yaml is correct.

2. storageClassName.set(null) omits the field - ✅ Passed

omitted.yaml has no storageClassName.

3. Parameterized PVC + callback - ✅ Passed

Helm expressions for storage class, capacity and annotation preserved; callback labels/volumeMode applied.

All 5 generated files (data.yaml, omitted.yaml, parameterized.yaml, values.yaml, data-service/statefulset.yaml) are byte-identical to the PR's committed .verified.yaml snapshots.

4. Unhappy: callback throws - ✅ Passed

aspire publish exits 6, output contains PVC callback failure (Capability Error ... Callback execution failed), no manifest is written.

5. Unhappy: invalid / unsupported usage - ✅ Passed

  • Accessing a C#-only member (spec.selector) -> tsc error TS2339 (not exported, as documented).
  • Runtime volumeMode.set(null) (non-nullable in TS types, forced via as any) -> publish succeeds, field omitted from YAML (safe, no crash).

Summary

Scenario Status
1 Claim customization ✅
2 null storage class omits field ✅
3 Parameterized + callback ✅
4 Callback throws ✅
5 Unsupported/invalid usage ✅

Notes

  • Not run locally: the PR's Docker-based TypeScriptPublishTests (Docker daemon unavailable); its scenario was reproduced manually and matched its snapshots. PR CI at head was green.
  • values.yaml parameter values are empty in publish output (pre-existing; matches snapshot).

Overall Result

✅ PR VERIFIED

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a26931a2-c0da-4434-adff-bf912b86dbe6

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.

🟢 Approval recommended

The bounded exports preserve the existing callback behavior, focused coverage addresses the relevant regressions, and no blocking issues remain.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

…-pvc-customization

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a26931a2-c0da-4434-adff-bf912b86dbe6

# Conflicts:
#	tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

7 / 100 PR test projects · 2 PR jobs, from 16 changed files.

Selected PR test projects (7 / 100)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.RemoteHost.Tests

Selected PR jobs (2)

polyglot, typescript-api-compat


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.Kubernetes/KubernetesPersistentVolumeExtensions.cs (changed source)
→ 1 directly: Aspire.Hosting.Kubernetes.Tests
→ 4 via the project graph: Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.CodeGeneration.Python.Tests (2 hops), Aspire.Hosting.Docker.Tests, Aspire.Hosting.RemoteHost.Tests (2 hops)

📦 affected project Aspire.Hosting.Kubernetes
→ 1 test: Aspire.Cli.EndToEnd.Tests

🔧 src/Aspire.Hosting.Kubernetes/Resources/BaseKubernetesResource.cs (changed source)
→ 1 directly: Aspire.Hosting.Kubernetes.Tests

🔧 src/Aspire.Hosting.Kubernetes/Resources/ObjectMetaV1.cs (changed source)
→ 1 directly: Aspire.Hosting.Kubernetes.Tests

🔧 src/Aspire.Hosting.Kubernetes/Resources/PersistentVolumeClaimSpecV1.cs (changed source)
→ 1 directly: Aspire.Hosting.Kubernetes.Tests

🔧 src/Aspire.Hosting.Kubernetes/Resources/PersistentVolumeClaimV1.cs (changed source)
→ 1 directly: Aspire.Hosting.Kubernetes.Tests

🔧 src/Aspire.Hosting.Kubernetes/Resources/VolumeResourceRequirementsV1.cs (changed source)
→ 1 directly: Aspire.Hosting.Kubernetes.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#00.verified.yaml (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#01.verified.yaml (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#02.verified.yaml (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#03.verified.yaml (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/TypeScriptPublishTests.PublishWithKubernetesPersistentVolumeConfigurationCustomizesClaims#04.verified.yaml (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPublishTests.cs (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/AtsTypeScriptCodeGeneratorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/AtsTypeScriptCodeGeneratorTests.Generate_KubernetesPersistentVolume_WithConfigurationExposesBoundedClaimModel.verified.ts (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

Job reasons

Job Triggered by
polyglot • tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/TypeScript/apphost.mts
• affected project Aspire.Hosting.Kubernetes
• affected project Aspire.Hosting.Azure.Provisioning.ContainerService
typescript-api-compat affected project Aspire.Hosting.Kubernetes

Selection computed for commit 42ca72a.

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.

🟢 Approval recommended

The changes reuse existing callback infrastructure, cover the affected export and publish behavior, and resolve the previously identified nullability issue.

No open issues 🎉

Review effort: Balanced

@mitchdenny
Mitch Denny (mitchdenny) merged commit 8cc1c3e into main Oct 28, 2026
168 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 28, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1963

Generated by PR Documentation Check · copilot · auto · 26.5 AIC · ⌖ 1.14 AIC · ⊞ 7.1K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#1963 targeting release/17.0.

Documented the new withConfiguration PVC callback for TypeScript AppHosts in deployment/kubernetes/persistent-volumes.mdx. Triggered signals: integration_readme_changed (Kubernetes README), pr_body_has_user_facing_section (User-facing usage), pr_body_has_cli_flag_mention (test commands).

Note

This draft PR needs human review before merging.

Mitch Denny (mitchdenny) added a commit to microsoft/aspire.dev that referenced this pull request Nov 17, 2026
…tion) (#1963)

Documents changes from microsoft/aspire#21124

Author: ``@mitchdenny``

Targeting `release/17.0` based on the source PR milestone `17.0` (exact
match).

## Why
The source PR exports the Kubernetes persistent volume
`WithConfiguration` callback through ATS, so TypeScript AppHosts can
customize generated PVCs. The docs didn't cover this.

## Changes
Updated (no new pages):
`src/frontend/src/content/docs/deployment/kubernetes/persistent-volumes.mdx`
- Added `WithConfiguration` / `withConfiguration` to the configuration
methods table.
- Added a "Customize the generated claim" section with C# and TypeScript
examples, storage class empty vs. null semantics, callback ordering,
bounded TypeScript model, and C#-only features.

Triggered signals: `integration_readme_changed`,
`pr_body_has_user_facing_section`, `pr_body_has_cli_flag_mention`.

> Generated by [PR Documentation
Check](https://github.com/microsoft/aspire/actions/runs/40609189241) for
#21124 · copilot · auto · 26.5 AIC · ⌖ 1.14 AIC · ⊞ 7.1K ·
[◷](https://github.com/search?q=repo%3Amicrosoft%2Faspire.dev+%22gh-aw-workflow-id%3A+pr-docs-check%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: PR Documentation Check, engine: copilot,
model: auto, id: 40609189241, workflow_id: pr-docs-check, run:
https://github.com/microsoft/aspire/actions/runs/40609189241 -->

<!-- gh-aw-workflow-id: pr-docs-check -->
<!-- gh-aw-workflow-call-id: microsoft/aspire/pr-docs-check -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review Kubernetes PVC customization APIs for TypeScript usage in 17.0

3 participants