Skip to content

feat(admin): add Template API for K8s Pool-based sandbox warm path - #1311

Open
Generalwin wants to merge 4 commits into
alibaba:masterfrom
Generalwin:e2b-style-template-implement
Open

feat(admin): add Template API for K8s Pool-based sandbox warm path#1311
Generalwin wants to merge 4 commits into
alibaba:masterfrom
Generalwin:e2b-style-template-implement

Conversation

@Generalwin

Copy link
Copy Markdown
Collaborator

What does this PR do?

Implements Template API for sandbox warm pool management via K8s Pool CRD. Resolves #1310.

Changes

  • Template API endpoints (template_api.py): POST/GET/DELETE /apis/envs/sandbox/v1/templates
  • K8s Provider (provider.py): Pool informer + create_template/get_template_status/delete_template methods
  • SandboxManager (sandbox_manager.py): proxy methods for template operations
  • Config (config.py): pool_template field for Jinja2-rendered Pool CRD config
  • Constants (constants.py): Pool CRD constants, TEMPLATE_ID_PREFIX = "tpl-", managed-by label
  • Proto (request.py/response.py): TemplateCreateRequest/TemplateStatusResponse

Design

  • templateID = tpl-{sha256(non-null spec fields)[:16]} — same spec always produces same ID
  • Pool CRD is the source of truth (no DB), Informer cache for reads
  • 409 Conflict on duplicate create = idempotent
  • Status mapping: available > 0 → ready, available == 0, total > 0 → building

Testing

  • Unit tests (tests/unit/test_template_api.py): 19 cases — ID generation, Spec, Jinja2 rendering, status mapping, constants
  • Smoke tests (tests/smoke/test_template.py): lifecycle (create → wait ready → delete) + idempotent create, with --admin-url and --smoke-image CLI options
pytest tests/unit/test_template_api.py     # 19 passed
pytest tests/smoke/ --smoke-image <image>  # 2 passed

@Generalwin
Generalwin force-pushed the e2b-style-template-implement branch from be4487a to 352ef98 Compare August 5, 2026 03:09
Comment thread rock/admin/entrypoints/template_api.py Outdated

template = copy.deepcopy(self._pool_template)

ctx: dict[str, Any] = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx需要包含initcontainer的镜像

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个image字段就够了,可以渲染在init container

Comment thread rock/sandbox/operator/k8s/provider.py
@Generalwin
Generalwin force-pushed the e2b-style-template-implement branch from 4d65ac6 to a5f879b Compare August 10, 2026 03:15
@Generalwin
Generalwin requested a review from zhongwen666 August 10, 2026 03:17
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.

[Feature] Template API: K8s Pool-based sandbox warm path

2 participants