Skip to content

feat(fsb): resolve SandboxPool through the shared informer at create - #3120

Merged
Pangjiping merged 2 commits into
opensandbox-group:mainfrom
Pangjiping:feat/osep-0034-pool-cr-reader
Nov 26, 2026
Merged

Pangjiping merged 2 commits into
opensandbox-group:mainfrom
Pangjiping:feat/osep-0034-pool-cr-reader

Conversation

@Pangjiping

Copy link
Copy Markdown
Collaborator

Summary

  • Prerequisite for the "Unified SandboxPool watch" section of OSEP-0034 (docs(osep): propose OSEP-0034 near-end runtime init for Fast Sandbox #3115): opensandbox-server resolves the target SandboxPool through the shared K8sClient LIST/WATCH informer (PoolCRReader / PoolSnapshot) instead of a per-create FastPath.GetPool RPC plus the 15-minute _pool_mode_cache.
    • RBAC: the server ClusterRole gains read-only get/list/watch on sandboxpools.sandbox.fast.io.
    • Resource-aware gate: PoolSnapshot.from_cr mirrors fast-sandbox's SandboxResourceProfile.ResourceMode(): ResourceAware requires mode, cpu, memory and overcommitRatio; every other shape keeps the legacy gate. The OSEP-0026 pool-profile checks are unchanged, and int-or-string quantities compare canonically with the request limits.
    • Single-pass mapping: the pool is resolved up front (resolve_pool_ref), so each create maps once and steady-state template, image and snapshot creates make no GetPool call.
    • Rolling-upgrade fallback: a 403 on sandboxpools (server image newer than its ClusterRole) falls back to GetPool with no action handlers and one warning per outage; the watch takes over once RBAC converges.
  • PoolSnapshot.action_handlers is parsed but not consumed yet; it drives the runtime-init binding in docs(osep): propose OSEP-0034 near-end runtime init for Fast Sandbox #3115.
  • Behavior change: a create that both targets a missing pool and carries an unsupported field now returns 404 FSB_POOL_NOT_FOUND instead of 400, because the pool is resolved before the single mapping pass.

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

server: uv run ruff check is clean and uv run pytest --cov=opensandbox_server --cov-fail-under=80 passes (3225 passed, 34 skipped, 87% total coverage). The new tests/test_fsb_cr_reader.py covers the mode-gate parity matrix, 404/403/503 mapping, cache-backed reads, watch-driven handler and mode changes, and the stale-cache fallback to the live API. test_fsb_service.py and test_templates.py cover zero GetPool calls on steady-state creates, canonical quantity comparison, 404 on a missing pool, the 403 fallback, and a same-name pool recreate flipping the mode.

manifests: helm lint manifests/charts/server and helm template render the new rule; scripts/verify-license.sh passes.

Not run: the scripts/fast-sandbox-env integration stack and the KVM e2e workflow.

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation (docs(osep): propose OSEP-0034 near-end runtime init for Fast Sandbox #3115)
  • Added/updated docs (if needed): no docs described the GetPool/TTL mechanism
  • Added/updated tests (if needed)
  • Security impact considered: read-only, least-privilege access on sandboxpools; no new data-plane surface
  • Backward compatibility considered: a server running ahead of its ClusterRole keeps serving creates through the GetPool fallback, and the mode gate fails safe

The fsb create path learned a pool's resource mode and default profile
from FastPath GetPool: one RPC per image/snapshot create, and a
15-minute TTL cache for template creates. Pool mode and action handlers
now come from one read of the SandboxPool CR through the shared
K8sClient informer, the pool-watch prerequisite of OSEP-0034 (opensandbox-group#3115).

- PoolSnapshot/PoolCRReader project the CR as fast-sandbox's
  ResourceMode() sees it: ResourceAware needs mode, cpu, memory and
  overcommitRatio, and every other shape keeps the legacy gate.
  Quantities may be numbers or strings and still compare canonically
  with the request limits.
- The target pool is resolved before mapping (resolve_pool_ref), so each
  request maps once instead of twice and steady-state creates make no
  GetPool call.
- A 403 on sandboxpools means the server image is newer than its
  ClusterRole: creates fall back to GetPool without action handlers,
  and the informer takes over once RBAC converges. The server
  ClusterRole gains get/list/watch on sandboxpools.

action_handlers is parsed but not consumed yet; it feeds the
runtime-init binding once opensandbox-group#3115 lands. A create that both targets a
missing pool and carries an unsupported field now returns 404 instead
of 400, because the pool is resolved before validation.

Signed-off-by: 高然 <pangjiping.pjp@alibaba-inc.com>
@github-actions github-actions Bot added component/server size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 26, 2026
@Pangjiping
Pangjiping marked this pull request as ready for review November 26, 2026 02:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T02:19:13.413793Z cc6b7de Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc6b7dea32

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

The pool is resolved before the request is mapped, so a cold or stale
SandboxPool cache makes the create wait on a live API-server GET before
the mapping read the clock for expires_at. The TTL then grew by that
wait (a 2.5s pool read extended a 3600s TTL by 2.2s) while createdAt
stayed at the pre-read timestamp. Pass the captured created_at to both
one-pass mappings so expiresAt is createdAt + timeout again.

Addresses the Codex review finding on opensandbox-group#3120.

Signed-off-by: 高然 <pangjiping.pjp@alibaba-inc.com>
@Pangjiping
Pangjiping merged commit 1b09bda into opensandbox-group:main Nov 26, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/server ok-to-test size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant