Skip to content

e2b add volume api#580

Open
ZhaoQing7892 wants to merge 4 commits into
openkruise:masterfrom
ZhaoQing7892:add_e2b_volume
Open

e2b add volume api#580
ZhaoQing7892 wants to merge 4 commits into
openkruise:masterfrom
ZhaoQing7892:add_e2b_volume

Conversation

@ZhaoQing7892

Copy link
Copy Markdown
Contributor

No description provided.

@kruise-bot kruise-bot requested review from furykerry and zmberg June 26, 2026 08:01
@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign furykerry for approval by writing /assign @furykerry in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.56613% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.75%. Comparing base (9564476) to head (13f6493).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pkg/servers/e2b/volume.go 74.85% 40 Missing and 2 partials ⚠️
pkg/sandbox-manager/infra/sandboxcr/volume.go 76.02% 30 Missing and 5 partials ⚠️
pkg/cache/index.go 0.00% 14 Missing ⚠️
pkg/servers/e2b/routes.go 78.94% 3 Missing and 1 partial ⚠️
pkg/cache/controllers/cache_controller_pvc_wait.go 90.47% 2 Missing ⚠️
pkg/cache/controllers/test_helpers.go 0.00% 1 Missing and 1 partial ⚠️
pkg/cache/tasks.go 94.11% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #580      +/-   ##
==========================================
- Coverage   79.85%   79.75%   -0.11%     
==========================================
  Files         202      205       +3     
  Lines       14796    15226     +430     
==========================================
+ Hits        11816    12143     +327     
- Misses       2551     2643      +92     
- Partials      429      440      +11     
Flag Coverage Δ
unittests 79.75% <76.56%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

},
}

err := i.Cache.GetClient().Create(ctx, pvc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plz add PVC create and list role and rolebinding

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

Comment thread pkg/cache/tasks.go Outdated

// If PVC is still Pending, check Events for provisioning failures
if pvc.Status.Phase == corev1.ClaimPending {
events := &corev1.EventList{}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it is bad practice for controller to rely on k8s event for handling, consider using pvc conditions instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed Event queries and switched to checking pvc.Status.Conditions for failure detection.

// validateStorageClass checks if the StorageClass exists and uses Immediate binding mode.
func (i *Infra) validateStorageClass(ctx context.Context, storageClassName string) error {
// StorageClass is a cluster-scoped resource, no namespace needed
sc := &storagev1.StorageClass{}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plz add storage class role and rolebinding

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

Comment thread pkg/servers/e2b/routes.go

// Volume management endpoints
RegisterE2BRoute(sc.mux, http.MethodPost, "/volumes", sc.CreateVolume, sc.CheckApiKey)
RegisterE2BRoute(sc.mux, http.MethodGet, "/volumes", sc.ListVolumes, sc.CheckApiKey)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plz modify CheckApiKey, so that we can ensure that the volume is owned by the user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

)

// CreateVolume creates a new PersistentVolumeClaim for the user
func (i *Infra) CreateVolume(ctx context.Context, opts infra.CreateVolumeOptions) (*infra.VolumeInfo, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this file has zero UT coverage, plz add UT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

Comment thread pkg/sandbox-manager/consts/consts.go Outdated
)

const (
DefaultWaitBoundPVCTimeout = 60 * time.Second

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DefaultWaitBoundPVCTimeout is in a separate const () block from the other constants. It could be in the same block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

}

err := i.Cache.GetClient().Create(ctx, pvc)
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plz handle already exist error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

Comment thread pkg/servers/e2b/volume.go
func validateVolumeRequest(request models.NewVolumeRequest) error {
if request.Name == "" {
return fmt.Errorf("name is required")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plz Add DNS-1123 label validation for the volume name to catch invalid names before they reach the API server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added DNS-1123 label validation in validateCreateVolumeOptions()

Comment thread pkg/servers/e2b/volume.go Outdated
})
if err != nil {
log.Error(err, "Failed to get volume", "volumeID", volumeID, "namespace", namespace)
if apierrors.IsNotFound(err) || managererrors.GetErrCode(err) == managererrors.ErrorNotFound {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GetVolume never return apierrors.IsNotFound error , consider remove the condition, and only checks for managererrors.ErrorNotFound

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed the apierrors.IsNotFound check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants