Skip to content

feat(e2b): support naming cloned sandbox via metadata extensions#385

Open
AiRanthem wants to merge 2 commits into
openkruise:masterfrom
AiRanthem:feature/assign-name-while-clone-260512
Open

feat(e2b): support naming cloned sandbox via metadata extensions#385
AiRanthem wants to merge 2 commits into
openkruise:masterfrom
AiRanthem:feature/assign-name-while-clone-260512

Conversation

@AiRanthem
Copy link
Copy Markdown
Member

Summary

  • Adds two new metadata keys for POST /sandboxes on the clone path:
    • e2b.agents.kruise.io/sandbox-name — sets ObjectMeta.Name (mutually exclusive with the next).
    • e2b.agents.kruise.io/sandbox-generate-name — sets ObjectMeta.GenerateName prefix.
  • Default behavior is unchanged when neither key is provided (GenerateName: <checkpointID>-).
  • Validates inputs as DNS-1123 label (apivalidation.NameIsDNSLabel); the canonical K8s validator with prefix=true masks the trailing - for GenerateName prefixes. Both keys are stripped from Metadata so they don't leak onto sandbox annotations.
  • AlreadyExists collision (only reachable when sandbox-name is set) maps to 409 Conflict via the manager's typed ErrorConflict.
  • Naming is a first-class field on infra.CloneSandboxOptions; newSandboxFromTemplate uses an explicit switch so the Name/GenerateName precedence is visible at the call site rather than relying on K8s semantics.

Public-contract note (beyond the design spec)

The claim path actively rejects these keys with 400 Bad Request (sandbox-name and sandbox-generate-name are only supported for clone). Caller-controlled naming on the claim path is owned by SandboxSet and is out of scope; failing fast is preferable to silently dropping the request.

Design

docs/superpowers/specs/2026-05-12-clone-sandbox-name-design.md (in the design branch; not included in this PR).

Test plan

  • go build ./...
  • go vet ./pkg/servers/e2b/... ./pkg/sandbox-manager/...
  • go test ./pkg/servers/e2b/... ./pkg/sandbox-manager/...
  • parseExtensionSandboxNaming table covers mutual exclusion, empty values, dot rejection, trailing-dash prefix, and key-stripping.
  • ValidateAndInitCloneOptions rejects both Name and GenerateName set together.
  • newSandboxFromTemplate honors Name, GenerateName, and falls back to <checkpointID>-.
  • TestCreateSandboxWithClone_Naming end-to-end: Extensions.Name / Extensions.GenerateName flow through to the resulting Sandbox ObjectMeta.
  • TestSandboxManager_CloneSandbox "explicit name collision returns conflict" maps to ErrorConflict.
  • TestMapCloneSandboxError confirms only manager-wrapped conflict maps to 409 (raw apierrors.AlreadyExists is not specially mapped — manager is expected to wrap).
  • TestCreateSandboxWithClaim_NamingExtensionRejected confirms claim path returns 400.

…le cloning sandboxes

Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com>
@kruise-bot kruise-bot requested review from furykerry and zmberg May 14, 2026 09:27
@kruise-bot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zmberg for approval by writing /assign @zmberg in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 92.72727% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.01%. Comparing base (5d3212b) to head (a0f1110).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pkg/servers/e2b/models/extensions.go 86.20% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #385      +/-   ##
==========================================
+ Coverage   75.90%   76.01%   +0.10%     
==========================================
  Files         145      145              
  Lines       10626    10673      +47     
==========================================
+ Hits         8066     8113      +47     
  Misses       2212     2212              
  Partials      348      348              
Flag Coverage Δ
unittests 76.01% <92.72%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kruise-bot
Copy link
Copy Markdown

@AiRanthem: PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants