lablup / lablup/backend.ai

Implement cascade soft delete for Projects and Resource Groups

Open
#7,741 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

## Summary

Provide a `force` option for project/resource group deletion that cascades soft delete to all related inactive entities, while blocking deletion if active entities exist.

## Current Behavior

- `purge_group_force` checks for active kernels/endpoints and fails if found
- No option to cascade delete inactive related entities
- Users must manually clean up all references before deletion

## Proposed Behavior

### Force Delete Option

```python
await group_service.delete_group(
action=DeleteGroupAction(
group_id=group_id,
force=True # Cascade soft delete to inactive references
)
)
```

### Cascade Logic

1. **Block if active entities exist**: active sessions, running kernels, active endpoints
1. **Cascade soft delete to inactive entities**:
- Inactive sessions → mark as DELETED
- Terminated kernels → mark as DELETED
- Inactive endpoints → mark as DELETED
- VFolders → mark as DELETE_PENDING (trigger async cleanup)
- Session templates → mark as DELETED

### Audit Log Integration

Record cascade deletion details in audit log:

```json
{
"action": "delete_project",
"target_id": "project-uuid",
"cascade_deleted": {
"sessions": 5,
"kernels": 12,
"vfolders": 3,
"endpoints": 1
}
}
```

## Technical Approach

1. Add `force: bool` parameter to DeleteGroupAction/DeleteScalingGroupAction
1. Implement `_collect_deletable_references()` to identify cascade targets
1. Implement `_cascade_soft_delete()` to mark all related entities
1. Update audit log monitor to capture cascade details
1. Add similar implementation for ScalingGroupRow

## Acceptance Criteria

- [ ] Force delete option available in delete API
- [ ] Active entities block deletion with clear error
- [ ] Inactive entities are cascade soft-deleted
- [ ] VFolders trigger async cleanup process
- [ ] Audit log records all cascade-deleted entities
- [ ] Works for both Projects and Resource Groups

## Dependencies

- Requires: "Add soft delete status management" story to be completed first

JIRA Issue: BA-3712

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.