Skip to content

fix(driver-k8s): add label selector to sandbox watch stream and list#2223

Open
rhuss wants to merge 1 commit into
NVIDIA:mainfrom
rhuss:fix/k8s-watch-crash-2211
Open

fix(driver-k8s): add label selector to sandbox watch stream and list#2223
rhuss wants to merge 1 commit into
NVIDIA:mainfrom
rhuss:fix/k8s-watch-crash-2211

Conversation

@rhuss

@rhuss rhuss commented Jul 11, 2026

Copy link
Copy Markdown

Summary

The K8s driver's watch_sandboxes() crashes with a file descriptor leak when non-gateway Sandbox resources (e.g. from SandboxWarmPool) exist in the namespace. This adds a label selector to filter at the API server level, and defensively skips unrecognized objects instead of propagating errors to the channel.

Related Issue

Fixes #2211

Changes

  • Add openshell.ai/managed-by=openshell label selector to the watcher::Config in watch_sandboxes() so only gateway-managed Sandbox objects generate watch events
  • Add the same label selector to ListParams in list_sandboxes() so only gateway-managed objects are returned
  • Replace error propagation in all three watch event branches (Applied, Deleted, Restarted) with let ... else guards that debug! log the object name and continue, preventing crash loops from unrecognized objects
  • Add 6 unit tests for sandbox_id_from_object and sandbox_from_object covering label extraction, name-prefix fallback, unknown object rejection, and the managed-by-without-sandbox-id edge case

Testing

  • cargo clippy -p openshell-driver-kubernetes --all-targets -- -D warnings: Clean
  • cargo test -p openshell-driver-kubernetes: 129 passed (123 existing + 6 new)
  • Unit tests added/updated
  • E2E tests added/updated (not applicable, label selector behavior requires a real K8s cluster with SandboxWarmPool CRDs)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (not applicable, no architectural change)

…VIDIA#2211)

The Kubernetes driver's watch_sandboxes() crashed with a file descriptor
leak when non-gateway Sandbox resources (e.g. from SandboxWarmPool)
existed in the namespace. The unfiltered watch received events for all
Sandbox objects, failed to extract IDs from warm pool objects, and
propagated errors that triggered a 2-second reconnect loop leaking
HTTP/2 connections until FD exhaustion.

Two fixes:
- Add openshell.ai/managed-by=openshell label selector to the watcher
  config and list params so only gateway-managed objects are received.
- Defensively skip unrecognized objects with a debug log instead of
  sending errors to the channel, using let-else for flat control flow.

Signed-off-by: Roland Huß <roland@jolokia.org>
Signed-off-by: Roland Huß <rhuss@redhat.com>
@rhuss rhuss requested review from a team, derekwaynecarr, maxamillion and mrunalp as code owners July 11, 2026 06:33
@copy-pr-bot

copy-pr-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

fix: K8s driver watch stream crashes with FD leak when non-gateway Sandbox resources exist

1 participant