diff --git a/scripts/src/hwlab-node/web-probe.ts b/scripts/src/hwlab-node/web-probe.ts index e4fc4794..e3fcc159 100644 --- a/scripts/src/hwlab-node/web-probe.ts +++ b/scripts/src/hwlab-node/web-probe.ts @@ -1554,45 +1554,54 @@ function nodeRuntimeCodeAgentManagerTarget(managerUrl: string, fallbackNamespace } function nodeRuntimeCodeAgentCloudApiEnvStatus(spec: HwlabRuntimeLaneSpec, runtime: NonNullable): Record { - const deployment = runNodeK3sArgs(spec, ["kubectl", "-n", spec.runtimeNamespace, "get", "deployment", "hwlab-cloud-api", "-o", "json"], 60); - if (deployment.exitCode !== 0) { + const envProbe = runNodeK3sArgs(spec, [ + "kubectl", + "-n", + spec.runtimeNamespace, + "get", + "deployment", + "hwlab-cloud-api", + "-o", + 'jsonpath={range .spec.template.spec.containers[?(@.name=="hwlab-cloud-api")].env[*]}{.name}{"\\t"}{.value}{"\\t"}{.valueFrom.secretKeyRef.name}{"\\t"}{.valueFrom.secretKeyRef.key}{"\\n"}{end}', + ], 60); + if (envProbe.exitCode !== 0) { return { ready: false, deploymentExists: false, mismatches: [{ name: "hwlab-cloud-api", reason: "deployment-missing" }], - result: compactCodeAgentDeploymentProbeResult(deployment), + result: compactCodeAgentDeploymentProbeResult(envProbe), valuesPrinted: false, }; } - let parsed: unknown; - try { - parsed = JSON.parse(deployment.stdout) as unknown; - } catch (error) { + const envByName = parseCodeAgentEnvProbe(envProbe.stdout); + if (envByName.size === 0) { return { ready: false, deploymentExists: true, - mismatches: [{ name: "hwlab-cloud-api", reason: "deployment-json-invalid", message: error instanceof Error ? error.message : String(error) }], - result: compactCodeAgentDeploymentProbeResult(deployment), + deploymentName: "hwlab-cloud-api", + containerName: "hwlab-cloud-api", + mismatches: [{ name: "hwlab-cloud-api", reason: "container-env-not-found" }], + result: compactCodeAgentDeploymentProbeResult(envProbe), valuesPrinted: false, }; } - const deploy = record(parsed); - const specRecord = record(record(record(deploy.spec).template).spec); - const containers = Array.isArray(specRecord.containers) ? specRecord.containers.map(record) : []; - const container = containers.find((item) => item.name === "hwlab-cloud-api") ?? containers[0]; - const env = Array.isArray(container?.env) ? container.env.map(record) : []; - const envByName = new Map(env.map((item) => [String(item.name || ""), item])); const mismatches: Array> = []; const expectValue = (name: string, expected: string): void => { const item = envByName.get(name); - const value = typeof item?.value === "string" ? item.value : null; - if (value !== expected) mismatches.push({ name, expected, value, kind: "value" }); + if (item === undefined) { + mismatches.push({ name, expected, present: false, kind: "value" }); + return; + } + if (item.value !== expected) mismatches.push({ name, expected, value: item.value, present: true, kind: "value" }); }; const expectSecret = (name: string, expectedSecret: string, expectedKey: string): void => { const item = envByName.get(name); - const secretRef = record(record(item?.valueFrom).secretKeyRef); - if (secretRef.name !== expectedSecret || secretRef.key !== expectedKey) { - mismatches.push({ name, expectedSecret, expectedKey, secret: secretRef.name ?? null, key: secretRef.key ?? null, kind: "secretKeyRef" }); + if (item === undefined) { + mismatches.push({ name, expectedSecret, expectedKey, present: false, kind: "secretKeyRef" }); + return; + } + if (item.secretName !== expectedSecret || item.secretKey !== expectedKey) { + mismatches.push({ name, expectedSecret, expectedKey, secret: item.secretName, key: item.secretKey, present: true, kind: "secretKeyRef" }); } }; expectValue("HWLAB_CODE_AGENT_ADAPTER", runtime.adapter); @@ -1616,14 +1625,37 @@ function nodeRuntimeCodeAgentCloudApiEnvStatus(spec: HwlabRuntimeLaneSpec, runti ready: mismatches.length === 0, deploymentExists: true, deploymentName: "hwlab-cloud-api", - containerName: container?.name ?? null, + containerName: "hwlab-cloud-api", checkedEnvCount: kafkaShadowProducer === undefined ? 9 : 14, + envCount: envByName.size, mismatches, - result: compactCodeAgentDeploymentProbeResult(deployment), + result: compactCodeAgentDeploymentProbeResult(envProbe), valuesPrinted: false, }; } +type CodeAgentEnvProbeRow = { + value: string | null; + secretName: string | null; + secretKey: string | null; +}; + +function parseCodeAgentEnvProbe(stdout: string): Map { + const rows = new Map(); + for (const line of stdout.split(/\r?\n/u)) { + const trimmed = line.trimEnd(); + if (trimmed.length === 0) continue; + const [name = "", value = "", secretName = "", secretKey = ""] = trimmed.split("\t"); + if (name.length === 0) continue; + rows.set(name, { + value: value.length > 0 ? value : null, + secretName: secretName.length > 0 ? secretName : null, + secretKey: secretKey.length > 0 ? secretKey : null, + }); + } + return rows; +} + function compactCodeAgentDeploymentProbeResult(result: CommandResult): Record { return { exitCode: result.exitCode,