fix(apps): always attempt K8s cleanup on delete, cluster service fixes

- Delete endpoint no longer requires clusterId && latestImageTag
- Clusters: getDefault fallback logic, reassign apps on delete
- Unit tests for cluster default/delete logic
This commit is contained in:
keyhan
2026-04-22 16:44:43 +03:30
parent 8ca787d46e
commit 5f6eccc483
7 changed files with 423 additions and 38 deletions
@@ -62,7 +62,7 @@ export class ApplicationsController {
}
@Post(':id/db-upload')
@ApiOperation({ summary: 'Upload and restore a SQL dump into the application database' })
@ApiOperation({ summary: 'Upload a SQL dump file for later restore during deployment' })
@ApiConsumes('multipart/form-data')
@UseInterceptors(FileInterceptor('file', {
limits: { fileSize: 500 * 1024 * 1024 }, // 500MB for DB dumps
@@ -84,12 +84,13 @@ export class ApplicationsController {
}
this.logger.log(`DB dump upload for ${app.name}${(file.size / 1024).toFixed(1)} KB`);
const result = await this.kubernetesService.restoreDatabaseDump(app, file.buffer);
// Save to disk (restore happens after deploy when namespace exists)
await this.applicationsService.uploadDbDump(id, isStaff ? app.userId : req.user.id, file);
return {
success: result.success,
message: result.success ? 'Database restored successfully' : 'Database restore failed',
logs: result.logs,
success: true,
message: 'Database dump uploaded. It will be restored automatically after deployment.',
};
}
@@ -225,12 +226,10 @@ export class ApplicationsController {
// 1. Get the app first
const app = await this.applicationsService.findOne(id, isStaff ? undefined : req.user.id);
// 2. Delete K8s resources (deployment, service, ingress, db, secrets)
// 2. Delete K8s resources (deployment, service, ingress, db, secrets, PVCs)
try {
if (app.clusterId && app.latestImageTag) {
await this.kubernetesService.deleteApplication(app);
this.logger.log(`Deleted K8s resources for ${app.name}`);
}
await this.kubernetesService.deleteApplication(app);
this.logger.log(`Deleted K8s resources for ${app.name}`);
} catch (e: any) {
this.logger.warn(`K8s cleanup failed for ${app.name}: ${e.message}`);
}