fix(cicd): surface taskrun log read failures

This commit is contained in:
Codex
2026-07-03 23:50:38 +00:00
parent 41a5315168
commit e19ef721e0
2 changed files with 38 additions and 5 deletions
+22 -4
View File
@@ -59,8 +59,12 @@ async function main() {
for (const container of logContainers) {
const name = container.containerName || container.name;
if (!podName || !name) continue;
const text = await readPodLog(podName, name, logsTailLines, perContainerBytes);
const read = await readPodLog(podName, name, logsTailLines, perContainerBytes);
const text = read.tail || "";
logs.push({
ok: read.ok,
degradedReason: read.degradedReason,
message: read.message,
pod: podName,
container: name,
lineCount: text.length === 0 ? 0 : text.split(/\r?\n/u).filter((line) => line.length > 0).length,
@@ -70,8 +74,16 @@ async function main() {
});
}
const timing = lastTiming(logs);
const logFailures = logs.filter((item) => item.ok === false);
console.log(JSON.stringify({
ok: true,
ok: logFailures.length === 0,
degradedReason: logFailures.length === 0 ? null : "log-read-failed",
errors: logFailures.map((item) => ({
pod: item.pod,
container: item.container,
degradedReason: item.degradedReason,
message: item.message,
})),
taskRun: {
name: metadata.name || null,
namespace: metadata.namespace || namespace,
@@ -222,9 +234,15 @@ function selectLogContainers(containers) {
async function readPodLog(podName, container, tailLines, limitBytes) {
const path = `/api/v1/namespaces/${encodeURIComponent(namespace)}/pods/${encodeURIComponent(podName)}/log?container=${encodeURIComponent(container)}&tailLines=${tailLines}&limitBytes=${limitBytes}`;
try {
return tailBytes(await getText(path, false), limitBytes);
const text = tailBytes(await getText(path, false), limitBytes);
return { ok: true, degradedReason: null, message: null, tail: text };
} catch (error) {
return `log-read-failed: ${shortText(error?.message || String(error))}`;
return {
ok: false,
degradedReason: isNotFoundError(error) ? "log-not-found" : error instanceof KubeReadError ? error.reason : "log-read-failed",
message: shortText(error?.message || String(error)),
tail: "",
};
}
}