feat(microservices): manage code queue through v3s
This commit is contained in:
@@ -66,6 +66,14 @@ export interface UniDeskMicroserviceConfig {
|
||||
healthPath: string;
|
||||
timeoutMs: number;
|
||||
};
|
||||
deployment: {
|
||||
mode: "unidesk-direct" | "v3sctl-managed";
|
||||
adapterServiceId?: string;
|
||||
v3sServiceId?: string;
|
||||
namespace?: string;
|
||||
expectedNodeIds?: string[];
|
||||
activeNodeId?: string;
|
||||
};
|
||||
development: {
|
||||
providerId: string;
|
||||
sshPassthrough: boolean;
|
||||
@@ -114,12 +122,25 @@ function booleanField(obj: Record<string, unknown>, key: string, path: string):
|
||||
return value;
|
||||
}
|
||||
|
||||
function optionalStringField(obj: Record<string, unknown>, key: string, path: string): string | undefined {
|
||||
const value = obj[key];
|
||||
if (value === undefined) return undefined;
|
||||
if (typeof value !== "string" || value.length === 0) throw new Error(`${path}.${key} must be a non-empty string`);
|
||||
return value;
|
||||
}
|
||||
|
||||
function optionalArray(value: unknown, name: string): Record<string, unknown>[] {
|
||||
if (value === undefined) return [];
|
||||
if (!Array.isArray(value)) throw new Error(`${name} must be an array`);
|
||||
return value.map((item, index) => asRecord(item, `${name}[${index}]`));
|
||||
}
|
||||
|
||||
function optionalStringArrayField(obj: Record<string, unknown>, key: string, path: string): string[] | undefined {
|
||||
const value = obj[key];
|
||||
if (value === undefined) return undefined;
|
||||
return stringArrayField(obj, key, path);
|
||||
}
|
||||
|
||||
function stringArrayField(obj: Record<string, unknown>, key: string, path: string): string[] {
|
||||
const value = obj[key];
|
||||
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || item.length === 0)) {
|
||||
@@ -146,6 +167,11 @@ function microserviceConfig(item: Record<string, unknown>, index: number): UniDe
|
||||
const backend = asRecord(item.backend, `${path}.backend`);
|
||||
const development = asRecord(item.development, `${path}.development`);
|
||||
const frontend = asRecord(item.frontend, `${path}.frontend`);
|
||||
const deployment = item.deployment === undefined ? undefined : asRecord(item.deployment, `${path}.deployment`);
|
||||
const deploymentMode = deployment === undefined ? "unidesk-direct" : stringField(deployment, "mode", `${path}.deployment`);
|
||||
if (deploymentMode !== "unidesk-direct" && deploymentMode !== "v3sctl-managed") {
|
||||
throw new Error(`${path}.deployment.mode must be unidesk-direct or v3sctl-managed`);
|
||||
}
|
||||
return {
|
||||
id: stringField(item, "id", path),
|
||||
name: stringField(item, "name", path),
|
||||
@@ -171,6 +197,16 @@ function microserviceConfig(item: Record<string, unknown>, index: number): UniDe
|
||||
healthPath: stringField(backend, "healthPath", `${path}.backend`),
|
||||
timeoutMs: numberField(backend, "timeoutMs", `${path}.backend`),
|
||||
},
|
||||
deployment: deployment === undefined
|
||||
? { mode: "unidesk-direct" }
|
||||
: {
|
||||
mode: deploymentMode,
|
||||
adapterServiceId: optionalStringField(deployment, "adapterServiceId", `${path}.deployment`),
|
||||
v3sServiceId: optionalStringField(deployment, "v3sServiceId", `${path}.deployment`),
|
||||
namespace: optionalStringField(deployment, "namespace", `${path}.deployment`),
|
||||
expectedNodeIds: optionalStringArrayField(deployment, "expectedNodeIds", `${path}.deployment`),
|
||||
activeNodeId: optionalStringField(deployment, "activeNodeId", `${path}.deployment`),
|
||||
},
|
||||
development: {
|
||||
providerId: stringField(development, "providerId", `${path}.development`),
|
||||
sshPassthrough: booleanField(development, "sshPassthrough", `${path}.development`),
|
||||
|
||||
Reference in New Issue
Block a user