deploy: configure NC01 HWLAB monitor exposure

This commit is contained in:
root
2026-07-08 05:34:11 +02:00
parent 5dfb78f000
commit a328aa909e
41 changed files with 2522 additions and 110 deletions
+41 -7
View File
@@ -42,7 +42,7 @@ interface HostProxyServer {
interface HostProxySource {
id: string;
sourceType: "benchmark-validated-master-shadowsocks";
sourceType: "benchmark-validated-master-shadowsocks" | "vpn-server-shadowsocks";
serverRef: string;
benchmarkRef: string;
implementationRef: string;
@@ -167,7 +167,7 @@ function readHostProxyConfig(): HostProxyConfig {
const server = parseServer(record(root.server, `${configPath}.server`), `${configPath}.server`);
const sources = Object.fromEntries(Object.entries(record(root.sources, `${configPath}.sources`)).map(([id, value]) => {
const source = parseSource(id, record(value, `${configPath}.sources.${id}`));
if (source.serverRef !== `server.${server.id}`) throw new Error(`${configPath}.sources.${id}.serverRef must be server.${server.id}`);
if (sourceUsesManagedServer(source) && source.serverRef !== `server.${server.id}`) throw new Error(`${configPath}.sources.${id}.serverRef must be server.${server.id}`);
return [id, source];
}));
const targets: Record<string, HostProxyTarget> = {};
@@ -232,7 +232,7 @@ function parseServer(raw: Record<string, unknown>, label: string): HostProxyServ
}
function parseSource(id: string, raw: Record<string, unknown>): HostProxySource {
const sourceType = enumField(raw, "sourceType", `${configPath}.sources.${id}`, ["benchmark-validated-master-shadowsocks"] as const);
const sourceType = enumField(raw, "sourceType", `${configPath}.sources.${id}`, ["benchmark-validated-master-shadowsocks", "vpn-server-shadowsocks"] as const);
const sourceConfigRef = stringField(raw, "sourceConfigRef", `${configPath}.sources.${id}`);
const resolved = resolveEgressProxySourceRef(sourceConfigRef, `${configPath}.sources.${id}.sourceConfigRef`);
if (resolved.sourceType !== "master-shadowsocks" || resolved.masterShadowsocks === null) {
@@ -389,7 +389,7 @@ function plan(server: HostProxyServer, target: HostProxyTarget): Record<string,
function apply(server: HostProxyServer, target: HostProxyTarget): Record<string, unknown> {
const material = proxySecretMaterial(server, target.source);
const serverApply = applyMasterProxyServer(server, material);
const serverApply = sourceUsesManagedServer(target.source) ? applyMasterProxyServer(server, material) : skippedMasterProxyServer(target.source, "apply");
const artifact = prepareClientArtifact(target.source.client);
const remotePrepare = runTrans(target.route, remotePrepareScript(target.source.client), 30);
const remoteArchive = remotePrepare.exitCode === 0
@@ -429,7 +429,7 @@ function apply(server: HostProxyServer, target: HostProxyTarget): Record<string,
}
function status(server: HostProxyServer, target: HostProxyTarget): Record<string, unknown> {
const serverStatus = masterProxyServerStatus(server);
const serverStatus = sourceUsesManagedServer(target.source) ? masterProxyServerStatus(server) : skippedMasterProxyServer(target.source, "status");
const result = runTrans(target.route, remoteStatusScript(target), 45);
const parsed = parseJson(result.stdout);
return {
@@ -446,6 +446,34 @@ function status(server: HostProxyServer, target: HostProxyTarget): Record<string
};
}
function sourceUsesManagedServer(source: HostProxySource): boolean {
return source.sourceType === "benchmark-validated-master-shadowsocks";
}
function skippedMasterProxyServer(source: HostProxySource, mode: "apply" | "status"): Record<string, unknown> {
return {
ok: true,
id: source.id,
sourceType: source.sourceType,
enabled: false,
mode,
skipped: true,
reason: `source ${source.id} uses externally managed ${source.sourceType} server`,
benchmarkRef: source.benchmarkRef,
implementationRef: source.implementationRef,
sourceConfigRef: source.sourceConfigRef,
sourceFingerprint: source.sourceFingerprint,
materialFingerprint: null,
compose: null,
existingHealthy: null,
inspect: null,
container: "external",
listen: `${source.masterShadowsocks.serverHost}:${source.masterShadowsocks.serverPort}`,
health: { ok: true, mode: "external", host: "", port: 0 },
valuesPrinted: false,
};
}
function proxySecretMaterial(server: HostProxyServer, source: HostProxySource): HostProxySecretMaterial {
const envSource = readEnvSourceFile({
root: rootPath(".state", "secrets"),
@@ -951,9 +979,12 @@ function renderApply(result: Record<string, unknown>): RenderedCliResult {
const client = record(remote.client);
const podProbe = record(remote.podAccessProbe);
const probe = record(remote.externalProbe);
const serverRows = serverApply.enabled === false
? table(["SOURCE", "OK", "UPSTREAM", "TYPE"], [[text(serverApply.id), text(serverApply.ok), text(serverApply.listen), text(serverApply.sourceType)]])
: table(["SERVER", "OK", "LISTEN", "BENCHMARK"], [[text(server.id), text(serverApply.ok), text(server.listen), text(server.benchmarkRef)]]);
const lines = [
"PLATFORM-INFRA HOST PROXY APPLY",
...table(["SERVER", "OK", "LISTEN", "BENCHMARK"], [[text(server.id), text(serverApply.ok), text(server.listen), text(server.benchmarkRef)]]),
...serverRows,
"",
...table(["SERVER_HEALTH", "CLIENT_BINARY", "DISTRIBUTION"], [[text(serverHealth.ok), text(artifact.binaryAction), text(distribution.mode)]]),
"",
@@ -979,9 +1010,12 @@ function renderStatus(result: Record<string, unknown>): RenderedCliResult {
const health = record(remote.health);
const probe = record(remote.externalProbe);
const podProbe = record(remote.podAccessProbe);
const serverRows = serverStatus.enabled === false
? table(["SOURCE", "OK", "UPSTREAM", "TYPE"], [[text(serverStatus.id), text(serverStatus.ok), text(serverStatus.listen), text(serverStatus.sourceType)]])
: table(["SERVER", "OK", "LISTEN", "CONTAINER"], [[text(server.id), text(serverStatus.ok), text(server.listen), text(serverStatus.container)]]);
const lines = [
"PLATFORM-INFRA HOST PROXY STATUS",
...table(["SERVER", "OK", "LISTEN", "CONTAINER"], [[text(server.id), text(serverStatus.ok), text(server.listen), text(serverStatus.container)]]),
...serverRows,
"",
...table(["TARGET", "ROUTE", "OK", "CLIENT"], [[text(target.id), text(target.route), result.ok === false ? "false" : "true", text(client.service)]]),
"",