ci: migrate sentinel to gitea pac
This commit is contained in:
@@ -6,6 +6,8 @@ const pipelineRun = process.env.PIPELINERUN || "";
|
||||
const shouldWait = process.env.WAIT === "true";
|
||||
const timeoutSeconds = requiredPositiveNumber("TIMEOUT_SECONDS");
|
||||
const pollIntervalSeconds = requiredPositiveNumber("POLL_INTERVAL_SECONDS");
|
||||
const logsTailLines = Number(process.env.LOGS_TAIL_LINES || "240");
|
||||
const maxLogBytes = Number(process.env.MAX_LOG_BYTES || "32000");
|
||||
const host = process.env.KUBERNETES_SERVICE_HOST;
|
||||
const port = Number(process.env.KUBERNETES_SERVICE_PORT || "443");
|
||||
const token = readFileSync("/var/run/secrets/kubernetes.io/serviceaccount/token", "utf8").trim();
|
||||
@@ -106,6 +108,7 @@ const condition = succeededCondition(latest.object);
|
||||
const completed = condition?.status === "True";
|
||||
const failed = condition?.status === "False";
|
||||
const terminal = completed || failed;
|
||||
const logsTail = terminal ? await pipelineRunLogsTail() : "";
|
||||
const output = {
|
||||
ok: !failed,
|
||||
submitted: true,
|
||||
@@ -120,6 +123,7 @@ const output = {
|
||||
timedOutWait: shouldWait && !terminal,
|
||||
elapsedMs: Date.now() - startedAt,
|
||||
pipelineRun: compact(latest.object),
|
||||
logsTail,
|
||||
statusAuthority: "kubernetes-api-serviceaccount",
|
||||
parsedDownstreamCliOutput: false,
|
||||
valuesRedacted: true,
|
||||
@@ -132,3 +136,25 @@ function requiredPositiveNumber(name) {
|
||||
if (!Number.isFinite(value) || value <= 0) throw new Error(`${name} must be a positive number`);
|
||||
return value;
|
||||
}
|
||||
|
||||
async function pipelineRunLogsTail() {
|
||||
const selector = encodeURIComponent(`tekton.dev/pipelineRun=${pipelineRun}`);
|
||||
const podsResult = await request("GET", `/api/v1/namespaces/${encodeURIComponent(namespace)}/pods?labelSelector=${selector}`);
|
||||
if (podsResult.status < 200 || podsResult.status >= 300) return "";
|
||||
const pods = parseBody(podsResult);
|
||||
const chunks = [];
|
||||
for (const pod of Array.isArray(pods?.items) ? pods.items : []) {
|
||||
const podName = pod?.metadata?.name;
|
||||
const containers = [
|
||||
...(Array.isArray(pod?.spec?.initContainers) ? pod.spec.initContainers : []),
|
||||
...(Array.isArray(pod?.spec?.containers) ? pod.spec.containers : []),
|
||||
];
|
||||
for (const container of containers) {
|
||||
if (!podName || !container?.name) continue;
|
||||
const path = `/api/v1/namespaces/${encodeURIComponent(namespace)}/pods/${encodeURIComponent(podName)}/log?container=${encodeURIComponent(container.name)}&tailLines=${Math.max(1, logsTailLines)}`;
|
||||
const log = await request("GET", path);
|
||||
if (log.status >= 200 && log.status < 300 && log.text) chunks.push(log.text);
|
||||
}
|
||||
}
|
||||
return chunks.join("\n").slice(-Math.max(1, maxLogBytes));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user