61 lines
2.0 KiB
Bash
61 lines
2.0 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
payload_dir=$(mktemp -d)
|
|
cleanup() {
|
|
status=$?
|
|
trap - 0 1 2 15
|
|
rm -rf "$payload_dir"
|
|
exit "$status"
|
|
}
|
|
trap cleanup 0 1 2 15
|
|
|
|
UNIDESK_PAC_EVALUATOR_PATH="$payload_dir/pac-status-evaluator.cjs"
|
|
printf '%s' "$UNIDESK_PAC_EVALUATOR_B64" | base64 -d >"$UNIDESK_PAC_EVALUATOR_PATH"
|
|
export UNIDESK_PAC_EVALUATOR_PATH
|
|
|
|
read_errors="$payload_dir/read-errors.jsonl"
|
|
: >"$read_errors"
|
|
|
|
capture_list() {
|
|
stage="$1"
|
|
resource="$2"
|
|
output="$3"
|
|
if timeout "$UNIDESK_PAC_READ_STEP_TIMEOUT_SECONDS" kubectl get "$resource" -A -o json >"$output" 2>"$payload_dir/$stage.stderr"; then
|
|
return 0
|
|
else
|
|
exit_code=$?
|
|
fi
|
|
printf '{"stage":"%s","code":"pac-node-%s-read-failed","exitCode":%s,"valuesPrinted":false}\n' \
|
|
"$stage" "$stage" "$exit_code" >>"$read_errors"
|
|
printf '{"items":[]}' >"$output"
|
|
}
|
|
|
|
capture_list pipeline-runs pipelinerun.tekton.dev "$payload_dir/pipelineruns.json"
|
|
capture_list argo-applications application.argoproj.io "$payload_dir/applications.json"
|
|
capture_list deployments deployment.apps "$payload_dir/deployments.json"
|
|
|
|
node - "$payload_dir" <<'NODE'
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const payloadDir = process.argv[2];
|
|
const readJson = (name, fallback) => {
|
|
try { return JSON.parse(fs.readFileSync(path.join(payloadDir, name), "utf8") || JSON.stringify(fallback)); }
|
|
catch { return fallback; }
|
|
};
|
|
const readErrors = fs.readFileSync(path.join(payloadDir, "read-errors.jsonl"), "utf8")
|
|
.split(/\r?\n/u)
|
|
.filter(Boolean)
|
|
.map((line) => JSON.parse(line));
|
|
const consumers = JSON.parse(Buffer.from(process.env.UNIDESK_PAC_NODE_CONSUMERS_B64 || "W10=", "base64").toString("utf8"));
|
|
const { evaluatePacNodeStatusSnapshot } = require(process.env.UNIDESK_PAC_EVALUATOR_PATH);
|
|
const result = evaluatePacNodeStatusSnapshot({
|
|
consumers,
|
|
pipelineRuns: readJson("pipelineruns.json", { items: [] }),
|
|
applications: readJson("applications.json", { items: [] }),
|
|
deployments: readJson("deployments.json", { items: [] }),
|
|
readErrors,
|
|
});
|
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
NODE
|