fix: verify k3s deploy commits independently

This commit is contained in:
Codex
2026-05-17 14:33:59 +00:00
parent aa5454cb89
commit 84db3532c9
+17 -5
View File
@@ -84,8 +84,9 @@ interface ServiceRuntimeState {
const defaultDeployFile = "deploy.json";
const defaultTimeoutMs = 900_000;
const resolveFetchTimeout = "120s";
const shortDispatchWaitMs = 25_000;
const shortDispatchWaitMs = 60_000;
const shortRemoteTimeoutMs = 20_000;
const providerDispatchCompletionLagMs = 45_000;
const pollIntervalMs = 5_000;
const remoteDeployRoot = "/home/ubuntu/.unidesk/deploy";
const k8sNamespace = "unidesk";
@@ -1307,11 +1308,21 @@ function runtimeCommitVerified(
orchestratorCommit: string | null,
desired: string,
): boolean {
if (healthCommit !== null && healthCommit.length > 0 && !commitMatches(healthCommit, desired)) return false;
if (service.deployment.mode === "k3sctl-managed") return commitMatches(orchestratorCommit, desired);
if (healthCommit !== null && healthCommit.length > 0 && !commitMatches(healthCommit, desired)) return false;
return commitMatches(imageCommit, desired);
}
function runtimeCurrentCommit(
service: UniDeskMicroserviceConfig,
healthCommit: string | null,
imageCommit: string | null,
orchestratorCommit: string | null,
): string | null {
if (service.deployment.mode === "k3sctl-managed") return orchestratorCommit ?? imageCommit;
return healthCommit ?? imageCommit ?? orchestratorCommit;
}
function coreBody(response: unknown): Record<string, unknown> | null {
const record = asRecord(response);
return asRecord(record?.body);
@@ -1352,7 +1363,8 @@ async function dispatchSsh(
raw: dispatchResponse,
};
}
const deadline = Date.now() + waitMs;
const effectiveWaitMs = Math.max(waitMs, Math.min(remoteTimeoutMs + providerDispatchCompletionLagMs, 120_000));
const deadline = Date.now() + effectiveWaitMs;
let latest: unknown = null;
while (Date.now() < deadline) {
latest = coreInternalFetch(`/api/tasks/${encodeURIComponent(taskId)}`);
@@ -1380,7 +1392,7 @@ async function dispatchSsh(
taskId,
status: "timeout",
stdout: "",
stderr: `host.ssh task ${taskId} did not finish within ${waitMs}ms`,
stderr: `host.ssh task ${taskId} did not finish within ${effectiveWaitMs}ms`,
exitCode: null,
raw: latest,
};
@@ -1554,7 +1566,7 @@ async function readRuntimeState(config: UniDeskConfig, service: UniDeskMicroserv
readDockerImageCommit(config, service).catch(() => null),
readK8sCommit(config, service).catch(() => null),
]);
const currentCommit = healthCommit ?? orchestratorCommit ?? imageCommit;
const currentCommit = runtimeCurrentCommit(service, healthCommit, imageCommit, orchestratorCommit);
return {
serviceId: service.id,
ok: reason === null,