mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 18:59:25 +00:00
♻️ refactor: remove stale code and comments
This commit is contained in:
@@ -7,14 +7,12 @@ import { ReverseProxyService } from "./services/reverse-proxy.service";
|
|||||||
import { ServerService } from "./services/server.service";
|
import { ServerService } from "./services/server.service";
|
||||||
import { UserService } from "./services/user.service";
|
import { UserService } from "./services/user.service";
|
||||||
|
|
||||||
// Infrastructure layer
|
|
||||||
const userRepo = new PrismaUserRepository();
|
const userRepo = new PrismaUserRepository();
|
||||||
const serverRepo = new PrismaServerRepository();
|
const serverRepo = new PrismaServerRepository();
|
||||||
const reverseProxyRepo = new PrismaReverseProxyRepository();
|
const reverseProxyRepo = new PrismaReverseProxyRepository();
|
||||||
const webSocketService = new WebSocketService();
|
const webSocketService = new WebSocketService();
|
||||||
const k8sService = new K8sService();
|
const k8sService = new K8sService();
|
||||||
|
|
||||||
// Application layer
|
|
||||||
export const userService = new UserService(userRepo);
|
export const userService = new UserService(userRepo);
|
||||||
export const serverService = new ServerService(serverRepo, k8sService);
|
export const serverService = new ServerService(serverRepo, k8sService);
|
||||||
export const reverseProxyService = new ReverseProxyService(reverseProxyRepo);
|
export const reverseProxyService = new ReverseProxyService(reverseProxyRepo);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import type * as k8s from "@kubernetes/client-node";
|
|||||||
import type { CustomResourceSummary } from "@minikura/api";
|
import type { CustomResourceSummary } from "@minikura/api";
|
||||||
|
|
||||||
export interface IK8sService {
|
export interface IK8sService {
|
||||||
// Initialization
|
|
||||||
isInitialized(): boolean;
|
isInitialized(): boolean;
|
||||||
getConnectionInfo(): {
|
getConnectionInfo(): {
|
||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
@@ -11,7 +10,6 @@ export interface IK8sService {
|
|||||||
namespace: string;
|
namespace: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pods
|
|
||||||
getPods(): Promise<any[]>;
|
getPods(): Promise<any[]>;
|
||||||
getPodsByLabel(labelSelector: string): Promise<any[]>;
|
getPodsByLabel(labelSelector: string): Promise<any[]>;
|
||||||
getPodInfo(podName: string): Promise<any>;
|
getPodInfo(podName: string): Promise<any>;
|
||||||
@@ -26,20 +24,16 @@ export interface IK8sService {
|
|||||||
): Promise<string>;
|
): Promise<string>;
|
||||||
getPodMetrics(namespace?: string): Promise<any>;
|
getPodMetrics(namespace?: string): Promise<any>;
|
||||||
|
|
||||||
// Workloads
|
|
||||||
getDeployments(): Promise<any[]>;
|
getDeployments(): Promise<any[]>;
|
||||||
getStatefulSets(): Promise<any[]>;
|
getStatefulSets(): Promise<any[]>;
|
||||||
|
|
||||||
// Network
|
|
||||||
getServices(): Promise<any[]>;
|
getServices(): Promise<any[]>;
|
||||||
getIngresses(): Promise<any[]>;
|
getIngresses(): Promise<any[]>;
|
||||||
getServiceInfo(serviceName: string): Promise<any>;
|
getServiceInfo(serviceName: string): Promise<any>;
|
||||||
getServerConnectionInfo(serviceName: string): Promise<any>;
|
getServerConnectionInfo(serviceName: string): Promise<any>;
|
||||||
|
|
||||||
// Configuration
|
|
||||||
getConfigMaps(): Promise<any[]>;
|
getConfigMaps(): Promise<any[]>;
|
||||||
|
|
||||||
// Custom Resources
|
|
||||||
getCustomResources(
|
getCustomResources(
|
||||||
group: string,
|
group: string,
|
||||||
version: string,
|
version: string,
|
||||||
@@ -48,11 +42,9 @@ export interface IK8sService {
|
|||||||
getMinecraftServers(): Promise<CustomResourceSummary[]>;
|
getMinecraftServers(): Promise<CustomResourceSummary[]>;
|
||||||
getReverseProxyServers(): Promise<CustomResourceSummary[]>;
|
getReverseProxyServers(): Promise<CustomResourceSummary[]>;
|
||||||
|
|
||||||
// Cluster
|
|
||||||
getNodes(): Promise<any[]>;
|
getNodes(): Promise<any[]>;
|
||||||
getNodeMetrics(): Promise<any>;
|
getNodeMetrics(): Promise<any>;
|
||||||
|
|
||||||
// Low-level access
|
|
||||||
getKubeConfig(): k8s.KubeConfig;
|
getKubeConfig(): k8s.KubeConfig;
|
||||||
getCoreApi(): k8s.CoreV1Api;
|
getCoreApi(): k8s.CoreV1Api;
|
||||||
getNamespace(): string;
|
getNamespace(): string;
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ export const DEFAULT_PORTS = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const DEFAULT_MEMORY = {
|
export const DEFAULT_MEMORY = {
|
||||||
SERVER: 2048, // MB
|
SERVER: 2048,
|
||||||
REVERSE_PROXY: 512, // MB
|
REVERSE_PROXY: 512,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const DEFAULT_MEMORY_REQUEST = {
|
export const DEFAULT_MEMORY_REQUEST = {
|
||||||
SERVER: 1024, // MB
|
SERVER: 1024,
|
||||||
REVERSE_PROXY: 512, // MB
|
REVERSE_PROXY: 512,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const DEFAULT_CPU = {
|
export const DEFAULT_CPU = {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { dotenvLoad } from "dotenv-mono";
|
|||||||
|
|
||||||
dotenvLoad();
|
dotenvLoad();
|
||||||
|
|
||||||
import { Elysia } from "elysia";
|
|
||||||
import { node } from "@elysiajs/node";
|
import { node } from "@elysiajs/node";
|
||||||
|
import { Elysia } from "elysia";
|
||||||
import { logger } from "./infrastructure/logger";
|
import { logger } from "./infrastructure/logger";
|
||||||
import { auth } from "./middleware/auth";
|
import { auth } from "./middleware/auth";
|
||||||
import { authPlugin } from "./middleware/auth-plugin";
|
import { authPlugin } from "./middleware/auth-plugin";
|
||||||
@@ -15,7 +15,6 @@ import { serverRoutes } from "./routes/servers";
|
|||||||
import { terminalRoutes } from "./routes/terminal";
|
import { terminalRoutes } from "./routes/terminal";
|
||||||
import { userRoutes } from "./routes/users";
|
import { userRoutes } from "./routes/users";
|
||||||
|
|
||||||
// Register event handlers
|
|
||||||
import "./infrastructure/event-handlers";
|
import "./infrastructure/event-handlers";
|
||||||
|
|
||||||
const app = new Elysia({ adapter: node() })
|
const app = new Elysia({ adapter: node() })
|
||||||
@@ -33,8 +32,7 @@ const app = new Elysia({ adapter: node() })
|
|||||||
.use(authPlugin)
|
.use(authPlugin)
|
||||||
.group("/api", (app) =>
|
.group("/api", (app) =>
|
||||||
app.use(userRoutes).use(serverRoutes).use(reverseProxyRoutes).use(k8sRoutes).use(terminalRoutes)
|
app.use(userRoutes).use(serverRoutes).use(reverseProxyRoutes).use(k8sRoutes).use(terminalRoutes)
|
||||||
)
|
);
|
||||||
.get("/health", () => ({ status: "ok" }));
|
|
||||||
|
|
||||||
export type App = typeof app;
|
export type App = typeof app;
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ export class PrismaReverseProxyRepository implements ReverseProxyRepository {
|
|||||||
throw new NotFoundError("ReverseProxyServer", id);
|
throw new NotFoundError("ReverseProxyServer", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update proxy fields
|
|
||||||
const updated = await prisma.reverseProxyServer.update({
|
const updated = await prisma.reverseProxyServer.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -107,12 +107,10 @@ export class PrismaServerRepository implements ServerRepository {
|
|||||||
throw new NotFoundError("Server", id);
|
throw new NotFoundError("Server", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle env variables separately
|
|
||||||
if (input.env_variables !== undefined) {
|
if (input.env_variables !== undefined) {
|
||||||
await this.replaceEnvVariables(id, input.env_variables);
|
await this.replaceEnvVariables(id, input.env_variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update server fields
|
|
||||||
const updated = await prisma.server.update({
|
const updated = await prisma.server.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export const k8sRoutes = new Elysia({ prefix: "/k8s" })
|
|||||||
};
|
};
|
||||||
const logs = await k8sService.getPodLogs(params.podName, options);
|
const logs = await k8sService.getPodLogs(params.podName, options);
|
||||||
|
|
||||||
// Return as plain text
|
|
||||||
const headers = (set.headers ?? {}) as Record<string, string>;
|
const headers = (set.headers ?? {}) as Record<string, string>;
|
||||||
headers["content-type"] = "text/plain";
|
headers["content-type"] = "text/plain";
|
||||||
set.headers = headers;
|
set.headers = headers;
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ import type { IK8sService } from "../application/interfaces/k8s.service.interfac
|
|||||||
import { logger } from "../infrastructure/logger";
|
import { logger } from "../infrastructure/logger";
|
||||||
import { ClusterOperations } from "./kubernetes/operations/cluster.operations";
|
import { ClusterOperations } from "./kubernetes/operations/cluster.operations";
|
||||||
import { CustomResourceOperations } from "./kubernetes/operations/custom-resource.operations";
|
import { CustomResourceOperations } from "./kubernetes/operations/custom-resource.operations";
|
||||||
import { NetworkOperations } from "./kubernetes/operations/network.operations";
|
|
||||||
import { PodOperations } from "./kubernetes/operations/pod.operations";
|
import { PodOperations } from "./kubernetes/operations/pod.operations";
|
||||||
import { WorkloadOperations } from "./kubernetes/operations/workload.operations";
|
|
||||||
import { K8sResources } from "./kubernetes/resources";
|
import { K8sResources } from "./kubernetes/resources";
|
||||||
|
|
||||||
const CUSTOM_RESOURCE_VERSION = "v1alpha1";
|
const CUSTOM_RESOURCE_VERSION = "v1alpha1";
|
||||||
@@ -56,8 +54,6 @@ export class K8sService implements IK8sService {
|
|||||||
|
|
||||||
private initializeOperations(): void {
|
private initializeOperations(): void {
|
||||||
this.podOps = new PodOperations(this.coreApi, this.namespace);
|
this.podOps = new PodOperations(this.coreApi, this.namespace);
|
||||||
this.workloadOps = new WorkloadOperations(this.appsApi, this.namespace);
|
|
||||||
this.networkOps = new NetworkOperations(this.coreApi, this.networkingApi, this.namespace);
|
|
||||||
this.clusterOps = new ClusterOperations(this.coreApi, this.customObjectsApi, this.namespace);
|
this.clusterOps = new ClusterOperations(this.coreApi, this.customObjectsApi, this.namespace);
|
||||||
this.customResourceOps = new CustomResourceOperations(this.customObjectsApi, this.namespace);
|
this.customResourceOps = new CustomResourceOperations(this.customObjectsApi, this.namespace);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export class WebSocketService implements IWebSocketService {
|
|||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send to all connected clients, removing any that fail
|
|
||||||
let failedClients = 0;
|
let failedClients = 0;
|
||||||
this.clients.forEach((client) => {
|
this.clients.forEach((client) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ datasource db {
|
|||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Better Auth Models
|
|
||||||
model User {
|
model User {
|
||||||
id String @id
|
id String @id
|
||||||
name String
|
name String
|
||||||
@@ -68,7 +67,6 @@ model Verification {
|
|||||||
@@map("verification")
|
@@map("verification")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Application Models
|
|
||||||
enum ServerType {
|
enum ServerType {
|
||||||
STATEFUL
|
STATEFUL
|
||||||
STATELESS
|
STATELESS
|
||||||
@@ -141,16 +139,13 @@ model Server {
|
|||||||
env_variables CustomEnvironmentVariable[] @relation("ServerEnvVars")
|
env_variables CustomEnvironmentVariable[] @relation("ServerEnvVars")
|
||||||
api_key String @unique
|
api_key String @unique
|
||||||
|
|
||||||
// Minecraft specific configurations
|
|
||||||
jar_type MinecraftServerJarType @default(VANILLA)
|
jar_type MinecraftServerJarType @default(VANILLA)
|
||||||
minecraft_version String @default("LATEST") // e.g., "LATEST", "1.20.4", "SNAPSHOT"
|
minecraft_version String @default("LATEST") // e.g., "LATEST", "1.20.4", "SNAPSHOT"
|
||||||
|
|
||||||
// JVM Options
|
|
||||||
jvm_opts String? // Custom JVM options
|
jvm_opts String? // Custom JVM options
|
||||||
use_aikar_flags Boolean @default(false)
|
use_aikar_flags Boolean @default(false)
|
||||||
use_meowice_flags Boolean @default(false)
|
use_meowice_flags Boolean @default(false)
|
||||||
|
|
||||||
// Server Properties (common ones)
|
|
||||||
difficulty ServerDifficulty @default(EASY)
|
difficulty ServerDifficulty @default(EASY)
|
||||||
game_mode GameMode @default(SURVIVAL)
|
game_mode GameMode @default(SURVIVAL)
|
||||||
max_players Int @default(20)
|
max_players Int @default(20)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export const NAMESPACE = process.env.KUBERNETES_NAMESPACE || "minikura";
|
|||||||
|
|
||||||
export const ENABLE_CRD_REFLECTION = process.env.ENABLE_CRD_REFLECTION === "true";
|
export const ENABLE_CRD_REFLECTION = process.env.ENABLE_CRD_REFLECTION === "true";
|
||||||
|
|
||||||
// Resource types
|
|
||||||
export const RESOURCE_TYPES = {
|
export const RESOURCE_TYPES = {
|
||||||
MINECRAFT_SERVER: {
|
MINECRAFT_SERVER: {
|
||||||
kind: "MinecraftServer",
|
kind: "MinecraftServer",
|
||||||
@@ -26,8 +25,7 @@ export const RESOURCE_TYPES = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Polling intervals (in milliseconds)
|
export const SYNC_INTERVAL = 30 * 1000;
|
||||||
export const SYNC_INTERVAL = 30 * 1000; // 30 seconds
|
|
||||||
|
|
||||||
export const IMAGES = {
|
export const IMAGES = {
|
||||||
MINECRAFT: "itzg/minecraft-server",
|
MINECRAFT: "itzg/minecraft-server",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ export const RESOURCE_DEFAULTS = {
|
|||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
// 80% of container memory goes to JVM heap; 20% headroom
|
|
||||||
export const JAVA_MEMORY_FACTOR = 0.8;
|
export const JAVA_MEMORY_FACTOR = 0.8;
|
||||||
|
|
||||||
export const DEFAULT_SERVER_MEMORY = "1G";
|
export const DEFAULT_SERVER_MEMORY = "1G";
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import type {
|
|||||||
Server as PrismaServer,
|
Server as PrismaServer,
|
||||||
} from "@minikura/db";
|
} from "@minikura/db";
|
||||||
|
|
||||||
// Base interface
|
|
||||||
export interface CustomResource {
|
export interface CustomResource {
|
||||||
apiVersion: string;
|
apiVersion: string;
|
||||||
kind: string;
|
kind: string;
|
||||||
@@ -45,8 +44,6 @@ export interface MinecraftServerCRD extends CustomResource {
|
|||||||
status?: MinecraftServerStatus;
|
status?: MinecraftServerStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reverse Proxy Types
|
|
||||||
|
|
||||||
export type ReverseProxyConfig = Pick<
|
export type ReverseProxyConfig = Pick<
|
||||||
PrismaReverseProxyServer,
|
PrismaReverseProxyServer,
|
||||||
| "id"
|
| "id"
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ export function getErrorMessage(error: unknown): string {
|
|||||||
}
|
}
|
||||||
return String(error);
|
return String(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns age string like "3d", "12h", "5m" */
|
|
||||||
export function getAge(timestamp: Date | string | undefined): string {
|
export function getAge(timestamp: Date | string | undefined): string {
|
||||||
if (!timestamp) return "unknown";
|
if (!timestamp) return "unknown";
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
import pino from "pino";
|
import pino from "pino";
|
||||||
|
|
||||||
export function createLogger(component: string): pino.Logger;
|
export function createLogger(component: string): pino.Logger;
|
||||||
|
export function createLogger(context: Record<string, string | number>): pino.Logger;
|
||||||
export function createLogger(
|
export function createLogger(
|
||||||
context: Record<string, string | number>,
|
componentOrContext: string | Record<string, string | number>
|
||||||
): pino.Logger;
|
|
||||||
export function createLogger(
|
|
||||||
componentOrContext: string | Record<string, string | number>,
|
|
||||||
): pino.Logger {
|
): pino.Logger {
|
||||||
const isString = typeof componentOrContext === "string";
|
const isString = typeof componentOrContext === "string";
|
||||||
const baseContext = isString
|
const baseContext = isString ? { component: componentOrContext } : componentOrContext;
|
||||||
? { component: componentOrContext }
|
|
||||||
: componentOrContext;
|
|
||||||
|
|
||||||
return pino({
|
return pino({
|
||||||
level: process.env.LOG_LEVEL || "info",
|
level: process.env.LOG_LEVEL || "info",
|
||||||
|
|||||||
Reference in New Issue
Block a user