Repository navigation
Add Kubernetes fileKeyRef environment variable support - #20847
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 37157142-2151-4210-8f9b-fc4b0c4e5138
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20847Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20847" |
Tests selector5 / 98 PR test projects · 2 PR jobs, from 9 changed files. Selected PR test projects (5 / 98)
Selected PR jobs (2)
How these were chosen — grouped by what changed🔧 📦 affected project 🔧 🧪 🧪 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🟢 Approval recommended
The API matches Kubernetes 1.35’s schema and has focused serialization and real deployment coverage.
0 open findings
What changed in this PR
Adds Kubernetes 1.34+ fileKeyRef support to the Kubernetes deployment resource model.
Changes:
- Adds
FileKeySelectorV1andEnvVarSourceV1.FileKeyRef. - Verifies nullable
optionalserialization through snapshots. - Adds KinD deployment coverage for generated values, renamed keys, and optional missing keys.
| File | Description |
|---|---|
src/Aspire.Hosting.Kubernetes/Resources/FileKeySelectorV1.cs |
Defines the Kubernetes file-key selector model. |
src/Aspire.Hosting.Kubernetes/Resources/EnvVarSourceV1.cs |
Exposes fileKeyRef for environment values. |
tests/Aspire.Hosting.Kubernetes.Tests/KubernetesPublisherTests.cs |
Tests generated Kubernetes YAML. |
tests/Aspire.Hosting.Kubernetes.Tests/Snapshots/KubernetesPublisherTests.PublishAsync_SupportsFileKeyRef_optional=null.verified.yaml |
Verifies omitted optional. |
tests/Aspire.Hosting.Kubernetes.Tests/Snapshots/KubernetesPublisherTests.PublishAsync_SupportsFileKeyRef_optional=False.verified.yaml |
Verifies explicit false. |
tests/Aspire.Hosting.Kubernetes.Tests/Snapshots/KubernetesPublisherTests.PublishAsync_SupportsFileKeyRef_optional=True.verified.yaml |
Verifies explicit true. |
tests/Aspire.Cli.EndToEnd.Tests/KubernetesDeployWithFileKeyRefTests.cs |
Validates real Kubernetes deployment behavior. |
tests/Aspire.Cli.EndToEnd.Tests/Helpers/KubernetesDeployTestHelpers.cs |
Supports selecting a pinned KinD node image. |
tests/Aspire.Cli.EndToEnd.Tests/RadiusDeployTests.cs |
Disambiguates an XML documentation reference. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Code review and PR testing reportPR information
Code reviewNo high-confidence correctness or regression findings. Reviewed all nine changed files and the shared KinD setup/cleanup helpers. The new selector matches Kubernetes 1.35's upstream API/OpenAPI schema: required string fields Impact analysis covered YAML serialization, optional/default handling, existing manifests when This is a generic code review, not a formal public API review or security review. Artifact version verification
Local Linux ARM64 testing used the PR's downloaded native archive and NuGet artifacts, not the earlier locally built archive. CI independently ran the committed test on Linux x64. Changes analyzed
Test scenarios executed
Exact source-test commanddotnet test --project tests/Aspire.Hosting.Kubernetes.Tests/Aspire.Hosting.Kubernetes.Tests.csproj --no-launch-profile -- --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'Result: 370 passed, 0 failed. Exact local artifact-test commandGITHUB_PR_NUMBER=20847 \
GITHUB_PR_HEAD_SHA=cdb79718e0a783ff528ae7d86590b269cba0bb15 \
ASPIRE_E2E_CLI_ARCHIVE_DIR="$PWD/artifacts/pr20847-testing/archive-flat" \
ASPIRE_E2E_DOTNET_IMAGE=aspire-pr20847-testing:local \
ASPIRE_E2E_CLI_VERSION_OUTPUT_DIR=/tmp/pr20847-cli-version \
dotnet test --project tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj --no-launch-profile -- --filter-method '*.DeployK8sWithFileKeyRef' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'Result: 1 passed, 0 failed in approximately 1 minute 38 seconds, including the temporary required-missing-key probe. The probe was removed after testing; the worktree is clean and the PR head is unchanged. Representative observed output: Setup issues and limitationsThe first isolated dogfood install ran before artifacts were available. After upload, the local harness's Validation subsequently succeeded with the CI-equivalent This report verifies the relevant scenarios, not the overall result of every job in the CI workflow. AKS registry mirroring and local-run emulation are outside this PR's scope. Evidence and cleanup
Overall resultRelevant PR scenarios verified. No code-review findings. The publisher suite and actual deployment test pass, and the additional required-missing-key probe produces the expected blocked startup. |
|
Pull request created: #1868
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1868 targeting Documented the new Kubernetes Note This draft PR needs human review before merging. |
Description
Allow Kubernetes workloads to source individual environment variables from an env file written by an init container, without mounting the file into the application container or overriding its entrypoint.
Adds
FileKeySelectorV1andEnvVarSourceV1.FileKeyRef, matching Kubernetes 1.35's API schema. Snapshot tests cover omitted, false, and trueoptionalvalues. A CLI E2E test builds and deploys an application to KinD, checking generated values, key renaming, optional missing keys, and the actual pod configuration. The Kubernetes node and BusyBox init-container images are digest-pinned.Requires Kubernetes 1.34+ with
EnvFilesenabled (enabled by default from 1.35). Init-container images must already be available to the cluster; this does not add image-publication primitives, AKS-specific behavior, or local-run emulation.Fixes #19756
User-facing usage
C# workload customization can select a key from an
emptyDirenv file populated by an init container:This is a C# Kubernetes resource-model API; no TypeScript API is introduced.
Validation
./restore.sh— passed.dotnet test --project tests/Aspire.Hosting.Kubernetes.Tests/Aspire.Hosting.Kubernetes.Tests.csproj --no-launch-profile -- --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'— passed, 370 tests.dotnet test --project tests/Aspire.Hosting.Kubernetes.Tests/Aspire.Hosting.Kubernetes.Tests.csproj --no-launch-profile -- --filter-method '*.PublishAsync_SupportsFileKeyRef' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'— passed, 3 cases with digest-pinned snapshots.ASPIRE_E2E_DOTNET_IMAGE=aspire-filekeyref-built:local ASPIRE_E2E_ARCHIVE="$PWD/artifacts/filekeyref-linux-arm64.tar.gz" dotnet test --project tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj --no-launch-profile -- --filter-method '*.DeployK8sWithFileKeyRef' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'— passed against local KinD/Kubernetes 1.35 with digest-pinned BusyBox.Checklist
<remarks />and<code />elements on your triple slash comments?