From e37b4dc79a6d6529192106beb2e91221a0778228 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 15 Jul 2026 03:34:03 +0200 Subject: [PATCH] =?UTF-8?q?fix(pikaoa):=20=E6=B3=A8=E5=85=A5=20Web=20?= =?UTF-8?q?=E5=90=8C=E6=BA=90=20API=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/fixtures/pikaoa-test-target.yaml | 2 ++ config/pikaoa.yaml | 2 ++ scripts/src/pikaoa-test-target-async.test.ts | 1 + scripts/src/pikaoa-test-target.ts | 21 +++++++++++++++++--- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/config/fixtures/pikaoa-test-target.yaml b/config/fixtures/pikaoa-test-target.yaml index bb537c7c..98218fcd 100644 --- a/config/fixtures/pikaoa-test-target.yaml +++ b/config/fixtures/pikaoa-test-target.yaml @@ -47,9 +47,11 @@ testRuntime: targetKey: DATABASE_URL runtime: secretName: pikaoa-test-runtime + apiServiceName: pikaoa-api apiPort: 8080 workerMetricsPort: 8081 webPort: 8080 + webApiUpstreamEnv: PIKAOA_API_UPSTREAM attachment: storageRoot: /var/lib/pikaoa/attachments maxBytes: 104857600 diff --git a/config/pikaoa.yaml b/config/pikaoa.yaml index 88ac9b8c..8e88b6b2 100644 --- a/config/pikaoa.yaml +++ b/config/pikaoa.yaml @@ -66,9 +66,11 @@ testRuntime: targetKey: DATABASE_URL runtime: secretName: pikaoa-test-runtime + apiServiceName: pikaoa-api apiPort: 8080 workerMetricsPort: 8081 webPort: 8080 + webApiUpstreamEnv: PIKAOA_API_UPSTREAM attachment: storageRoot: /var/lib/pikaoa/attachments maxBytes: 104857600 diff --git a/scripts/src/pikaoa-test-target-async.test.ts b/scripts/src/pikaoa-test-target-async.test.ts index 3749882a..4f5b0a76 100644 --- a/scripts/src/pikaoa-test-target-async.test.ts +++ b/scripts/src/pikaoa-test-target-async.test.ts @@ -171,6 +171,7 @@ exit 64 assert.equal(objects.some((object) => object.kind === "Deployment" && object.name === "pikaoa-web"), true); assert.equal(objects.find((object) => object.kind === "Deployment" && object.name === "pikaoa-api")?.podFsGroup, 65532); assert.deepEqual(plan.exposure, { serviceType: "NodePort", serviceName: "pikaoa-web", hostIP: "192.0.2.10", port: 32080 }); + assert.deepEqual(plan.webApiUpstream, { envName: "PIKAOA_API_UPSTREAM", value: "http://pikaoa-api:8080", scope: "same-namespace" }); const missing = await projection("status", "runtime", false, "api"); assert.equal((missing.status as Record).code, "start-not-found"); diff --git a/scripts/src/pikaoa-test-target.ts b/scripts/src/pikaoa-test-target.ts index 79dea2ff..87a38dce 100644 --- a/scripts/src/pikaoa-test-target.ts +++ b/scripts/src/pikaoa-test-target.ts @@ -69,9 +69,11 @@ interface TestTargetSpec { }; runtime: { secretName: string; + apiServiceName: string; apiPort: number; workerMetricsPort: number; webPort: number; + webApiUpstreamEnv: string; attachment: { storageRoot: string; maxBytes: number; @@ -343,9 +345,11 @@ function parseTarget(id: string, root: Record, configLabel: str }, runtime: { secretName: kubernetesName(nonEmpty(runtime.secretName, `${path}.runtime.secretName`), `${path}.runtime.secretName`, 63), + apiServiceName: kubernetesName(nonEmpty(runtime.apiServiceName, `${path}.runtime.apiServiceName`), `${path}.runtime.apiServiceName`, 63), apiPort: positiveInteger(runtime.apiPort, `${path}.runtime.apiPort`, 65_535), workerMetricsPort: positiveInteger(runtime.workerMetricsPort, `${path}.runtime.workerMetricsPort`, 65_535), webPort: positiveInteger(runtime.webPort, `${path}.runtime.webPort`, 65_535), + webApiUpstreamEnv: envName(runtime.webApiUpstreamEnv, `${path}.runtime.webApiUpstreamEnv`), attachment: { storageRoot: absolutePath(attachment.storageRoot, `${path}.runtime.attachment.storageRoot`), maxBytes: positiveInteger(attachment.maxBytes, `${path}.runtime.attachment.maxBytes`, Number.MAX_SAFE_INTEGER), @@ -502,6 +506,7 @@ function renderedPlan(selection: Selection, context: RenderContext): Record object.kind === "Job"); const workload = (name: string): Record[] => manifest.filter((object) => { if (object.kind !== "Deployment" && object.kind !== "Service") return false; - return optionalRecord(object.metadata, "metadata")?.name === `pikaoa-${name}`; + const metadata = optionalRecord(object.metadata, "metadata") ?? {}; + const labels = optionalRecord(metadata.labels, "metadata.labels") ?? {}; + return labels["app.kubernetes.io/component"] === name; }); const foundation = manifest.filter((object) => object.kind !== "Job" && object.kind !== "Deployment" && object.kind !== "Service"); const encode = (objects: Record[]): string => Buffer.from(objects.map((object) => JSON.stringify(object)).join("\n---\n"), "utf8").toString("base64"); @@ -1582,6 +1591,12 @@ function httpPath(value: unknown, path: string): string { return result; } +function envName(value: unknown, path: string): string { + const result = nonEmpty(value, path); + if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(result)) throw new Error(`${path} 必须是合法环境变量名`); + return result; +} + function ipv4Address(value: unknown, path: string): string { const result = nonEmpty(value, path); const octets = result.split(".");