fix(cicd): 使用最小联通就绪门禁

This commit is contained in:
root
2026-07-21 14:27:10 +02:00
parent c0b336a9a1
commit aae393367f
4 changed files with 18 additions and 48 deletions
+1 -33
View File
@@ -21,7 +21,6 @@ function requiredEnv(name) {
const revision = requiredEnv("HWLAB_SOURCE_REVISION");
const runtimeNamespace = requiredEnv("HWLAB_RUNTIME_NAMESPACE");
const gitopsTarget = requiredEnv("HWLAB_GITOPS_TARGET");
const argoApplication = requiredEnv("HWLAB_ARGO_APPLICATION");
const pipelineRun = process.env.HWLAB_TEKTON_PIPELINERUN || null;
const taskRun = process.env.HWLAB_TEKTON_TASKRUN || null;
const task = process.env.HWLAB_TEKTON_TASK || null;
@@ -161,35 +160,6 @@ function maybeEmitProgress(state, stage, stageStartedAt, payload) {
emit({ stage, status: "progress", durationMs: now - stageStartedAt, readinessMode, ...payload });
}
async function argoApplicationState() {
const path = "/apis/argoproj.io/v1alpha1/namespaces/argocd/applications/" + encodeURIComponent(argoApplication);
const response = await request("GET", path);
if (response.statusCode === 403) return { status: "rbac-denied", item: null, statusCode: response.statusCode };
if (response.statusCode < 200 || response.statusCode > 299) return { status: "error", item: null, statusCode: response.statusCode, body: response.body.slice(0, 500) };
return { status: "ok", item: response.json, statusCode: response.statusCode };
}
async function waitForArgoSyncedHealthy() {
const stageStartedAt = Date.now();
const progressState = { lastProgressAt: 0 };
while (Date.now() < deadline) {
const application = await argoApplicationState();
if (application.status === "rbac-denied") return fail("argo-sync-health", "argocd-application-rbac-denied", stageStartedAt, { readinessMode });
if (application.status !== "ok") return fail("argo-sync-health", "argocd-application-read-failed", stageStartedAt, { readinessMode, statusCode: application.statusCode, body: application.body || null });
const syncStatus = application.item?.status?.sync?.status || null;
const healthStatus = application.item?.status?.health?.status || null;
const operationPhase = application.item?.status?.operationState?.phase || null;
const operationMessage = application.item?.status?.operationState?.message || null;
if (syncStatus === "Synced" && healthStatus === "Healthy") {
emit({ stage: "argo-sync-health", status: "succeeded", durationMs: Date.now() - stageStartedAt, readinessMode, syncStatus, healthStatus, operationPhase });
return true;
}
maybeEmitProgress(progressState, "argo-sync-health", stageStartedAt, { syncStatus, healthStatus, operationPhase, operationMessage });
await sleep(Math.min(pollMs, Math.max(0, deadline - Date.now())));
}
return fail("argo-sync-health", "runtime-ready-wall-clock-timeout", stageStartedAt, { readinessMode }, "timeout");
}
async function waitForArgoRefresh() {
const stageStartedAt = Date.now();
const progressState = { lastProgressAt: 0 };
@@ -236,9 +206,7 @@ function fail(stage, reason, stageStartedAt, extra = {}, status = "failed") {
emit({ stage: "runtime-ready", status: "started", readinessMode, observedServiceCount: observedServiceIds ? observedServiceIds.size : 0, timeoutMs });
try {
if (!observedServiceIds) {
if (await waitForArgoSyncedHealthy()) await waitForWorkloads();
} else if (await waitForArgoRefresh()) {
if (await waitForArgoRefresh()) {
await waitForWorkloads();
}
} catch (error) {