Skip to content

feat(driver): configure sandbox resources#336

Draft
eetoc wants to merge 1 commit into
mainfrom
feat/configurable-sandbox-resources
Draft

feat(driver): configure sandbox resources#336
eetoc wants to merge 1 commit into
mainfrom
feat/configurable-sandbox-resources

Conversation

@eetoc

@eetoc eetoc commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add shared SANDBOX_CPUS, SANDBOX_MEMORY_MIB, and SANDBOX_DISK_SIZE_GB daemon configuration
  • apply the same CPU, memory, and disk limits to BoxLite and Microsandbox
  • default sandbox resources to 4 CPUs, 4096 MiB memory, and 6 GiB disk
  • document the environment variables and update configuration/runtime tests

Testing

  • go test ./pkg/config ./pkg/driver
  • task lint (blocked by pre-existing unused boxliteVolumeBridgeIsMountPoint in pkg/driver/boxlite_volume_bridge.go:188, outside this change)

Checklist

  • Documentation updated when behavior or configuration changed.
  • Tests added or updated for user-visible behavior.
  • No secrets, private endpoints, internal certificates, or local runtime state included.

@monkeyscan

monkeyscan Bot commented Jul 18, 2026

Copy link
Copy Markdown

PR Title: feat(driver): configure sandbox resources

Commit: 969b308

该PR将沙箱资源配置从硬编码和分散的环境变量(BOX_DISK_SIZE_GB、MICROSANDBOX_BIND_QUOTA_GB)统一为三个共享的环境变量(SANDBOX_CPUS、SANDBOX_MEMORY_MIB、SANDBOX_DISK_SIZE_GB),并在Config结构体中增加了SandboxCPUs、SandboxMemoryMiB、SandboxDiskSizeGB字段。BoxLite和Microsandbox两个运行时现在都从配置中读取CPU、内存和磁盘大小。

关键设计决策:

  1. 使用positiveIntEnv辅助函数统一解析正整数环境变量,并带有默认回退。
  2. 删除了MICROSANDBOX_BIND_QUOTA_GB的独立覆盖能力,统一使用SANDBOX_DISK_SIZE_GB。
  3. 将微沙箱的内存默认值从硬编码的8192 MiB降至4096 MiB。

整体评估:代码结构更清晰,但存在潜在的默认行为回归风险,特别是微沙箱内存默认值的下降可能影响现有docker-in-VM工作负载。此外,BoxLite驱动中CPU和内存设置变为无条件调用,如果Config结构体手动构造时未设置这两个字段,可能传递0值给底层C库。

Comment thread pkg/config/config.go Outdated
Comment thread pkg/driver/boxlite_cgo.go Outdated
@eetoc
eetoc force-pushed the feat/configurable-sandbox-resources branch from 969b308 to ed5480a Compare July 18, 2026 03:56
@monkeyscan

monkeyscan Bot commented Jul 18, 2026

Copy link
Copy Markdown

PR Title: feat(driver): configure sandbox resources

Commit: ed5480a

本次 PR 统一了 BoxLite 与 Microsandbox 两个 driver 的沙箱资源配置,将原来的 BOX_DISK_SIZE_GBMICROSANDBOX_BIND_QUOTA_GB 合并为 SANDBOX_CPUSSANDBOX_MEMORY_MIBSANDBOX_DISK_SIZE_GB,并新增 configuredSandboxResources 辅助函数为两个 runtime 提供一致的默认值与配置解析逻辑。

主要变更:

  • pkg/config/config.go:新增 DefaultSandboxCPUs/MemoryMiB/DiskSizeGB,使用 positiveUintEnv 族函数统一解析环境变量,并对内存(31 bit)和磁盘(22 bit)做上限保护以防止 C API / uint32 溢出。
  • pkg/driver/sandbox_resources.go(新增):提供 nil-safe 的默认值回退逻辑。
  • pkg/driver/boxlite_cgo.go:为 BoxLite 显式设置 CPU、Memory、DiskSize。
  • pkg/driver/microsandbox_runtime.go:将原来写死的 8192 MiB / 4 CPU 改为读取配置;microsandboxBindQuotaGB() 直接返回 SandboxDiskSizeGB,移除独立的 MICROSANDBOX_BIND_QUOTA_GB

风险评估:整体逻辑清晰,类型上限保护合理,测试覆盖新增逻辑。但存在一处可能的编译错误(smoke test 中 int 变量直接赋给 int32 字段),以及 Microsandbox 默认内存从 8 GiB 降至 4 GiB 的行为回归风险。

Comment thread pkg/driver/microsandbox_runtime.go
Comment thread pkg/driver/runtime_mount_manifest_smoke_test.go
@eetoc
eetoc force-pushed the feat/configurable-sandbox-resources branch from ed5480a to 2bb92e2 Compare July 18, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant