fix: make unidesk host pac diagnostics actionable
This commit is contained in:
@@ -398,7 +398,7 @@ function kubectlJson(args, fallback, context) {
|
||||
|
||||
function condition(item) {
|
||||
const c = (item.status?.conditions || []).find((x) => x.type === 'Succeeded') || {};
|
||||
return { status: c.status || '', reason: c.reason || '' };
|
||||
return { status: c.status || '', reason: c.reason || '', message: c.message || '' };
|
||||
}
|
||||
|
||||
function durationSeconds(start, done) {
|
||||
@@ -523,7 +523,20 @@ function envReuseForPipelineRun(namespace, name) {
|
||||
return state;
|
||||
}
|
||||
|
||||
function taskSummary(taskRuns, name) {
|
||||
function failedStep(item) {
|
||||
const steps = (item.status?.steps || []).map((step) => ({
|
||||
name: step.name || null,
|
||||
container: step.container || null,
|
||||
exitCode: Number.isInteger(step.terminated?.exitCode) ? step.terminated.exitCode : null,
|
||||
reason: step.terminated?.reason || null,
|
||||
terminationReason: step.terminationReason || null,
|
||||
}));
|
||||
return steps.find((step) => step.exitCode !== null && step.exitCode !== 0 && step.terminationReason !== 'Skipped')
|
||||
|| steps.find((step) => step.terminationReason === 'Error')
|
||||
|| null;
|
||||
}
|
||||
|
||||
function taskSummary(taskRuns, name, namespace) {
|
||||
const rows = (taskRuns.items || [])
|
||||
.filter((item) => item.metadata?.labels?.['tekton.dev/pipelineRun'] === name)
|
||||
.map((item) => {
|
||||
@@ -532,19 +545,31 @@ function taskSummary(taskRuns, name) {
|
||||
name: item.metadata?.name || '',
|
||||
status: c.status || null,
|
||||
reason: c.reason || null,
|
||||
message: c.message || null,
|
||||
failedStep: failedStep(item),
|
||||
startTime: item.status?.startTime || null,
|
||||
completionTime: item.status?.completionTime || null,
|
||||
durationSeconds: durationSeconds(item.status?.startTime, item.status?.completionTime),
|
||||
};
|
||||
});
|
||||
const longest = [...rows].sort((a, b) => (b.durationSeconds || 0) - (a.durationSeconds || 0))[0] || null;
|
||||
return { count: rows.length, longest };
|
||||
const failed = rows.find((row) => row.status === 'False') || null;
|
||||
const target = process.env.UNIDESK_PAC_TARGET_ID || '';
|
||||
return {
|
||||
count: rows.length,
|
||||
longest,
|
||||
failed,
|
||||
details: detailId ? rows : undefined,
|
||||
logsCommand: target && namespace
|
||||
? `trans ${target}:k3s logs -n ${namespace} -l tekton.dev/pipelineRun=${name} --all-containers --tail=240`
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
function rowFor(consumer, item, taskRuns) {
|
||||
const params = mapParams(item.spec?.params);
|
||||
const c = condition(item);
|
||||
const tasks = taskSummary(taskRuns, item.metadata.name);
|
||||
const tasks = taskSummary(taskRuns, item.metadata.name, consumer.namespace);
|
||||
const labels = item.metadata?.labels || {};
|
||||
const annotations = item.metadata?.annotations || {};
|
||||
return {
|
||||
@@ -618,7 +643,18 @@ if (!pr) {
|
||||
}
|
||||
function cond(item) {
|
||||
const c = (item.status?.conditions || []).find((x) => x.type === 'Succeeded') || {};
|
||||
return { status: c.status || '', reason: c.reason || '' };
|
||||
return { status: c.status || '', reason: c.reason || '', message: c.message || '' };
|
||||
}
|
||||
function failedStep(item) {
|
||||
const steps = (item.status?.steps || []).map((step) => ({
|
||||
name: step.name || null,
|
||||
exitCode: Number.isInteger(step.terminated?.exitCode) ? step.terminated.exitCode : null,
|
||||
reason: step.terminated?.reason || null,
|
||||
terminationReason: step.terminationReason || null,
|
||||
}));
|
||||
return steps.find((step) => step.exitCode !== null && step.exitCode !== 0 && step.terminationReason !== 'Skipped')
|
||||
|| steps.find((step) => step.terminationReason === 'Error')
|
||||
|| null;
|
||||
}
|
||||
function durationSeconds(item) {
|
||||
const start = item.status?.startTime;
|
||||
@@ -632,7 +668,7 @@ const rows = (data.items || [])
|
||||
.slice(0, 20)
|
||||
.map((item) => {
|
||||
const c = cond(item);
|
||||
return { name: item.metadata.name, pipelineRun: item.metadata.labels?.['tekton.dev/pipelineRun'] || null, status: c.status, reason: c.reason, startTime: item.status?.startTime || null, completionTime: item.status?.completionTime || null, durationSeconds: durationSeconds(item) };
|
||||
return { name: item.metadata.name, pipelineRun: item.metadata.labels?.['tekton.dev/pipelineRun'] || null, status: c.status, reason: c.reason, message: c.message || null, failedStep: failedStep(item), startTime: item.status?.startTime || null, completionTime: item.status?.completionTime || null, durationSeconds: durationSeconds(item) };
|
||||
});
|
||||
process.stdout.write(JSON.stringify(rows));
|
||||
NODE
|
||||
|
||||
Reference in New Issue
Block a user