fix: move sub2api runtime to PK01 host docker

This commit is contained in:
Codex
2026-06-28 14:24:08 +00:00
parent 1d07df3df1
commit d225fd1a61
18 changed files with 1088 additions and 186 deletions
+30 -9
View File
@@ -17,7 +17,7 @@ import { fingerprintSecretValues, parseEnvFile, readEnvSourceFile, readTextFile,
import { apply, plan, status } from "./actions";
import { defaultSub2ApiTargetId, readSub2ApiConfig, validateOptions } from "./config";
import { configPath, platformInfraHelp, serviceName } from "./entry";
import { resolveTarget } from "./manifest";
import { isHostDockerTarget, resolveTarget } from "./manifest";
import { validate } from "./policy";
export function sub2ApiHelpTargetSummary(): Record<string, unknown> {
@@ -27,7 +27,8 @@ export function sub2ApiHelpTargetSummary(): Record<string, unknown> {
default: sub2api.defaults.targetId,
namespace: target.namespace,
service: serviceName,
serviceDns: `${serviceName}.${target.namespace}.svc.cluster.local:8080`,
runtimeMode: target.runtimeMode,
serviceDns: isHostDockerTarget(target) ? `host-docker:127.0.0.1:${target.hostDocker?.appPort ?? 0}` : `${serviceName}.${target.namespace}.svc.cluster.local:8080`,
exposure: target.publicExposure?.enabled === true ? "yaml-controlled-public-exposure" : "k3s-cluster-internal-only",
resourceLimits: "unset-by-policy",
versionConfigPath: configPath,
@@ -145,6 +146,8 @@ function renderSub2ApiStatus(result: Record<string, unknown>): RenderedCliResult
const secret = record(summary.secret);
const egress = record(summary.egressProxy);
const networkPolicy = record(summary.networkPolicy);
const checks = record(summary.checks);
const isHostDocker = stringValue(summary.runtimeMode, "") === "host-docker";
const deployments = arrayRecords(summary.deployments)
.filter((item) => stringValue(item.name).startsWith("sub2api"))
.map((item) => [
@@ -153,6 +156,13 @@ function renderSub2ApiStatus(result: Record<string, unknown>): RenderedCliResult
`${stringValue(item.readyReplicas, "0")}/${stringValue(item.desired, "0")}`,
arrayValues(item.images).slice(0, 1).map((value) => stringValue(value)).join(",") || "-",
]);
const containers = arrayRecords(summary.containers)
.map((item) => [
stringValue(item.Names, stringValue(item.names)),
stringValue(item.State, stringValue(item.state)),
stringValue(item.Status, stringValue(item.status)),
stringValue(item.Image, stringValue(item.image)),
]);
const services = arrayRecords(summary.services)
.filter((item) => stringValue(item.name).startsWith("sub2api"))
.map((item) => [
@@ -165,18 +175,29 @@ function renderSub2ApiStatus(result: Record<string, unknown>): RenderedCliResult
...table(["TARGET", "ROUTE", "NAMESPACE", "STATUS"], [[stringValue(summary.target, stringValue(target.id)), stringValue(summary.route, stringValue(target.route)), stringValue(summary.namespace, stringValue(target.namespace)), stringValue(summary.status, result.ok === false ? "failed" : "ok")]]),
"",
"WORKLOADS",
...(deployments.length === 0 ? ["-"] : table(["NAME", "READY", "REPLICAS", "IMAGE"], deployments)),
...(deployments.length > 0
? table(["NAME", "READY", "REPLICAS", "IMAGE"], deployments)
: containers.length > 0
? table(["NAME", "STATE", "STATUS", "IMAGE"], containers)
: ["-"]),
"",
"SERVICES",
...(services.length === 0 ? ["-"] : table(["NAME", "TYPE", "PORTS"], services)),
"",
"CHECKS",
...table(["CHECK", "VALUE", "DETAIL"], [
["namespace", boolText(summary.namespaceExists), stringValue(summary.namespace)],
["secret", boolText(secret.ready), `name=${stringValue(secret.name, "-")} missing=${arrayValues(secret.missingKeys).length}`],
["egressProxy", boolText(egress.aligned), `enabled=${boolText(egress.enabled)} valuesPrinted=false`],
["networkPolicy", boolText(networkPolicy.ok), `required=${stringValue(networkPolicy.requiredName, "-")}`],
]),
...table(["CHECK", "VALUE", "DETAIL"], isHostDocker
? [
["localHealth", boolText(record(checks.localHealth).exitCode === 0), "http://127.0.0.1 health"],
["caddy", boolText(record(checks.caddyService).exitCode === 0), "PK01 Caddy service"],
["egressProxy", boolText(egress.enabled === false), "not deployed"],
["sentinel", boolText(record(summary.sentinel).enabled === false), "not deployed"],
]
: [
["namespace", boolText(summary.namespaceExists), stringValue(summary.namespace)],
["secret", boolText(secret.ready), `name=${stringValue(secret.name, "-")} missing=${arrayValues(secret.missingKeys).length}`],
["egressProxy", boolText(egress.aligned), `enabled=${boolText(egress.enabled)} valuesPrinted=false`],
["networkPolicy", boolText(networkPolicy.ok), `required=${stringValue(networkPolicy.requiredName, "-")}`],
]),
"",
"NEXT",
` validate: bun scripts/cli.ts platform-infra sub2api validate --target ${stringValue(summary.target, stringValue(target.id))}`,