Skip to content

feat: auto-create PVC/Docker volumes on sandbox creation#661

Open
xfgong wants to merge 3 commits intoalibaba:mainfrom
xfgong:feature/volume-auto-create
Open

feat: auto-create PVC/Docker volumes on sandbox creation#661
xfgong wants to merge 3 commits intoalibaba:mainfrom
xfgong:feature/volume-auto-create

Conversation

@xfgong
Copy link
Copy Markdown

@xfgong xfgong commented Apr 8, 2026

Resolves #660

When a sandbox requests a PVC volume that doesn't exist yet, the server now auto-creates it instead of failing. This eliminates the need for callers to independently manage storage lifecycle outside OpenSandbox.

Changes:

  • Extend PVC model with optional provisioning hints (storageClass, storage size, accessModes) for auto-creation
  • Add volume_auto_create config flag (default: true) and volume_default_size (default: "1Gi") to StorageConfig
  • Add get_pvc/create_pvc methods to K8sClient
  • Kubernetes: ensure PVCs exist before creating workload, with race-condition handling (409 Conflict)
  • Docker: auto-create named volumes when not found (via docker API)
  • Update OpenAPI spec, configuration docs, and example configs
  • Update tests for new behavior

Summary

  • What is changing and why?

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 8, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f39558b56e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@xfgong xfgong force-pushed the feature/volume-auto-create branch from f39558b to deb2cf1 Compare April 8, 2026 04:05
When a sandbox requests a PVC volume that doesn't exist yet, the server
now auto-creates it instead of failing. This eliminates the need for
callers to independently manage storage lifecycle outside OpenSandbox.

Changes:
- Extend PVC model with optional provisioning hints (storageClass,
  storage size, accessModes) for auto-creation
- Add volume_auto_create config flag (default: true) and
  volume_default_size (default: "1Gi") to StorageConfig
- Add get_pvc/create_pvc methods to K8sClient
- Kubernetes: ensure PVCs exist before creating workload, with
  race-condition handling (409 Conflict) and graceful RBAC degradation
- Docker: auto-create named volumes when not found (via docker API)
- Update Helm chart RBAC to include PVC verbs
- Update OpenAPI spec, configuration docs, and example configs
- Update tests for new behavior
@xfgong xfgong force-pushed the feature/volume-auto-create branch from deb2cf1 to 52d1493 Compare April 8, 2026 04:05
return # Skip all remaining PVCs — same SA, same permissions
raise
if existing is not None:
logger.info("PVC '%s' already exists in namespace '%s'", claim_name, self.namespace)
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.

INFO level maybe is not suitable, there exists hotpath for sandbox creation wiith existing PVC.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure,change it to debug.

@Spground
Copy link
Copy Markdown
Collaborator

Spground commented Apr 8, 2026

System automatically create PVC if absent will help user a lot. it seems we didn't handle deletion of PVC created by us, maybe it's a problem?

xfgong added 2 commits April 8, 2026 20:53
This log fires on every sandbox creation with an existing PVC,
which is the common hot path. DEBUG avoids noise in production.
Add opt-in volume_auto_delete config (default false, Docker only).
Auto-created volumes are labeled with opensandbox.io/volume-managed-by
and cleaned up on sandbox deletion. Kubernetes PVCs are unaffected as
their lifecycle is managed by StorageClass reclaim policy.
@xfgong
Copy link
Copy Markdown
Author

xfgong commented Apr 8, 2026

System automatically create PVC if absent will help user a lot. it seems we didn't handle deletion of PVC created by us, maybe it's a problem?

Good catch.

For Docker, we've added opt-in volume cleanup (volume_auto_delete = false by default). Auto-created volumes are labeled with opensandbox.io/volume-managed-by: server and removed on sandbox deletion when enabled. Pre-existing volumes are never touched.

For Kubernetes PVCs, they don't need server-side cleanup — their lifecycle is governed by the StorageClass reclaimPolicy (Retain/Delete), so Kubernetes handles it natively.

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 Request] Auto-create backing storage (PVC / Docker volume) when volume is requested

3 participants