Skip to content

Add Downward API volume fieldRef support for pod metadata files#530

Merged
dciangot merged 11 commits into
mainfrom
copilot/add-downward-api-volume-support
Jun 3, 2026
Merged

Add Downward API volume fieldRef support for pod metadata files#530
dciangot merged 11 commits into
mainfrom
copilot/add-downward-api-volume-support

Conversation

Copilot AI commented May 9, 2026

Copy link
Copy Markdown
Contributor

InterLink already resolved Downward API fieldRef for env vars, but volume-based Downward API metadata files were incomplete. This PR extends volume handling so pods can mount metadata files from both projected and direct downwardAPI volumes with Kubernetes-standard field paths.

  • Downward API field path coverage

    • Added field resolution for volume items:
      • metadata.name, metadata.namespace, metadata.uid
      • metadata.labels, metadata.annotations
      • spec.nodeName, spec.serviceAccountName
      • status.podIP, status.hostIP
    • Kept unsupported selectors as non-fatal (logged and skipped), matching existing behavior.
  • Direct downwardAPI volume support

    • Added handling for volumes[].downwardAPI in remoteExecutionHandleVolumes (previously only projected sources were handled for this path).
    • Populates ProjectedVolumeMaps for downstream execution in the same way as other projected sources.
  • Deterministic metadata file rendering

    • Implemented stable serialization for metadata.labels / metadata.annotations as newline-delimited key="value" entries with sorted keys for deterministic output.
  • Targeted unit coverage

    • Added tests validating:
      • all newly supported fieldRef mappings for projected Downward API sources
      • end-to-end handling of direct downwardAPI volumes
volumes:
  - name: podinfo
    downwardAPI:
      items:
        - path: pod-name
          fieldRef: { fieldPath: metadata.name }
        - path: labels
          fieldRef: { fieldPath: metadata.labels }
        - path: annotations
          fieldRef: { fieldPath: metadata.annotations }

@netlify

netlify Bot commented May 9, 2026

Copy link
Copy Markdown

Deploy Preview for interlink-dev canceled.

Name Link
🔨 Latest commit 4457bcc
🔍 Latest deploy log https://app.netlify.com/projects/interlink-dev/deploys/6a2005f928cc4c0008db5a7a

Copilot AI changed the title [WIP] Add support for Downward API volumes Add Downward API volume fieldRef support for pod metadata files May 9, 2026
Copilot AI requested a review from dciangot May 9, 2026 10:00
@dciangot

dciangot commented May 9, 2026

Copy link
Copy Markdown
Member

@copilot lint action is failing

Copilot AI commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot lint action is failing

Fixed. The lint failure was due to staticcheck QF1012 in formatDownwardAPIMetadataMap; I updated the string building to satisfy lint without changing behavior. Addressed in commit d379093.

@dciangot dciangot marked this pull request as ready for review May 9, 2026 17:05
Copilot AI review requested due to automatic review settings May 9, 2026 17:05

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.

Pull request overview

This PR extends InterLink’s Downward API handling for volume-mounted metadata files by resolving additional fieldRef paths and adding support for direct volumes[].downwardAPI (not only projected sources). It also makes label/annotation rendering deterministic to avoid non-reproducible output from map iteration.

Changes:

  • Refactors Downward API volume item processing into shared helpers and adds support for more fieldRef paths (incl. labels/annotations, node/service account, pod/host IPs).
  • Adds handling for direct DownwardAPI volumes in remoteExecutionHandleVolumes by populating ProjectedVolumeMaps.
  • Adds unit tests covering the new field paths and the direct downwardAPI volume path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/virtualkubelet/execute.go Adds shared Downward API resolution helpers and new handling for direct DownwardAPI volumes.
pkg/virtualkubelet/execute_test.go Adds tests for the expanded fieldRef mapping and direct downwardAPI volumes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/virtualkubelet/execute.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Diego Ciangottini <diego.ciangottini@gmail.com>

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +961 to +967
case volume.DownwardAPI != nil:
projectedVolume := v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: volume.Name},
Data: make(map[string]string),
}
log.G(ctx).Debug("Adding to PodCreateRequests the downwardAPI volume ", volume.Name)

Comment on lines +512 to +516
require.Len(t, req.ProjectedVolumeMaps, 1)
assert.Equal(t, "podinfo", req.ProjectedVolumeMaps[0].Name)
assert.Equal(t, "test-pod", req.ProjectedVolumeMaps[0].Data["pod-name"])
assert.Equal(t, "app=\"demo\"\n", req.ProjectedVolumeMaps[0].Data["labels"])
assert.Equal(t, "a=\"b\"\n", req.ProjectedVolumeMaps[0].Data["annotations"])
@dciangot dciangot merged commit 6fb734f into main Jun 3, 2026
19 of 20 checks passed
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.

Add support for Downward API volumes (fieldRef in volume mounts)

3 participants