CubeSandbox icon indicating copy to clipboard operation
CubeSandbox copied to clipboard

fix(sandbox): return volume mounts in sandbox info and list APIs

Open xiaojunxiang2023 opened this issue 5 months ago • 6 comments

Summary

  • Expose volume_mounts on Cubelet list Container responses and thread them through CubeMaster sandbox info/list into CubeAPI GET /sandboxes and list payloads.
  • Populate hostPath when injecting host-dir mounts so clients can see bind-mount source paths after create.
  • Extend SandboxVolumeMount with optional hostPath and readOnly; regenerate openapi.yml and web TypeScript schema; update SDK models and cubemastercli info output.

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)

xiaojunxiang2023 avatar Jul 01 '26 08:07 xiaojunxiang2023

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:

  1. Cubelet — exposes volume_mounts in the gRPC Container message (proto field 10)
  2. CubeMaster — new volume_mounts.go with collectVolumeMountsFromContainers (aggregate across containers) → volumeMountsToContainerInfo (filter internal rootfs + dedupe) → VolumeMountInfo in list/info JSON APIs
  3. CubeAPI (Rust) — new CubeVolumeMount deserialization struct → map_volume_mounts converter → populates SandboxDetail.volume_mounts and ListedSandbox.volume_mounts
  4. 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)

  • volumeMountsToContainerInfo in CubeMaster/pkg/service/sandbox/volume_mounts.go explicitly omits HostPath — the struct it writes (VolumeMountInfo) doesn't have a hostPath field.
  • The Rust CubeVolumeMount deserializes containerPath from the CubeMaster JSON but map_volume_mounts maps only name, container_path → path, and readonly → read_only.
  • Tests in Python SDK (test_sandbox.py) and CLI (list_info_test.go) assert hostPath is absent.
  • E2e test asserts "hostPath" not in m for 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 root
  • Name starts 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 mounts
  • volumeMountsToContainerInfo: skips nil mounts, returns nil for empty input
  • isInternalRootfsMount: nil-safe
  • map_volume_mounts (Rust): returns None for empty input
  • Go protobuf getter GetVolumeMounts(): nil-safe (generated, but the PR's injectHostDirMounts at hostdir_mount.go:97 and collectVolumeMountsFromContainers also 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.

cubesandboxbot[bot] avatar Jul 01 '26 08:07 cubesandboxbot[bot]

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.yml copyright header removed by the OpenAPI export.
  • ** 2 ** Added a doc comment on CubeVolumeMount (CubeMaster deserialization shape vs request VolumeMount).
  • ** 3 ** Added godoc on VolumeMountInfo, collectVolumeMountsFromContainers, and volumeMountsToContainerInfo.
  • ** 5 ** Added tests for empty map_volume_mounts input, all-empty entries filtered out, nil container in the slice, and nil mount in volumeMountsToContainerInfo.
  • ** 7 ** Documented why the map_volume_mounts filter keeps partial name/path entries.

No code change (by design)

  • ** 4 ** cubemastercli info reuses the same tabwriter as the surrounding 2-column rows; 4-column VOLUME_MOUNTS may 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.

xiaojunxiang2023 avatar Jul 01 '26 08:07 xiaojunxiang2023

@ls-ggg Does this conflict with our volume work?

kinwin-ustc avatar Jul 01 '26 10:07 kinwin-ustc

@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.

xiaojunxiang2023 avatar Jul 09 '26 08:07 xiaojunxiang2023

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.

ls-ggg avatar Jul 13 '26 02:07 ls-ggg

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.

xiaojunxiang2023 avatar Jul 13 '26 02:07 xiaojunxiang2023

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 avatar Jul 27 '26 03:07 ls-ggg

@ls-ggg ok, rebase done

xiaojunxiang2023 avatar Jul 27 '26 04:07 xiaojunxiang2023

@xiaojunxiang2023 Ack! e2e framework landed in v0.6.0. Please add tests under tests/e2e/sdk_compat. Thanks!

ls-ggg avatar Jul 29 '26 07:07 ls-ggg

@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 avatar Jul 29 '26 09:07 xiaojunxiang2023

@xiaojunxiang2023 Sorry about that—could you resolve these conflicts? I'm prioritizing this PR today

ls-ggg avatar Jul 30 '26 03:07 ls-ggg

@ls-ggg Rebased onto latest master and resolved the conflicts (kept master readOnly bool semantics and added hostPath). Force-pushed in f2c99ca.

xiaojunxiang2023 avatar Jul 30 '26 03:07 xiaojunxiang2023

PR #696 — Issues (concise)

Blocking

  1. volumeMounts empty on common path — collectVolumeMountsFromContainers skips type=sandbox, but template sandboxes often have only that container. Host mounts live there → info/list return volumeMounts: null. Live e2e: test_get_info_returns_volume_mounts / test_list_returns_volume_mounts fail. Unit tests only cover sandbox+workload.

  2. E2E vs API serialization — Tests assert readOnly is False, but CubeAPI omits readOnly when false. Will fail after (1) is fixed. Use bool(m.get("readOnly")) is False.

Product / API & SDK surface

  1. hostPath should not be user-facing — Node-local path; not useful (and risky) for clients. Prefer omit from public CubeAPI responses and SDKs; keep path / readOnly / name. This PR currently exposes it in the API, Go VolumeMount.HostPath, and Python via raw volumeMounts JSON.

  2. SDK field gaps / inconsistency

    • Create vs query: Python already has create-time VolumeMount(..., read_only=True) (#1098), but no typed query fields on SandboxInfo for mounts — only raw dict access (info.get("volumeMounts")) if the API returns them.
    • Go: SandboxInfo.VolumeMounts exists; this PR adds HostPath / ReadOnly on the struct — HostPath should not be part of the public SDK model (see #3).
    • Python: no first-class volume_mounts / host_path attributes; 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 surface hostPath.

Non-blocking / gaps

  1. 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 avatar Jul 30 '26 04:07 ls-ggg

@ls-ggg Thanks for the clear review — addressed in the latest push (2899dd4):

Blocking

  1. volumeMounts empty on common path — collectVolumeMountsFromContainers now collects mounts from all containers (including type=sandbox), with dedupe by public identity (name + path + readOnly). Added unit coverage for sandbox-only + cross-type dedupe.
  2. E2E readOnly omit-false — updated test_get_info_returns_volume_mounts / test_list_returns_volume_mounts to use bool(m.get("readOnly")) is False.

Product / API & SDK

  1. hostPath removed from public surface — dropped from CubeMaster VolumeMountInfo, CubeAPI SandboxVolumeMount / openapi / generated schema, Go VolumeMount, CLI info output, and e2e/SDK assertions. Public shape is name / path / readOnly only.
  2. SDK typed query fields (Python) — Go already has typed SandboxInfo.VolumeMounts (without HostPath). Python still returns mounts via the existing raw/dict SandboxInfo path (info["volumeMounts"]); adding first-class volume_mounts attributes can be a small follow-up if you want that in this PR rather than later.

Non-blocking

  1. 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.

xiaojunxiang2023 avatar Jul 30 '26 06:07 xiaojunxiang2023

Retest update (576e22a)

Thanks for the follow-up — the earlier issues look fixed on a live deploy:

  • volumeMounts are returned for the common single type=sandbox template path
  • public responses omit hostPath
  • e2e readOnly assertions 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 avatar Jul 30 '26 06:07 ls-ggg

@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}
]

xiaojunxiang2023 avatar Jul 30 '26 06:07 xiaojunxiang2023

Retest (f5bcd223) — LGTM

Live deploy of CubeAPI / CubeMaster / Cubelet on the test host; previous issues look fixed.

Fixed / verified

  • volumeMounts returned for the common single type=sandbox template path
  • Public info/list omit hostPath
  • Internal rootfs mounts (cube_rootfs_* / path: "/") filtered out
  • e2e readOnly assertions 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 avatar Jul 30 '26 07:07 ls-ggg

@ls-ggg Thanks for the thorough retest and LGTM — glad the public volumeMounts shape looks right on the live deploy.

xiaojunxiang2023 avatar Jul 30 '26 07:07 xiaojunxiang2023

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 avatar Jul 31 '26 12:07 lkml-likexu

@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

xiaojunxiang2023 avatar Jul 31 '26 12:07 xiaojunxiang2023