feat: multi-cluster management with pool-based load balancing
- Add ClusterPool entity for grouping clusters into named pools - Support 3 deployment modes: manual cluster, pool load-balanced, default fallback - Pool strategies: least-apps (fewest deployed apps) and round-robin - Add pool CRUD API endpoints (admin) and public pool listing - Frontend deploy page: 3-mode cluster selector (Default/Manual/Pool) - Frontend app detail: shows assigned cluster and pool info - Admin pools management page with cluster selection and strategy picker - Application entity extended with poolId field
This commit is contained in:
@@ -12,6 +12,7 @@ import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { ClustersService } from './clusters.service';
|
||||
import { CreateClusterDto, UpdateClusterDto } from './dto/cluster.dto';
|
||||
import { CreateClusterPoolDto, UpdateClusterPoolDto } from './dto/cluster-pool.dto';
|
||||
import { RolesGuard } from '../common/guards/roles.guard';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
import { UserRole } from '../common/enums';
|
||||
@@ -20,44 +21,103 @@ import { UserRole } from '../common/enums';
|
||||
@ApiBearerAuth()
|
||||
@Controller('clusters')
|
||||
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
export class ClustersController {
|
||||
constructor(private readonly clustersService: ClustersService) {}
|
||||
|
||||
// ─── Public endpoints (any authenticated user) ────────────────────
|
||||
|
||||
@Get('public')
|
||||
@ApiOperation({ summary: 'List available clusters (public info, no kubeconfig)' })
|
||||
async findAllPublic() {
|
||||
return this.clustersService.findAllPublic();
|
||||
}
|
||||
|
||||
@Get('pools/public')
|
||||
@ApiOperation({ summary: 'List active cluster pools with resolved cluster names' })
|
||||
async findAllPoolsPublic() {
|
||||
return this.clustersService.findAllPoolsPublic();
|
||||
}
|
||||
|
||||
// ─── Cluster admin endpoints ──────────────────────────────────────
|
||||
|
||||
@Post()
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Register a new Kubernetes cluster (Admin only)' })
|
||||
async create(@Body() dto: CreateClusterDto) {
|
||||
return this.clustersService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'List all clusters (Admin only)' })
|
||||
async findAll() {
|
||||
return this.clustersService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Get cluster details (Admin only)' })
|
||||
async findOne(@Param('id') id: string) {
|
||||
return this.clustersService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Update cluster configuration (Admin only)' })
|
||||
async update(@Param('id') id: string, @Body() dto: UpdateClusterDto) {
|
||||
return this.clustersService.update(id, dto);
|
||||
}
|
||||
|
||||
@Post(':id/test')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Test connectivity to a registered cluster (Admin only)' })
|
||||
async testConnection(@Param('id') id: string) {
|
||||
return this.clustersService.testClusterById(id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Remove a cluster (Admin only)' })
|
||||
async delete(@Param('id') id: string) {
|
||||
await this.clustersService.delete(id);
|
||||
return { message: 'Cluster deleted' };
|
||||
}
|
||||
|
||||
// ─── Cluster Pool admin endpoints ─────────────────────────────────
|
||||
|
||||
@Post('pools')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Create a cluster pool for load balancing (Admin only)' })
|
||||
async createPool(@Body() dto: CreateClusterPoolDto) {
|
||||
return this.clustersService.createPool(dto);
|
||||
}
|
||||
|
||||
@Get('pools')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'List all cluster pools (Admin only)' })
|
||||
async findAllPools() {
|
||||
return this.clustersService.findAllPools();
|
||||
}
|
||||
|
||||
@Get('pools/:id')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Get cluster pool details (Admin only)' })
|
||||
async findOnePool(@Param('id') id: string) {
|
||||
return this.clustersService.findOnePool(id);
|
||||
}
|
||||
|
||||
@Patch('pools/:id')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Update cluster pool (Admin only)' })
|
||||
async updatePool(@Param('id') id: string, @Body() dto: UpdateClusterPoolDto) {
|
||||
return this.clustersService.updatePool(id, dto);
|
||||
}
|
||||
|
||||
@Delete('pools/:id')
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiOperation({ summary: 'Delete a cluster pool (Admin only)' })
|
||||
async deletePool(@Param('id') id: string) {
|
||||
await this.clustersService.deletePool(id);
|
||||
return { message: 'Cluster pool deleted' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user