fix(dev): route v1 code queue inside dev namespace

This commit is contained in:
Codex
2026-05-19 05:46:15 +00:00
parent fbe364f798
commit 0e827a348e
2 changed files with 88 additions and 1 deletions
@@ -410,6 +410,45 @@ function codeQueueK3sServiceIdForRequest(method: string, targetPath: string): st
return "code-queue-write";
}
function devCodeQueueDirectBaseUrl(k3sServiceId: string): string | null {
if (config().identity.environment !== "dev") return null;
const enabled = String(process.env.CODE_QUEUE_DEV_DIRECT_PROXY ?? "1").toLowerCase();
if (enabled === "0" || enabled === "false" || enabled === "no") return null;
const namespace = config().identity.namespace || process.env.UNIDESK_NAMESPACE || "unidesk-dev";
if (k3sServiceId === "code-queue-scheduler") {
return (process.env.CODE_QUEUE_DEV_SCHEDULER_URL || `http://code-queue-scheduler-dev.${namespace}.svc.cluster.local:4222`).replace(/\/+$/u, "");
}
if (k3sServiceId === "code-queue-read") {
return (process.env.CODE_QUEUE_DEV_READ_URL || `http://code-queue-read-dev.${namespace}.svc.cluster.local:4222`).replace(/\/+$/u, "");
}
if (k3sServiceId === "code-queue-write") {
return (process.env.CODE_QUEUE_DEV_WRITE_URL || `http://code-queue-write-dev.${namespace}.svc.cluster.local:4222`).replace(/\/+$/u, "");
}
return null;
}
function devCodeQueueDirectService(service: MicroserviceConfig, method: string, targetPath: string): { service: MicroserviceConfig; k3sServiceId: string } | null {
const k3sServiceId = codeQueueK3sServiceIdForRequest(method, targetPath);
const nodeBaseUrl = devCodeQueueDirectBaseUrl(k3sServiceId);
if (nodeBaseUrl === null) return null;
return {
k3sServiceId,
service: {
...service,
backend: {
...service.backend,
nodeBaseUrl,
proxyMode: "dev-k3s-direct",
},
deployment: {
...service.deployment,
mode: "unidesk-direct",
k3sServiceId,
},
},
};
}
function codeQueueMasterControlPath(method: string, targetPath: string): boolean {
const normalizedMethod = method.toUpperCase();
if (targetPath === "/" || targetPath === "/health" || targetPath === "/live" || targetPath === "/logs") return true;
@@ -1078,6 +1117,14 @@ async function fetchMicroserviceUpstreamResponse(
bodyText: string,
abortSignal?: AbortSignal,
): Promise<Response> {
if (service.id === "code-queue") {
const devDirect = devCodeQueueDirectService(service, method, targetPath);
if (devDirect !== null) {
const response = await directMicroserviceResponse(devDirect.service, method, targetPath, proxyOptions, requestHeaders, bodyText, abortSignal);
response.headers.set("x-unidesk-code-queue-target", devDirect.k3sServiceId);
return response;
}
}
if (service.id === "code-queue" && codeQueueMasterControlPath(method, targetPath)) {
const mgr = microserviceById("code-queue-mgr");
if (mgr !== null) {