Skip to content

fix(sandbox): resolve short sandbox ID prefixes consistently#697

Open
xiaojunxiang2023 wants to merge 2 commits into
TencentCloud:masterfrom
xiaojunxiang2023:fix/sandbox-id-prefix-resolve
Open

fix(sandbox): resolve short sandbox ID prefixes consistently#697
xiaojunxiang2023 wants to merge 2 commits into
TencentCloud:masterfrom
xiaojunxiang2023:fix/sandbox-id-prefix-resolve

Conversation

@xiaojunxiang2023

Copy link
Copy Markdown
Contributor

Summary

Sandbox IDs are 32-character lowercase hex strings (UUID without dashes). cubecli ls truncates them to 12 characters for display, but several APIs and CLIs previously required the full ID or used naive strings.HasPrefix matching without ambiguity checks.

This PR adds a shared sandbox ID resolver and wires it through CubeMaster, Cubelet, and CLI entry points so that:

  • Display can stay short (12-char truncation unchanged; --no-trunc still shows the full ID)
  • Input accepts either a full 32-char ID or a unique short prefix
  • Ambiguous prefixes return a clear error instead of silently matching the wrong sandbox
  • Missing IDs return a not-found error

Core resolver (sandboxid.Resolve)

Case Behavior
Exact match (case-insensitive hex) Return canonical full ID
Unique prefix among candidates Return the matching full ID
Multiple prefix matches ambiguous sandbox id prefix
No match, input is 32-char hex Passthrough (downstream validates existence)
No match, input is short prefix sandbox id not found

Changes by component

CubeMaster

  • New pkg/sandboxid/ with table-driven unit tests
  • New ResolveSandboxID() in pkg/service/sandbox/:
    • Resolves against localcache.ListKnownSandboxIDs()
    • Falls back to listing sandboxes from healthy Cubelet nodes when cache is cold
  • Wired into: SandboxInfo, DestroySandbox, Exec, Update, SetTimeout, Refresh
  • HTTP handlers: snapshot create/rollback, template commit, sandbox logs
  • cubemastercli list --sandboxid filter uses prefix resolution

Cubelet

  • New pkg/sandboxid/ (same logic, separate module)
  • pkg/store/cubebox.Store.Get() resolves short/full IDs before indexer lookup
  • List filter by id benefits automatically via Get()

cubecli

  • destroy and inspect/info (metadata) use resolver instead of raw HasPrefix
  • Ambiguous or missing prefixes surface as CLI errors

Out of scope (unchanged)

  • cubecli ls default 12-char display truncation
  • Container ID prefix resolution (containerd CompleteShortId path unchanged)
  • SDK model changes (no new fields; clients pass short or full ID as before)

Motivation

Users often copy the truncated ID from cubecli ls and then fail on cubemastercli sandbox info -s <prefix> or cubecli destroy <prefix>. This aligns behavior with the common expectation: show short, accept short when unique.

Example:

# cubecli ls shows: a1b2c3d4e5f6 ...
cubemastercli sandbox info -s a1b2c3d4e5f6   # works when prefix is unique
cubecli destroy a1b2c3d4e5f6                   # works when prefix is unique
cubecli destroy a1b2                          # error if multiple sandboxes share prefix
Accept unique short prefixes for sandbox operations across CubeMaster,
Cubelet store lookups, and cubecli/cubemastercli commands while keeping
list display truncation unchanged.

Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.com>
Comment thread CubeMaster/pkg/sandboxid/resolve.go Outdated
Comment thread CubeMaster/pkg/service/sandbox/id_resolve.go
Comment thread CubeMaster/pkg/service/sandbox/id_resolve.go Outdated
Comment thread Cubelet/pkg/store/cubebox/store.go
Comment thread CubeMaster/pkg/sandboxid/resolve.go Outdated
Comment thread CubeMaster/pkg/service/sandbox/id_resolve.go
Comment thread CubeMaster/pkg/service/sandbox/id_resolve.go Outdated
Comment thread Cubelet/pkg/store/cubebox/store.go
Remove full-ID passthrough without candidates, add Store.Get fast-path
for 32-char IDs, log cluster collect failures, split cache side effects,
and cap concurrent node queries.

Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant