fix(cicd): 使用最小联通就绪门禁
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -223,6 +223,10 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
|
||||
assert.match(pipeline, /node scripts\/run-bun\.mjs test cmd\/hwlab-codex-api-responses-forwarder\/main\.test\.ts/u);
|
||||
assert.doesNotMatch(pipeline, /cmd\/hwlab-codex-api-responses-forwarder\/main\.mjs/u);
|
||||
const runtimeReadySource = await readFile(path.join(process.cwd(), "scripts/ci/runtime-ready.mjs"), "utf8");
|
||||
assert.doesNotMatch(runtimeReadySource, /argo-sync-health|healthStatus === "Healthy"/u);
|
||||
assert.doesNotMatch(runtimeReadySource, /HWLAB_ARGO_APPLICATION/u);
|
||||
assert.match(runtimeReadySource, /if \(await waitForArgoRefresh\(\)\) \{\s+await waitForWorkloads\(\);/u);
|
||||
assert.ok(!JSON.stringify(pipelineJson).includes("argo-application"));
|
||||
assert.match(runtimeReadySource, /process\.exitCode = 1/u);
|
||||
assert.match(runtimeReadySource, /item\.metadata\?\.labels\?\.\["hwlab\.pikastech\.local\/source-commit"\]/u);
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ function runtimeReadyTask({ profile = "dev", deploy = null } = {}) {
|
||||
runAfter: ["gitops-promote"],
|
||||
workspaces: [{ name: "source", workspace: "source" }],
|
||||
taskSpec: {
|
||||
params: [{ name: "revision" }, { name: "runtime-namespace" }, { name: "gitops-target" }, { name: "argo-application" }, { name: "timeout-ms" }],
|
||||
params: [{ name: "revision" }, { name: "runtime-namespace" }, { name: "gitops-target" }, { name: "timeout-ms" }],
|
||||
workspaces: [{ name: "source" }],
|
||||
steps: [{
|
||||
name: "runtime-ready",
|
||||
@@ -458,8 +458,7 @@ function runtimeReadyTask({ profile = "dev", deploy = null } = {}) {
|
||||
env: [
|
||||
...proxyEnv(),
|
||||
{ name: "HWLAB_RUNTIME_NAMESPACE", value: "$(params.runtime-namespace)" },
|
||||
{ name: "HWLAB_GITOPS_TARGET", value: "$(params.gitops-target)" },
|
||||
{ name: "HWLAB_ARGO_APPLICATION", value: "$(params.argo-application)" }
|
||||
{ name: "HWLAB_GITOPS_TARGET", value: "$(params.gitops-target)" }
|
||||
],
|
||||
script: runtimeReadyScript()
|
||||
}]
|
||||
@@ -468,7 +467,6 @@ function runtimeReadyTask({ profile = "dev", deploy = null } = {}) {
|
||||
{ name: "revision", value: "$(params.revision)" },
|
||||
{ name: "runtime-namespace", value: namespaceNameForProfile(profile, deploy) },
|
||||
{ name: "gitops-target", value: gitopsTargetForProfile(profile) },
|
||||
{ name: "argo-application", value: argoApplicationName(profile) },
|
||||
{ name: "timeout-ms", value: "$(params.runtime-ready-timeout-ms)" }
|
||||
]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user