fix: close out sentinel pac status
Pipelines as Code CI / hwlab-web-probe-sentinel-jd01- Success

This commit is contained in:
Codex
2026-07-05 16:31:26 +00:00
parent 2195a646b7
commit 0370f14594
3 changed files with 83 additions and 4 deletions
+5
View File
@@ -52,3 +52,8 @@ spec:
--source-commit "$SOURCE_COMMIT" \
--source-stage-ref "$SOURCE_STAGE_REF" \
--source-authority gitea-snapshot
bun scripts/cli.ts web-probe sentinel control-plane apply \
--node JD01 \
--lane v03 \
--sentinel jd01-web-probe-sentinel \
--confirm
@@ -311,6 +311,14 @@ for (const line of lines) {
}
const publish = [...records].reverse().find((item) => item.phase === 'gitops-publish' || item.gitopsCommit);
const image = publish || [...records].reverse().find((item) => item.imageStatus || item.status === 'reused' || item.status === 'built');
const envHeaderIndex = lines.findIndex((line) => /^ENV_REUSE\s+NODE_DEPS\s+/u.test(line.trim()));
let humanEnv = null;
if (envHeaderIndex >= 0) {
const row = (lines.slice(envHeaderIndex + 1).find((line) => line.trim() && !/^-+\s+-+/u.test(line.trim())) || '').trim().split(/\s+/u);
if (row.length >= 5) {
humanEnv = { envReuse: row[0], nodeDeps: row[1], buildPackage: row[2], buildNetwork: row[3], cache: row[4] };
}
}
function digestOf(item) {
if (item.digest) return item.digest;
const ref = item.digestRef || '';
@@ -325,15 +333,71 @@ process.stdout.write(JSON.stringify(image ? {
imageStatus: image.imageStatus || image.status || (image.digestRef ? 'built' : null),
envIdentity: image.envIdentity || null,
envReuse: envReuseOf(image),
nodeDepsReuse: null,
buildCache: null,
digest: digestOf(image),
gitopsCommit: image.gitopsCommit || null,
sourceCommit: image.sourceCommit || null,
valuesPrinted: false,
} : humanEnv ? {
imageStatus: 'published',
envIdentity: null,
envReuse: humanEnv.envReuse,
nodeDepsReuse: humanEnv.nodeDeps,
buildCache: humanEnv.cache,
buildPackage: humanEnv.buildPackage,
buildNetwork: humanEnv.buildNetwork,
digest: null,
gitopsCommit: null,
sourceCommit: null,
valuesPrinted: false,
} : { valuesPrinted: false }));
NODE
rm -f "$log_file"
}
runtime_summary() {
app_file=$(mktemp)
kubectl -n "$UNIDESK_PAC_ARGO_NAMESPACE" get application "$UNIDESK_PAC_ARGO_APPLICATION" -o json >"$app_file" 2>/dev/null || printf '{}' >"$app_file"
target=$(node - "$app_file" <<'NODE'
const fs = require('node:fs');
const app = JSON.parse(fs.readFileSync(process.argv[2], 'utf8') || '{}');
const resource = (app.status?.resources || []).find((item) => item.kind === 'Deployment' && item.namespace && item.name);
if (resource) process.stdout.write(`${resource.namespace}\t${resource.name}`);
NODE
)
rm -f "$app_file"
if [ -z "$target" ]; then
printf '{}'
return
fi
namespace=$(printf '%s' "$target" | cut -f1)
name=$(printf '%s' "$target" | cut -f2)
deploy_file=$(mktemp)
kubectl -n "$namespace" get deploy "$name" -o json >"$deploy_file" 2>/dev/null || printf '{}' >"$deploy_file"
node - "$deploy_file" <<'NODE' || printf '{}'
const fs = require('node:fs');
const input = fs.readFileSync(process.argv[2], 'utf8').trim();
if (!input) {
process.stdout.write('{}');
process.exit(0);
}
const deploy = JSON.parse(input);
const image = deploy.spec?.template?.spec?.containers?.[0]?.image || null;
const digest = image && String(image).includes('@') ? String(image).split('@').slice(1).join('@') : null;
process.stdout.write(JSON.stringify({
namespace: deploy.metadata?.namespace || null,
deployment: deploy.metadata?.name || null,
readyReplicas: deploy.status?.readyReplicas ?? null,
replicas: deploy.spec?.replicas ?? null,
image,
digest,
valuesPrinted: false,
}));
NODE
rm -f "$deploy_file"
}
hook_summary() {
hooks=$(gitea_api GET "repos/$UNIDESK_PAC_GITEA_OWNER/$UNIDESK_PAC_GITEA_REPO/hooks" 2>/dev/null || echo '[]')
HOOKS_JSON="$hooks" node <<'NODE'
@@ -355,12 +419,13 @@ status_action() {
artifact=$(artifact_summary)
hooks=$(hook_summary)
argo=$(kubectl -n "$UNIDESK_PAC_ARGO_NAMESPACE" get application "$UNIDESK_PAC_ARGO_APPLICATION" -o json 2>/dev/null | node -e 'const fs=require("fs"); const s=fs.readFileSync(0,"utf8").trim(); if(!s){process.stdout.write("{}"); process.exit(0)} const a=JSON.parse(s); process.stdout.write(JSON.stringify({sync:a.status?.sync?.status||null, health:a.status?.health?.status||null, revision:a.status?.sync?.revision||null}))' || echo '{}')
printf '{"ok":%s,"crdPresent":%s,"controllerReady":"%s","repositoryCondition":"%s","webhooks":%s,"pipelineRuns":%s,"taskRuns":%s,"artifact":%s,"argo":%s,"valuesPrinted":false}\n' \
runtime=$(runtime_summary)
printf '{"ok":%s,"crdPresent":%s,"controllerReady":"%s","repositoryCondition":"%s","webhooks":%s,"pipelineRuns":%s,"taskRuns":%s,"artifact":%s,"argo":%s,"runtime":%s,"valuesPrinted":false}\n' \
"$( [ -n "$crd" ] && [ "$controller_ready" != "0/0" ] && echo true || echo false )" \
"$( [ -n "$crd" ] && echo true || echo false )" \
"$(json_string "$controller_ready")" \
"$(json_string "$repository_condition")" \
"$hooks" "$pipelines" "$tasks" "$artifact" "$argo"
"$hooks" "$pipelines" "$tasks" "$artifact" "$argo" "$runtime"
}
webhook_test_action() {
@@ -533,6 +533,14 @@ function statusSummary(payload: Record<string, unknown>): Record<string, unknown
const pipelineRuns = arrayRecords(payload.pipelineRuns);
const latest = pipelineRuns[0] ?? {};
const taskRuns = arrayRecords(payload.taskRuns);
const argo = record(payload.argo);
const runtime = record(payload.runtime);
const artifact = {
...record(payload.artifact),
imageStatus: record(payload.artifact).imageStatus ?? (runtime.image === undefined ? undefined : "runtime"),
digest: record(payload.artifact).digest ?? runtime.digest,
gitopsCommit: record(payload.artifact).gitopsCommit ?? argo.revision,
};
return {
ready: payload.crdPresent === true && String(payload.controllerReady ?? "0/0") !== "0/0",
crdPresent: payload.crdPresent === true,
@@ -541,8 +549,9 @@ function statusSummary(payload: Record<string, unknown>): Record<string, unknown
webhookCount: arrayRecords(payload.webhooks).length,
latestPipelineRun: latest,
taskRuns,
artifact: record(payload.artifact),
argo: record(payload.argo),
artifact,
argo,
runtime,
valuesPrinted: false,
};
}