fix(sandbox): return volume mounts in sandbox info and list APIs
Summary
- Expose
volume_mountson Cubelet listContainerresponses and thread them through CubeMaster sandbox info/list into CubeAPIGET /sandboxesand list payloads. - Populate
hostPathwhen injecting host-dir mounts so clients can see bind-mount source paths after create. - Extend
SandboxVolumeMountwith optionalhostPathandreadOnly; regenerateopenapi.ymland web TypeScript schema; update SDK models andcubemastercli infooutput.
Problem
Host mounts are applied at create time via metadata["host-mount"], but sandbox detail/list APIs always returned volumeMounts: null. Web, CLI, and SDK callers could not inspect mounts on a running sandbox.
Test plan
- [x]
go test ./services/cubebox -run TestToGRPCContainerIncludesVolumeMounts(Cubelet) - [x]
go test ./pkg/service/sandbox -run 'TestInjectHostDirMounts|TestCollectVolumeMounts'(CubeMaster) - [x]
go test ./cmd/cubemastercli/commands/cubebox -run TestPrintSandboxInfoBlockIncludesVolumeMounts(CLI) - [x]
cargo test map_volume_mounts(CubeAPI)
Review: PR #696 — fix(sandbox): return volume mounts in sandbox info and list APIs
AI-generated review — the reviewer is an automated agent, not a human. Findings should be verified before acting on them.
Summary
This PR plumbs volume-mount visibility through the entire sandbox stack: Cubelet stores → CubeMaster gRPC/JSON → CubeAPI REST → SDKs (Go, Python, TypeScript/web) + CLI. Previously, mount annotations (host-mount) were applied at create time but never surfaced in read APIs. The change is 759 additions, 171 deletions across 23 files.
Architecture: New data flows in four independent layers, each with its own type:
- Cubelet — exposes
volume_mountsin the gRPCContainermessage (proto field 10) - CubeMaster — new
volume_mounts.gowithcollectVolumeMountsFromContainers(aggregate across containers) →volumeMountsToContainerInfo(filter internal rootfs + dedupe) →VolumeMountInfoin list/info JSON APIs - CubeAPI (Rust) — new
CubeVolumeMountdeserialization struct →map_volume_mountsconverter → populatesSandboxDetail.volume_mountsandListedSandbox.volume_mounts - SDK / CLI / Web — consume the new field
Overall assessment
Well-structured, well-tested change. The PR follows existing patterns, has sensible null-safety guards throughout, correctly omits node-local hostPath from public APIs, and filters internal Cube rootfs mounts. Tests exist at every layer including a new e2e test. A few minor observations below.
Observations
1. Proto field numbering matches between Cubelet and CubeMaster (good)
Both CubeMaster/api/.../cubebox.proto and Cubelet/api/.../cubebox.proto add repeated VolumeMounts volume_mounts = 10 to the Container message. The field number 10 is available (previous max was 9 for paused_at). ✅
2. hostPath correctly excluded from public APIs (good)
volumeMountsToContainerInfoinCubeMaster/pkg/service/sandbox/volume_mounts.goexplicitly omitsHostPath— the struct it writes (VolumeMountInfo) doesn't have a hostPath field.- The Rust
CubeVolumeMountdeserializescontainerPathfrom the CubeMaster JSON butmap_volume_mountsmaps onlyname,container_path→path, andreadonly→read_only. - Tests in Python SDK (
test_sandbox.py) and CLI (list_info_test.go) asserthostPathis absent. - E2e test asserts
"hostPath" not in mfor both info and list responses.
3. Internal rootfs mounts correctly filtered
The isInternalRootfsMount predicate in volume_mounts.go catches two patterns:
ContainerPath == "/"— catches any mount at rootNamestarts with"cube_rootfs_"— catches the specific Cube runtime prefix
The e2e test also asserts neither "/" path nor cube_rootfs_* names leak into responses. Covers the gap that a mount named unconventionally but mounted at / would also be caught.
4. Null-safety handled consistently
collectVolumeMountsFromContainers: skips nil containers and nil mountsvolumeMountsToContainerInfo: skips nil mounts, returns nil for empty inputisInternalRootfsMount: nil-safemap_volume_mounts(Rust): returnsNonefor empty input- Go protobuf getter
GetVolumeMounts(): nil-safe (generated, but the PR'sinjectHostDirMountsathostdir_mount.go:97andcollectVolumeMountsFromContainersalso guard against nil)
5. Dedup key in volumeMountsToContainerInfo — acknowledged limitation
The dedup key is name + "\x1f" + containerPath + "\x1f" + readOnly. The code comment explicitly documents this is hostdir-oriented and that non-hostdir mounts with identical (name, path, readOnly) tuples would collapse. Given that hostPath is intentionally excluded from the public struct, this is a reasonable trade-off. Worth keeping an eye on if the mount model gains additional dimensions in the future.
6. VolumeMountInfo.Readonly always serializes in JSON
The VolumeMountInfo struct in types/types.go has:
Readonly bool `json:"readonly,omitempty"`
Wait — actually the PR adds it without omitempty:
Readonly bool `json:"readonly,omitempty"`
No, looking at the diff more carefully:
+type VolumeMountInfo struct {
+ Name string `json:"name,omitempty"`
+ ContainerPath string `json:"container_path,omitempty"`
+ Readonly bool `json:"readonly,omitempty"`
+}
The omitempty tag means false is omitted during Go JSON serialization. This is consistent with the Rust SandboxVolumeMount model which also uses skip_serializing_if = "is_false". ✅
7. CLI tabwriter format matches header/data rows
The CLI output uses:
VOLUME_MOUNTS
NAME CONTAINER_PATH READ_ONLY
<val> <val> <val>
The list_info_test.go correctly uses string Contains checks (not exact match), so tab alignment differences won't cause test flakiness. ✅
8. GetSandboxResponse::into_items only covers the detail path
This is the SandboxDetail struct in cubemaster/mod.rs used by GET /sandboxes/{id}/info. The into_items method now copies volume_mounts: item.volume_mounts. The get_sandbox method in sandboxes.rs maps this via map_volume_mounts. Both paths (list via from_cubemaster_info and detail via get_sandbox) are correctly plumbed. ✅
9. Test coverage gaps (minor)
The Rust tests add unit coverage for map_volume_mounts (3 test cases + updated fixtures) but there's no integration-level test in Rust that exercises the entire CubeVolumeMount → SandboxVolumeMount conversion through get_sandbox with non-empty mounts. The existing from_cubemaster_info test at line ~1400 only sets volume_mounts: vec![] on the fixture (verifying empty is handled). Consider adding a test that exercises the get_sandbox path with populated mounts.
Not blocking — the e2e test covers this end-to-end — but a pure unit test would catch regressions faster.
Conclusion
The PR is well-implemented, correctly layered, and has strong test coverage. The data model choices (separate response-only CubeVolumeMount, explicit omission of hostPath, deduplication with caveats) are sound for the current scope. Ship it with confidence.
Review: PR #696 — Expose volume mounts in sandbox info/list APIs
Overall: Well-structured change that consistently threads volume mount data through the entire stack (Cubelet to CubeMaster to CubeAPI to SDKs to CLI to Web). Tests cover the happy path well. A few items below.
1. openapi.yml copyright header unintentionally removed
File: openapi.yml (lines 1-6, deleted)
The diff removes the copyright header block. This was likely an accidental deletion. Please restore or confirm dliberate.
2. Exported Rust struct CubeVolumeMount missing doc comment
File: CubeAPI/src/cubemaster/mod.rs:9
A brief doc comment would help distinguish this deserialization target from the serialization-only VolumeMount.
3. Exported Go types/functions missing godoc comments
Files:
- CubeMaster/pkg/service/sandbox/types/types.go:529 - VolumeMountInfo
- CubeMaster/pkg/service/sandbox/volume_mounts.go:567 - collectVolumeMountsFromContainers
- CubeMaster/pkg/service/sandbox/volume_mounts.go:589 - volumeMountsToContainerInfo
All exported but undocumented.
4. CLI tabwriter alignment may produce ragged output
File: CubeMaster/cmd/cubemastercli/commands/cubebox/info.go:127-137
The 4-column VOLUME_MOUNTS header is aligned by the same tabwriter as surrounding 2-column rows, likely producing uneven columns.
5. Test coverage gaps: edge cases in mapping functions
- map_volume_mounts with empty input
- map_volume_mounts where all entries filter to empty
- map_volume_mounts with mixed valid + invalid
- collectVolumeMountsFromContainers with nil container in the slice
- volumeMountsToContainerInfo with nil mount or empty slice
6. volumeMountsToContainerInfo defensive nil check (optional)
File: CubeMaster/pkg/service/sandbox/volume_mounts.go:595
Nil guard is redundant since its caller already filters nils.
7. map_volume_mounts filter could use a comment
File: CubeAPI/src/services/sandboxes.rs:736
Filter intentionally preserves partial entries; an inline comment would make this explicit.
Summary: No security concerns - data-propagation-only change. All existing auth/access controls apply
Fixed
- ** 1 ** Restored the
openapi.ymlcopyright header removed by the OpenAPI export. - ** 2 ** Added a doc comment on
CubeVolumeMount(CubeMaster deserialization shape vs requestVolumeMount). - ** 3 ** Added godoc on
VolumeMountInfo,collectVolumeMountsFromContainers, andvolumeMountsToContainerInfo. - ** 5 ** Added tests for empty
map_volume_mountsinput, all-empty entries filtered out, nil container in the slice, and nil mount involumeMountsToContainerInfo. - ** 7 ** Documented why the
map_volume_mountsfilter keeps partial name/path entries.
No code change (by design)
- ** 4 **
cubemastercli inforeuses the same tabwriter as the surrounding 2-column rows; 4-columnVOLUME_MOUNTSmay look uneven but remains readable for ops/debug. Happy to polish formatting in a follow-up if maintainers prefer. - ** 6 ** Keeping the nil guard in
volumeMountsToContainerInfo— protobuf slices can contain nil entries and callers may grow over time.
@ls-ggg Does this conflict with our volume work?
@ls-ggg Does this conflict with our volume work? @kinwin-ustc Could you help move this forward when you have some time? I think this feature is really necessary for operations troubleshooting.
Thanks for your pr,We are currently developing volume-related features that may conflict with your PR. We plan to submit this code later this week, so you can rebase your work against it to implement these features.
Thanks for your pr,We are currently developing volume-related features that may conflict with your PR. We plan to submit this code later this week, so you can rebase your work against it to implement these features.
OK, I'll rebase my work once the volume-related changes are available.
Hi! The core volume capabilities have been merged into master. Please rebase on the latest code and implement your changes on top of it
@ls-ggg ok, rebase done
@xiaojunxiang2023 Ack! e2e framework landed in v0.6.0. Please add tests under tests/e2e/sdk_compat. Thanks!
@ls-ggg Thanks! Added sdk_compat e2e coverage under cases/host-mount/: create with host mounts, then assert get_info and list expose volumeMounts (hostPath/path/readOnly). Rebased onto latest master and force-pushed.
@xiaojunxiang2023 Sorry about that—could you resolve these conflicts? I'm prioritizing this PR today
@ls-ggg Rebased onto latest master and resolved the conflicts (kept master readOnly bool semantics and added hostPath). Force-pushed in f2c99ca.
PR #696 — Issues (concise)
Blocking
-
volumeMountsempty on common path —collectVolumeMountsFromContainersskipstype=sandbox, but template sandboxes often have only that container. Host mounts live there → info/list returnvolumeMounts: null. Live e2e:test_get_info_returns_volume_mounts/test_list_returns_volume_mountsfail. Unit tests only cover sandbox+workload. -
E2E vs API serialization — Tests assert
readOnly is False, but CubeAPI omitsreadOnlywhen false. Will fail after (1) is fixed. Usebool(m.get("readOnly")) is False.
Product / API & SDK surface
-
hostPathshould not be user-facing — Node-local path; not useful (and risky) for clients. Prefer omit from public CubeAPI responses and SDKs; keeppath/readOnly/name. This PR currently exposes it in the API, GoVolumeMount.HostPath, and Python via rawvolumeMountsJSON. -
SDK field gaps / inconsistency
- Create vs query: Python already has create-time
VolumeMount(..., read_only=True)(#1098), but no typed query fields onSandboxInfofor mounts — only raw dict access (info.get("volumeMounts")) if the API returns them. - Go:
SandboxInfo.VolumeMountsexists; this PR addsHostPath/ReadOnlyon the struct —HostPathshould not be part of the public SDK model (see #3). - Python: no first-class
volume_mounts/host_pathattributes; relying on raw API keys is not a stable SDK contract. If mounts are exposed at all, use typed fields aligned with the public API (name,path,read_only) and document them; do not surfacehostPath.
- Create vs query: Python already has create-time
Non-blocking / gaps
- No unit test for single sandbox container + host mounts.
What passed
Unit tests from the PR plan; host-mount create/RW/RO/reject e2e still work (mounts function inside the sandbox; only info/list exposure fails).
Request: Please share a short demo of the intended end-to-end effect after fixes — e.g. create a sandbox with host-mount (RW + RO), then show GET /sandboxes/:id and list output (and preferably SDK get_info / list) with the expected volumeMounts shape, so reviewers can confirm what clients are supposed to see.
@ls-ggg Thanks for the clear review — addressed in the latest push (2899dd4):
Blocking
volumeMountsempty on common path —collectVolumeMountsFromContainersnow collects mounts from all containers (includingtype=sandbox), with dedupe by public identity (name+path+readOnly). Added unit coverage for sandbox-only + cross-type dedupe.- E2E
readOnlyomit-false — updatedtest_get_info_returns_volume_mounts/test_list_returns_volume_mountsto usebool(m.get("readOnly")) is False.
Product / API & SDK
hostPathremoved from public surface — dropped from CubeMasterVolumeMountInfo, CubeAPISandboxVolumeMount/ openapi / generated schema, GoVolumeMount, CLIinfooutput, and e2e/SDK assertions. Public shape isname/path/readOnlyonly.- SDK typed query fields (Python) — Go already has typed
SandboxInfo.VolumeMounts(withoutHostPath). Python still returns mounts via the existing raw/dictSandboxInfopath (info["volumeMounts"]); adding first-classvolume_mountsattributes can be a small follow-up if you want that in this PR rather than later.
Non-blocking
- Covered by the new sandbox-only unit test above.
Expected client view (after create with RW+RO host mounts)
"volumeMounts": [
{"name": "hostdir-0", "path": "/mnt/rw"},
{"name": "hostdir-1", "path": "/mnt/ro", "readOnly": true}
]
(readOnly omitted when false; no hostPath.)
Unit tests for CubeMaster / CubeAPI map_volume_mounts / Go+Python SDK volume-mount decoding are green. Happy to run a live create→info/list demo against a cluster if you want that captured in-thread next.
Retest update (576e22a)
Thanks for the follow-up — the earlier issues look fixed on a live deploy:
volumeMountsare returned for the common singletype=sandboxtemplate path- public responses omit
hostPath - e2e
readOnlyassertions match CubeAPI’s omit-when-false serialization cases/host-mount/test_create_with_mount.py— 6/6 passed
Remaining issue: rootfs mount leaks into public volumeMounts
After collecting mounts from all containers (including type=sandbox), info/list now also expose the internal writable-rootfs mount, e.g.:
[
{ "name": "cube_rootfs_rw", "path": "/" },
{ "name": "hostdir-0", "path": "/mnt/rw" },
{ "name": "hostdir-1", "path": "/mnt/ro", "readOnly": true }
]
Hostdir entries look correct, but cube_rootfs_rw / path: "/" is an implementation detail and probably should not be part of the public sandbox info/list contract (or the SDK surface).
Suggestion: keep collecting from sandbox containers (needed for host-mount), but filter out rootfs-style mounts — e.g. container_path == "/" and/or known names like cube_rootfs_* — so clients only see user-facing mounts (name / path / readOnly).
@ls-ggg Thanks for the retest — fixed the rootfs leak in the latest push.
Public volumeMounts now filters internal rootfs mounts (container_path == "/" and/or names prefixed with cube_rootfs_) while still collecting hostdir mounts from type=sandbox containers. Added unit coverage and tightened the host-mount e2e assertions so cube_rootfs_* / path: "/" must not appear.
Expected shape after RW+RO host mounts:
[
{"name": "hostdir-0", "path": "/mnt/rw"},
{"name": "hostdir-1", "path": "/mnt/ro", "readOnly": true}
]
Retest (f5bcd223) — LGTM
Live deploy of CubeAPI / CubeMaster / Cubelet on the test host; previous issues look fixed.
Fixed / verified
volumeMountsreturned for the common singletype=sandboxtemplate path- Public info/list omit
hostPath - Internal rootfs mounts (
cube_rootfs_*/path: "/") filtered out - e2e
readOnlyassertions match omit-when-false serialization
Observed public shape
[
{ "name": "hostdir-0", "path": "/mnt/rw" },
{ "name": "hostdir-1", "path": "/mnt/ro", "readOnly": true }
]
Tests
- PR unit tests (Cubelet / CubeMaster / CLI / CubeAPI
map_volume_mounts) — passed cases/host-mount/test_create_with_mount.py— 6/6 passed
LGTM
@ls-ggg Thanks for the thorough retest and LGTM — glad the public volumeMounts shape looks right on the live deploy.
It looks like we need:
diff --git a/Cubelet/doc/cubelet-api.md b/Cubelet/doc/cubelet-api.md
index ab14260..f87e6b3 100644
--- a/Cubelet/doc/cubelet-api.md
+++ b/Cubelet/doc/cubelet-api.md
@@ -433,6 +433,7 @@ Capability contains the container capabilities to add or drop
| finished_at | [int64](#int64) | | exit time of the container in nanoseconds. |
| labels | [Container.LabelsEntry](#cubelet-services-cubebox-v1-Container-LabelsEntry) | repeated | |
| paused_at | [int64](#int64) | | |
+| volume_mounts | [VolumeMounts](#cubelet-services-cubebox-v1-VolumeMounts) | repeated | Mounts declared on the container spec (including host-dir mounts). |
@lkml-likexu Thanks for catching this — the Container table in Cubelet/doc/cubelet-api.md was missing volume_mounts even though the proto already exposes it.
Opened a follow-up docs PR with the exact row you suggested: https://github.com/TencentCloud/CubeSandbox/pull/1241