Skip to content

Commit 7c78d7c

Browse files
committed
migrate podsizes
1 parent 43d5d4f commit 7c78d7c

6 files changed

Lines changed: 99 additions & 326 deletions

File tree

server/prisma/migrations/20250702090708_init/migration.sql renamed to server/prisma/migrations/20250715160026_init/migration.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ CREATE TABLE "Runpack" (
100100
CONSTRAINT "Runpack_runId_fkey" FOREIGN KEY ("runId") REFERENCES "RunpackPhase" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
101101
);
102102

103+
-- CreateTable
104+
CREATE TABLE "PodSize" (
105+
"id" TEXT NOT NULL PRIMARY KEY,
106+
"name" TEXT NOT NULL,
107+
"cpuLimit" TEXT NOT NULL,
108+
"memoryLimit" TEXT NOT NULL,
109+
"cpuRequest" TEXT NOT NULL,
110+
"memoryRequest" TEXT NOT NULL,
111+
"description" TEXT,
112+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
113+
"updatedAt" DATETIME NOT NULL
114+
);
115+
103116
-- CreateTable
104117
CREATE TABLE "RunpackPhase" (
105118
"id" TEXT NOT NULL PRIMARY KEY,

server/prisma/schema.prisma

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ model Runpack {
174174
updatedAt DateTime @updatedAt
175175
}
176176

177+
model PodSize {
178+
id String @id @default(cuid())
179+
name String
180+
cpuLimit String
181+
memoryLimit String
182+
cpuRequest String
183+
memoryRequest String
184+
description String?
185+
createdAt DateTime @default(now())
186+
updatedAt DateTime @updatedAt
187+
}
188+
177189
model RunpackPhase {
178190
id String @id @default(cuid())
179191
repository String

server/src/config/config.service.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,23 @@ export class ConfigService {
635635
}
636636

637637
public async getPodSizes() {
638-
const podSizeList: PodSize[] = [];
639-
640-
const namespace = process.env.KUBERO_NAMESPACE || 'kubero';
641-
const kuberoes = await this.kubectl.getKuberoConfig(namespace);
642-
643-
for (const podSize of kuberoes.spec.kubero.config.podSizeList) {
644-
const p = new PodSize(podSize);
645-
podSizeList.push(p);
646-
}
647-
648-
return podSizeList;
638+
// Fetch PodSizes from the database using Prisma
639+
const dbPodSizes = await this.prisma.podSize.findMany();
640+
// Map DB results to PodSize class
641+
return dbPodSizes.map((ps: any) => new PodSize({
642+
name: ps.name,
643+
description: ps.description,
644+
resources: {
645+
requests: {
646+
memory: ps.memoryRequest || '',
647+
cpu: ps.cpuLimit || '',
648+
},
649+
limits: {
650+
memory: ps.memoryLimit || '',
651+
cpu: ps.cpuLimit || '',
652+
},
653+
},
654+
}));
649655
}
650656

651657
public static getLocalauthEnabled(): boolean {

server/src/database/database.service.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PrismaClient } from '@prisma/client';
33
import * as crypto from 'crypto';
44
import * as bcrypt from 'bcrypt';
55
import { runpacks } from './runpacks.seed'; // Assuming runpacks.seed.ts exports a Runpack type
6+
import { podsizes } from './podsizes.seed'; // Assuming podsizes.seed.ts exports a PodSize type
67
import * as yaml from 'yaml'; // Import yaml for parsing runpacks
78

89
@Injectable()
@@ -35,6 +36,7 @@ export class DatabaseService {
3536
});
3637

3738
this.seedRunpacks();
39+
this.seedPodSizes();
3840
}
3941

4042
private async init() {
@@ -354,20 +356,6 @@ export class DatabaseService {
354356
}
355357

356358
private async seedRunpacks() {
357-
/*
358-
// Seed runpacks from ./runpacks.seed.yaml
359-
const fs = await import('fs');
360-
const yaml = await import('yaml');
361-
const path = require('path');
362-
const configPath = path.resolve(__dirname, '../runpacks.seed.yaml');
363-
if (!fs.existsSync(configPath)) {
364-
this.logger.warn('runpacks.seed.yaml not found, skipping runpack seed.');
365-
return;
366-
}
367-
const file = fs.readFileSync(configPath, 'utf8');
368-
const config = yaml.parse(file);
369-
*/
370-
371359
const config = yaml.parse(runpacks);
372360

373361
const buildpacks = config || [];
@@ -424,4 +412,28 @@ export class DatabaseService {
424412
}
425413
this.logger.log('Buildpacks/Runpacks seeded successfully.');
426414
}
415+
416+
private async seedPodSizes() {
417+
const config = yaml.parse(podsizes);
418+
// seed pod sizes if the table is empty
419+
const existingSizes = await this.prisma.podSize.count();
420+
if (existingSizes > 0) {
421+
this.logger.log('Pod sizes already exist. Skipping seeding.');
422+
return;
423+
}
424+
for (const size of config) {
425+
await this.prisma.podSize.create({
426+
data: {
427+
name: size.name,
428+
description: size.description,
429+
cpuLimit: size.resources.limits.cpu,
430+
memoryLimit: size.resources.limits.memory,
431+
cpuRequest: size.resources.requests.cpu,
432+
memoryRequest: size.resources.requests.memory,
433+
},
434+
});
435+
this.logger.log(`Pod size '${size.name}' seeded successfully.`);
436+
}
437+
this.logger.log('Pod sizes seeded successfully.');
438+
}
427439
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const podsizes = `
2+
- name: small
3+
description: 'Small (CPU: 0.25, Memory: 0.5Gi)'
4+
default: true
5+
resources:
6+
requests:
7+
memory: 0.5Gi
8+
cpu: 250m
9+
limits:
10+
memory: 1Gi
11+
cpu: 500m
12+
- name: medium
13+
description: 'Medium (CPU: 1, Memory: 2Gi)'
14+
resources:
15+
requests:
16+
memory: 2Gi
17+
cpu: 1000m
18+
limits:
19+
memory: 4Gi
20+
cpu: 2000m
21+
- name: large
22+
description: 'Large (CPU: 2, Memory: 4Gi)'
23+
active: false
24+
resources:
25+
requests:
26+
memory: 4Gi
27+
cpu: 2000m
28+
limits:
29+
memory: 4Gi
30+
cpu: 2000m
31+
`

0 commit comments

Comments
 (0)