fix: resolve pac node pipelineruns by source label
Pipelines as Code CI / hwlab-web-probe-sentinel-jd01- Success
Pipelines as Code CI / hwlab-web-probe-sentinel-jd01- Success
This commit is contained in:
@@ -179,7 +179,8 @@ export function nodeRuntimeControlPlaneStatus(scoped: ReturnType<typeof parseNod
|
||||
const pipelineRunOverride = optionValue(scoped.originalArgs, "--pipeline-run");
|
||||
const head = sourceCommitOverride === undefined ? resolveNodeRuntimeLaneHead(spec) : null;
|
||||
const sourceCommit = sourceCommitOverride ?? head?.sourceCommit ?? null;
|
||||
const pipelineRun = pipelineRunOverride ?? (sourceCommit === null ? null : nodeRuntimePipelineRunName(spec, sourceCommit));
|
||||
const expectedPipelineRun = sourceCommit === null ? null : nodeRuntimePipelineRunName(spec, sourceCommit);
|
||||
let pipelineRun = pipelineRunOverride ?? expectedPipelineRun;
|
||||
const namespace = runNodeK3sArgs(spec, ["kubectl", "get", "ns", spec.runtimeNamespace, "-o", "name"], probeTimeoutSeconds);
|
||||
const namespaceExists = namespace.exitCode === 0;
|
||||
const postgresObjects = namespaceExists
|
||||
@@ -192,7 +193,22 @@ export function nodeRuntimeControlPlaneStatus(scoped: ReturnType<typeof parseNod
|
||||
const pipeline = runNodeK3sArgs(spec, ["kubectl", "-n", "hwlab-ci", "get", "pipeline", spec.pipeline, "-o", "name"], probeTimeoutSeconds);
|
||||
const argo = runNodeK3sArgs(spec, ["kubectl", "-n", "argocd", "get", "application", spec.app, "-o", "jsonpath={.spec.source.repoURL}{\"\\n\"}{.spec.source.targetRevision}{\"\\n\"}{.spec.source.path}{\"\\n\"}{.status.sync.revision}{\"\\n\"}{.status.sync.status}{\"\\n\"}{.status.health.status}{\"\\n\"}"], probeTimeoutSeconds);
|
||||
const [repoURL = "", targetRevision = "", path = "", syncRevision = "", syncStatus = "", health = ""] = argo.stdout.split(/\r?\n/u);
|
||||
const pipelineRunProbe = pipelineRun === null ? null : getNodeRuntimePipelineRun(spec, pipelineRun);
|
||||
let pipelineRunProbe = pipelineRun === null ? null : getNodeRuntimePipelineRun(spec, pipelineRun);
|
||||
const pipelineRunResolution = pipelineRunOverride !== undefined
|
||||
? { mode: "explicit-pipeline-run", expectedName: pipelineRun, resolvedName: pipelineRun, fallbackUsed: false, result: null }
|
||||
: sourceCommit === null || expectedPipelineRun === null
|
||||
? { mode: "source-unresolved", expectedName: null, resolvedName: null, fallbackUsed: false, result: null }
|
||||
: { mode: "source-commit", expectedName: expectedPipelineRun, resolvedName: pipelineRun, fallbackUsed: false, result: null as Record<string, unknown> | null };
|
||||
if (pipelineRunOverride === undefined && sourceCommit !== null && expectedPipelineRun !== null && pipelineRunProbe !== null && pipelineRunProbe.exists !== true) {
|
||||
const resolved = resolveNodeRuntimePipelineRunBySourceCommit(spec, sourceCommit);
|
||||
pipelineRunResolution.result = compactRuntimeCommand(resolved.result);
|
||||
if (resolved.name !== null) {
|
||||
pipelineRun = resolved.name;
|
||||
pipelineRunResolution.resolvedName = resolved.name;
|
||||
pipelineRunResolution.fallbackUsed = true;
|
||||
pipelineRunProbe = getNodeRuntimePipelineRun(spec, resolved.name);
|
||||
}
|
||||
}
|
||||
const pipelineRunDiagnostics = pipelineRun !== null && pipelineRunProbe?.exists === true && pipelineRunProbe?.status !== "True"
|
||||
? nodeRuntimePipelineRunDiagnostics(spec, pipelineRun)
|
||||
: null;
|
||||
@@ -288,6 +304,8 @@ export function nodeRuntimeControlPlaneStatus(scoped: ReturnType<typeof parseNod
|
||||
lane: scoped.lane,
|
||||
sourceCommit,
|
||||
pipelineRun,
|
||||
expectedPipelineRun,
|
||||
pipelineRunResolution,
|
||||
expected: nodeRuntimeExpected(spec),
|
||||
sourceHead: head === null
|
||||
? { ok: sourceCommit !== null, value: sourceCommit, source: "option" }
|
||||
@@ -373,6 +391,29 @@ export function parseNodeRuntimeWorkloadReadiness(text: string): Array<Record<st
|
||||
});
|
||||
}
|
||||
|
||||
function resolveNodeRuntimePipelineRunBySourceCommit(spec: HwlabRuntimeLaneSpec, sourceCommit: string): { name: string | null; result: CommandResult } {
|
||||
const script = [
|
||||
"set -eu",
|
||||
`source_commit=${shellQuote(sourceCommit)}`,
|
||||
`prefix=${shellQuote(spec.pipelineRunPrefix)}`,
|
||||
"find_by_selector() {",
|
||||
" selector=$1",
|
||||
" kubectl -n hwlab-ci get pipelinerun -l \"$selector\" -o 'jsonpath={range .items[*]}{.metadata.creationTimestamp}{\"\\t\"}{.metadata.name}{\"\\n\"}{end}' 2>/dev/null \\",
|
||||
" | awk -v prefix=\"$prefix\" 'index($2, prefix) == 1 { print $0 }' \\",
|
||||
" | sort \\",
|
||||
" | tail -n 1 \\",
|
||||
" | awk '{print $2}'",
|
||||
"}",
|
||||
"name=$(find_by_selector \"hwlab.pikastech.local/source-commit=$source_commit\")",
|
||||
"if [ -z \"$name\" ]; then name=$(find_by_selector \"unidesk.ai/source-commit=$source_commit\"); fi",
|
||||
"if [ -z \"$name\" ]; then name=$(find_by_selector \"agentrun.pikastech.local/source-commit=$source_commit\"); fi",
|
||||
"printf '%s\\n' \"$name\"",
|
||||
].join("\n");
|
||||
const result = runNodeK3sArgs(spec, ["sh", "--", script], 30);
|
||||
const name = result.exitCode === 0 ? result.stdout.trim().split(/\r?\n/u).filter(Boolean).pop() ?? null : null;
|
||||
return { name: name !== null && name.length > 0 ? name : null, result };
|
||||
}
|
||||
|
||||
export function nullableInteger(value: string): number | null {
|
||||
if (!/^[0-9]+$/u.test(value)) return null;
|
||||
return Number(value);
|
||||
|
||||
Reference in New Issue
Block a user