From fb597c6c72e84ff01074edce7bb20cf297f4ea0b Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 24 Jun 2026 13:51:05 +0000 Subject: [PATCH] fix(hwlab): allow targeted active run cleanup --- scripts/src/hwlab-node-impl.ts | 60 ++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/scripts/src/hwlab-node-impl.ts b/scripts/src/hwlab-node-impl.ts index dc9dad77..bf047108 100644 --- a/scripts/src/hwlab-node-impl.ts +++ b/scripts/src/hwlab-node-impl.ts @@ -150,6 +150,7 @@ interface NodeRuntimeCleanupOptions { sourceCommit?: string; pipelineRun?: string; targetPipelineRun?: string; + includeActive: boolean; dryRun: boolean; } @@ -1963,6 +1964,7 @@ function parseNodeRuntimeCleanupOptions(scoped: ReturnType item.name === options.targetPipelineRun); - if (target === undefined) { - return [{ - name: options.targetPipelineRun, - createdAt: null, - ageMinutes: null, - status: null, - reason: "target-pipelinerun-not-found", - selected: false, - }]; - } - if (target.status !== "True" && target.status !== "False") { - return [{ ...target, selected: false, selectedReason: "target-pipelinerun-not-terminal" }]; - } - if (target.ageMinutes === null || target.ageMinutes < options.minAgeMinutes) { - return [{ ...target, selected: false, selectedReason: target.ageMinutes === null ? "missing-creation-timestamp" : "below-min-age" }]; - } - return [target]; - } const prefix = `${spec.pipelineRunPrefix}-`; const terminalRuns = rows .filter((item) => item.name.startsWith(prefix)) @@ -2092,6 +2097,21 @@ function listNodeRuntimeCleanupPipelineRuns(spec: HwlabRuntimeLaneSpec, options: .slice(0, options.limit); } +function getNodeRuntimeCleanupPipelineRun(spec: HwlabRuntimeLaneSpec, pipelineRun: string): NodeRuntimeCleanupPipelineRunRow | null { + const result = runNodeK3sArgs(spec, [ + "kubectl", + "-n", + HWLAB_CI_NAMESPACE, + "get", + "pipelinerun", + pipelineRun, + "-o", + 'jsonpath={.metadata.name}{"\\t"}{.metadata.creationTimestamp}{"\\t"}{.status.conditions[0].status}{"\\t"}{.status.conditions[0].reason}{"\\n"}', + ], 60); + if (result.exitCode !== 0) return null; + return nodeRuntimeCleanupPipelineRunRowsFromText(result.stdout)[0] ?? null; +} + function nodeRuntimeCleanupPipelineRunRowsFromText(text: string): NodeRuntimeCleanupPipelineRunRow[] { const now = Date.now(); return text.split(/\r?\n/u).map((line) => {