feat: add bounded cicd long polling

This commit is contained in:
Codex
2026-07-15 06:35:25 +02:00
parent b9c86f4d3f
commit 81163ab236
15 changed files with 363 additions and 59 deletions
+14 -4
View File
@@ -20,6 +20,7 @@ import {
} from "../artifact-registry";
import { k3sGuardShellLines, defaultNativeKubeconfig } from "../k3s-target-guard";
import { runSshCommandCapture } from "../ssh";
import { kubernetesWatchOneEventShellFunction } from "../kubernetes-watch";
import type { DispatchResult, PipelineRunCondition } from "./types";
import { status } from "./cleanup";
@@ -48,10 +49,11 @@ export async function waitForPipelineRun(name: string, waitMs: number, target =
const command = [
"set -euo pipefail",
...ciTargetGuardShellLines(target),
`printf 'waiting_pipelinerun=%s\\n' ${shellQuote(name)}`,
kubernetesWatchOneEventShellFunction(),
`deadline=$((SECONDS + ${Math.ceil(waitMs / 1000)}))`,
"while [ \"$SECONDS\" -lt \"$deadline\" ]; do",
` condition="$(kubectl get pipelinerun/${shellQuote(name)} -n unidesk-ci -o jsonpath='{range .status.conditions[?(@.type==\"Succeeded\")]}{.status}{\"\\t\"}{.reason}{\"\\t\"}{.message}{end}' 2>/dev/null || true)"`,
`printf 'waiting_pipelinerun=%s\\n' ${shellQuote(name)}`,
`condition="$(kubectl get pipelinerun/${shellQuote(name)} -n unidesk-ci -o jsonpath='{range .status.conditions[?(@.type==\"Succeeded\")]}{.status}{\"\\t\"}{.reason}{\"\\t\"}{.message}{end}' 2>/dev/null || true)"`,
"while :; do",
" case \"$condition\" in",
" True*)",
" printf 'condition=%s\\n' \"$condition\"",
@@ -64,7 +66,15 @@ export async function waitForPipelineRun(name: string, waitMs: number, target =
" exit 1",
" ;;",
" esac",
" sleep 2",
" remaining=$((deadline - SECONDS))",
" [ \"$remaining\" -gt 0 ] || break",
" set +e",
` event="$(unidesk_watch_one_event kubectl get pipelinerun/${shellQuote(name)} -n unidesk-ci --watch-only --request-timeout="\${remaining}s" -o name)"`,
" watch_status=$?",
" set -e",
" [ \"$watch_status\" -eq 0 ] || exit \"$watch_status\"",
" [ -n \"$event\" ] || break",
` condition="$(kubectl get pipelinerun/${shellQuote(name)} -n unidesk-ci -o jsonpath='{range .status.conditions[?(@.type==\"Succeeded\")]}{.status}{\"\\t\"}{.reason}{\"\\t\"}{.message}{end}' 2>/dev/null || true)"`,
"done",
`echo "Timed out waiting for pipelinerun/${name}" >&2`,
`kubectl get pipelinerun/${shellQuote(name)} -n unidesk-ci -o json`,