Skip to content

fix: resolve every downward API env fieldRef the kubelet supports - #594

Merged
dciangot merged 1 commit into
interlink-hq:mainfrom
NopeCharon:fix/env-fieldref-resolution
Oct 28, 2026
Merged

dciangot merged 1 commit into
interlink-hq:mainfrom
NopeCharon:fix/env-fieldref-resolution

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Summary

When SkipDownwardAPIResolution is on, the virtual-kubelet library leaves downward API env vars to interLink's resolveEnvRefs. That function only handled five field paths. Every other fieldRef was silently set to an empty string, so offloaded containers got NODE_NAME='' from spec.nodeName, and the same happened for spec.serviceAccountName, metadata.labels['<KEY>'], status.hostIP, status.podIPs and status.hostIPs. There was no log line for any of it.

The downwardAPI volume code already has a resolver (resolveDownwardAPIFieldPath) that covers most of these. This PR makes env vars use it too, so both go through one resolver, and extends it with:

  • metadata.labels['<KEY>'] / metadata.annotations['<KEY>']. These are valid in downwardAPI volume items too, where they used to be dropped with an "unsupported FieldPath" warning. A missing key resolves to an empty value, as with the kubelet. Before, a missing annotation left the env var with its valueFrom.
  • status.podIPs / status.hostIPs. The VK reports one pod/host IP (PodPhase), so these hold that IP.

A field path that still can't be resolved is logged and left unresolved instead of being emptied silently. The Slurm plugin reads only env.Value, so the job sees the same thing as before; the operator now gets a warning. Kubernetes validation already rejects such paths, so this should not happen in practice.

Tests:

  • new TestResolveEnvRefsFieldRef covers every env field path, plus a missing annotation and an unsupported path;
  • TestRemoteExecutionHandleProjectedSourceDownwardAPIFieldRef now also checks metadata.labels['tier'] and metadata.annotations['my.annotation/key'] volume items.

Without the change, both tests fail on the paths above. go test -race ./pkg/... and golangci-lint run (v2.14.0, as in CI) pass.


Related issue : #593

With SkipDownwardAPIResolution set, the virtual-kubelet library leaves
downward API env vars to the provider, and resolveEnvRefs handled only
metadata.name, metadata.namespace, metadata.uid, status.podIP and
metadata.annotations['<KEY>']. Any other fieldRef fell into the default
branch and was silently set to an empty string: spec.nodeName (the usual
NODE_NAME), spec.serviceAccountName, metadata.labels['<KEY>'],
status.hostIP, status.podIPs and status.hostIPs. A missing annotation
also kept its valueFrom instead of resolving to an empty value.

resolveDownwardAPIFieldPath, used for downwardAPI volumes, already knew
most of these but not the subscripted labels/annotations, which are
valid volume items too.

Make resolveEnvRefs use resolveDownwardAPIFieldPath and extend it:

- metadata.labels['<KEY>'] and metadata.annotations['<KEY>'], with an
  empty value for a missing key, as the kubelet does;
- status.podIPs and status.hostIPs, which hold the single IP the
  virtual kubelet reports (see PodPhase).

A field path that still cannot be resolved is logged and left alone
instead of being emptied without a trace.

Fixes interlink-hq#593

Signed-off-by: NopeCharon <[email protected]>
@netlify

netlify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for interlink-dev canceled.

Name Link
🔨 Latest commit 79a7bf1
🔍 Latest deploy log https://app.netlify.com/projects/interlink-dev/deploys/6adde071f5ab53ff626224da

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

There are no active review issues for the shared downward API field-resolution change.

No open issues 🎉

What changed in this PR

This PR addresses #593 by sharing downward API field resolution between environment variables and volumes, preventing supported env field references from silently becoming empty.

Changes:

  • Routes env fieldRef values through the shared resolver and adds metadata subscripts and single-IP list aliases.
  • Logs unsupported env field paths and leaves them unresolved.
  • Adds tests for env field references and metadata subscripts in projected volumes.
File Description
pkg/​virtualkubelet/​execute.go Extends the shared resolver and uses it for env field references.
pkg/​virtualkubelet/​execute_test.go Adds env resolution coverage and projected-volume metadata assertions.

Review effort: Balanced

@dciangot
dciangot self-requested a review October 28, 2026 10:17

@dciangot dciangot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dciangot
dciangot merged commit 5890e7e into interlink-hq:main Oct 28, 2026
11 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.

3 participants