fix(hwlab): configure d601 internal probe and local postgres (#725)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -80,6 +80,13 @@ export interface HwlabRuntimeExternalPostgresSpec {
|
||||
}
|
||||
|
||||
export interface HwlabRuntimePostgresStoreSpec {
|
||||
readonly mode?: "local-k3s" | "platform-service";
|
||||
readonly secretName?: string;
|
||||
readonly statefulSet?: string;
|
||||
readonly serviceName?: string;
|
||||
readonly adminUser?: string;
|
||||
readonly cloudApi?: HwlabRuntimePostgresStoreComponentSpec;
|
||||
readonly openfga?: HwlabRuntimePostgresStoreComponentSpec;
|
||||
readonly poolMax: number;
|
||||
readonly connectionTimeoutMs?: number;
|
||||
readonly queryRetryMaxAttempts?: number;
|
||||
@@ -87,10 +94,39 @@ export interface HwlabRuntimePostgresStoreSpec {
|
||||
readonly queryRetryMaxDelayMs?: number;
|
||||
}
|
||||
|
||||
export interface HwlabRuntimePostgresStoreComponentSpec {
|
||||
readonly secretName: string;
|
||||
readonly secretKey: string;
|
||||
readonly database: string;
|
||||
readonly role: string;
|
||||
readonly authnKey?: string;
|
||||
readonly postgresPasswordKey?: string;
|
||||
}
|
||||
|
||||
export interface HwlabRuntimeStoreSpec {
|
||||
readonly postgres?: HwlabRuntimePostgresStoreSpec;
|
||||
}
|
||||
|
||||
export interface HwlabRuntimeWebProbeServiceOriginSpec {
|
||||
readonly mode: "k8s-service-cluster-ip";
|
||||
readonly serviceName: string;
|
||||
readonly namespace: string;
|
||||
readonly port: number;
|
||||
readonly scheme: "http" | "https";
|
||||
}
|
||||
|
||||
export interface HwlabRuntimeWebProbePublicOriginSpec {
|
||||
readonly mode: "public";
|
||||
readonly baseUrl?: string;
|
||||
}
|
||||
|
||||
export type HwlabRuntimeWebProbeOriginSpec = HwlabRuntimeWebProbeServiceOriginSpec | HwlabRuntimeWebProbePublicOriginSpec;
|
||||
|
||||
export interface HwlabRuntimeWebProbeSpec {
|
||||
readonly browserProxyMode?: "auto" | "direct";
|
||||
readonly defaultOrigin?: HwlabRuntimeWebProbeOriginSpec;
|
||||
}
|
||||
|
||||
export interface HwlabRuntimeBuildkitSpec {
|
||||
readonly sidecarImage: string;
|
||||
}
|
||||
@@ -230,6 +266,7 @@ export interface HwlabRuntimeLaneSpec {
|
||||
readonly bootstrapAdmin?: HwlabRuntimeBootstrapAdminSpec;
|
||||
readonly externalPostgres?: HwlabRuntimeExternalPostgresSpec;
|
||||
readonly runtimeStore?: HwlabRuntimeStoreSpec;
|
||||
readonly webProbe?: HwlabRuntimeWebProbeSpec;
|
||||
readonly publicExposure: HwlabRuntimePublicExposureSpec | null;
|
||||
readonly observability: HwlabRuntimeObservabilitySpec;
|
||||
readonly runtimeImageRewrites: readonly HwlabRuntimeImageRewriteSpec[];
|
||||
@@ -272,6 +309,7 @@ interface HwlabLaneConfig {
|
||||
readonly bootstrapAdmin?: HwlabRuntimeBootstrapAdminSpec;
|
||||
readonly externalPostgres?: HwlabRuntimeExternalPostgresSpec;
|
||||
readonly runtimeStore?: HwlabRuntimeStoreSpec;
|
||||
readonly webProbe?: HwlabRuntimeWebProbeSpec;
|
||||
readonly publicExposure: HwlabRuntimePublicExposureSpec | null;
|
||||
readonly observability: HwlabRuntimeObservabilitySpec;
|
||||
readonly runtimeImageRewrites: readonly HwlabRuntimeImageRewriteSpec[];
|
||||
@@ -490,6 +528,7 @@ function laneConfig(id: HwlabRuntimeLane, raw: Record<string, unknown>): HwlabLa
|
||||
bootstrapAdmin: bootstrapAdminConfig(raw.bootstrapAdmin, `lanes.${id}.bootstrapAdmin`),
|
||||
externalPostgres: externalPostgresConfig(raw.externalPostgres, `lanes.${id}.externalPostgres`),
|
||||
runtimeStore: runtimeStoreConfig(raw.runtimeStore, `lanes.${id}.runtimeStore`),
|
||||
webProbe: webProbeConfig(raw.webProbe, `lanes.${id}.webProbe`),
|
||||
publicExposure: publicExposureConfig(raw.publicExposure, `lanes.${id}.publicExposure`),
|
||||
observability: observabilityConfig(raw.observability, `lanes.${id}.observability`),
|
||||
runtimeImageRewrites: runtimeImageRewritesConfig(raw.runtimeImageRewrites, `lanes.${id}.runtimeImageRewrites`),
|
||||
@@ -510,6 +549,7 @@ function laneTargetConfig(id: HwlabRuntimeLane, nodeId: string, baseRaw: Record<
|
||||
bootstrapAdmin: mergeOptionalRecord(baseRaw.bootstrapAdmin, targetRaw.bootstrapAdmin),
|
||||
externalPostgres: mergeOptionalRecord(baseRaw.externalPostgres, targetRaw.externalPostgres),
|
||||
runtimeStore: mergeOptionalRecord(baseRaw.runtimeStore, targetRaw.runtimeStore),
|
||||
webProbe: mergeOptionalRecord(baseRaw.webProbe, targetRaw.webProbe),
|
||||
publicExposure: mergeOptionalRecord(baseRaw.publicExposure, targetRaw.publicExposure),
|
||||
observability: mergeOptionalRecord(baseRaw.observability, targetRaw.observability),
|
||||
};
|
||||
@@ -595,6 +635,13 @@ function runtimeStoreConfig(value: unknown, path: string): HwlabRuntimeStoreSpec
|
||||
? {}
|
||||
: {
|
||||
postgres: {
|
||||
...(postgres.mode === undefined ? {} : { mode: postgresModeField(postgres, `${path}.postgres`) }),
|
||||
...(postgres.secretName === undefined ? {} : { secretName: stringField(postgres, "secretName", `${path}.postgres`) }),
|
||||
...(postgres.statefulSet === undefined ? {} : { statefulSet: stringField(postgres, "statefulSet", `${path}.postgres`) }),
|
||||
...(postgres.serviceName === undefined ? {} : { serviceName: stringField(postgres, "serviceName", `${path}.postgres`) }),
|
||||
...(postgres.adminUser === undefined ? {} : { adminUser: stringField(postgres, "adminUser", `${path}.postgres`) }),
|
||||
...(postgres.cloudApi === undefined ? {} : { cloudApi: runtimeStorePostgresComponentConfig(postgres.cloudApi, `${path}.postgres.cloudApi`) }),
|
||||
...(postgres.openfga === undefined ? {} : { openfga: runtimeStorePostgresComponentConfig(postgres.openfga, `${path}.postgres.openfga`) }),
|
||||
poolMax: numberField(postgres, "poolMax", `${path}.postgres`),
|
||||
...(postgres.connectionTimeoutMs === undefined
|
||||
? {}
|
||||
@@ -613,6 +660,62 @@ function runtimeStoreConfig(value: unknown, path: string): HwlabRuntimeStoreSpec
|
||||
};
|
||||
}
|
||||
|
||||
function postgresModeField(raw: Record<string, unknown>, path: string): "local-k3s" | "platform-service" {
|
||||
const mode = stringField(raw, "mode", path);
|
||||
if (mode !== "local-k3s" && mode !== "platform-service") throw new Error(`${path}.mode must be local-k3s or platform-service`);
|
||||
return mode;
|
||||
}
|
||||
|
||||
function runtimeStorePostgresComponentConfig(value: unknown, path: string): HwlabRuntimePostgresStoreComponentSpec {
|
||||
const raw = asRecord(value, path);
|
||||
return {
|
||||
secretName: stringField(raw, "secretName", path),
|
||||
secretKey: secretKeyField(raw, "secretKey", path),
|
||||
database: stringField(raw, "database", path),
|
||||
role: stringField(raw, "role", path),
|
||||
authnKey: optionalStringField(raw, "authnKey", path),
|
||||
postgresPasswordKey: optionalStringField(raw, "postgresPasswordKey", path),
|
||||
};
|
||||
}
|
||||
|
||||
function webProbeConfig(value: unknown, path: string): HwlabRuntimeWebProbeSpec | undefined {
|
||||
if (value === undefined) return undefined;
|
||||
const raw = asRecord(value, path);
|
||||
const rawBrowserProxyMode = optionalStringField(raw, "browserProxyMode", path);
|
||||
let browserProxyMode: "auto" | "direct" | undefined;
|
||||
if (rawBrowserProxyMode !== undefined) {
|
||||
if (rawBrowserProxyMode !== "auto" && rawBrowserProxyMode !== "direct") {
|
||||
throw new Error(`${path}.browserProxyMode must be auto or direct`);
|
||||
}
|
||||
browserProxyMode = rawBrowserProxyMode;
|
||||
}
|
||||
return {
|
||||
...(browserProxyMode === undefined ? {} : { browserProxyMode }),
|
||||
...(raw.defaultOrigin === undefined ? {} : { defaultOrigin: webProbeOriginConfig(raw.defaultOrigin, `${path}.defaultOrigin`) }),
|
||||
};
|
||||
}
|
||||
|
||||
function webProbeOriginConfig(value: unknown, path: string): HwlabRuntimeWebProbeOriginSpec {
|
||||
const raw = asRecord(value, path);
|
||||
const mode = stringField(raw, "mode", path);
|
||||
if (mode === "public") {
|
||||
return {
|
||||
mode,
|
||||
...(raw.baseUrl === undefined ? {} : { baseUrl: stringField(raw, "baseUrl", path).replace(/\/+$/u, "") }),
|
||||
};
|
||||
}
|
||||
if (mode !== "k8s-service-cluster-ip") throw new Error(`${path}.mode must be public or k8s-service-cluster-ip`);
|
||||
const scheme = stringField(raw, "scheme", path);
|
||||
if (scheme !== "http" && scheme !== "https") throw new Error(`${path}.scheme must be http or https`);
|
||||
return {
|
||||
mode,
|
||||
serviceName: stringField(raw, "serviceName", path),
|
||||
namespace: stringField(raw, "namespace", path),
|
||||
port: numberField(raw, "port", path),
|
||||
scheme,
|
||||
};
|
||||
}
|
||||
|
||||
function publicExposureProxyConfig(value: unknown, path: string): HwlabRuntimePublicExposureFrpcProxySpec {
|
||||
const raw = asRecord(value, path);
|
||||
return {
|
||||
@@ -887,6 +990,7 @@ function buildRuntimeLaneSpec(config: HwlabLaneConfig): HwlabRuntimeLaneSpec {
|
||||
...(config.bootstrapAdmin === undefined ? {} : { bootstrapAdmin: config.bootstrapAdmin }),
|
||||
...(config.externalPostgres === undefined ? {} : { externalPostgres: config.externalPostgres }),
|
||||
...(config.runtimeStore === undefined ? {} : { runtimeStore: config.runtimeStore }),
|
||||
...(config.webProbe === undefined ? {} : { webProbe: config.webProbe }),
|
||||
publicExposure: config.publicExposure,
|
||||
observability: config.observability,
|
||||
runtimeImageRewrites: config.runtimeImageRewrites,
|
||||
|
||||
Reference in New Issue
Block a user