Skip to content

Commit a4b3159

Browse files
Merge pull request #156 from lokanandaprabhu/feature/SRVKP-6363
SRVKP-6363: use TaskRuns `results.tekton.dev/record` annotation to get the logs
2 parents c416771 + 3f8692b commit a4b3159

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

src/components/hooks/useTektonResult.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export const useGetTaskRuns = (
199199
export const useTRTaskRunLog = (
200200
namespace: string,
201201
taskRunName: string,
202+
taskRunPath: string,
202203
): [string, boolean, unknown] => {
203204
const [result, setResult] = React.useState<[string, boolean, unknown]>([
204205
null,
@@ -210,7 +211,7 @@ export const useTRTaskRunLog = (
210211
if (namespace && taskRunName) {
211212
(async () => {
212213
try {
213-
const log = await getTaskRunLog(namespace, taskRunName);
214+
const log = await getTaskRunLog(taskRunPath);
214215
if (!disposed) {
215216
setResult([log, true, undefined]);
216217
}

src/components/logs/TektonTaskRunLog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const TektonTaskRunLog: React.FC<TektonTaskRunLogProps> = ({
2222
const [trResults, trLoaded, trError] = useTRTaskRunLog(
2323
taskRun.metadata.namespace,
2424
taskRun.metadata.name,
25+
taskRun.metadata?.annotations?.['results.tekton.dev/record'],
2526
);
2627

2728
React.useEffect(() => {

src/components/logs/logs-utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type StepsWatchUrl = {
7979
[key: string]: {
8080
name: string;
8181
steps: { [step: string]: WatchURLStatus };
82+
taskRunPath: string;
8283
};
8384
};
8485

@@ -133,6 +134,8 @@ export const getDownloadAllLogsCallback = (
133134
acc[currTask] = {
134135
name: pipelineTaskName,
135136
steps: { ...allStepUrls },
137+
taskRunPath:
138+
taskRun.metadata?.annotations?.['results.tekton.dev/record'],
136139
};
137140
return acc;
138141
}, {});
@@ -167,7 +170,7 @@ export const getDownloadAllLogsCallback = (
167170
}
168171
} else {
169172
// eslint-disable-next-line no-await-in-loop
170-
allLogs += await getTaskRunLog(namespace, currTask).then(
173+
allLogs += await getTaskRunLog(task.taskRunPath).then(
171174
(log) => `${tasks[currTask].name.toUpperCase()}\n\n${log}\n\n`,
172175
);
173176
}

src/components/utils/tekton-results.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ export const NEQ = (left: string, right: string) =>
124124
export enum DataType {
125125
PipelineRun = 'tekton.dev/v1.PipelineRun',
126126
TaskRun = 'tekton.dev/v1.TaskRun',
127-
Log = 'results.tekton.dev/v1alpha2.Log',
128127
}
129128

130129
export const labelsToFilter = (labels?: MatchLabels): string =>
@@ -481,31 +480,14 @@ export const getTRURLHost = async () => {
481480
return route?.spec.host;
482481
};
483482

484-
const getLog = async (taskRunPath: string) => {
483+
export const getTaskRunLog = async (taskRunPath: string): Promise<string> => {
484+
if (!taskRunPath) {
485+
throw404();
486+
}
485487
const tektonResultsAPI = await getTektonResultsAPIUrl();
486488
const url = `https://${tektonResultsAPI}/apis/results.tekton.dev/v1alpha2/parents/${taskRunPath.replace(
487489
'/records/',
488490
'/logs/',
489491
)}`;
490492
return consoleProxyFetchLog({ url, method: 'GET', allowInsecure: true });
491493
};
492-
493-
export const getTaskRunLog = (
494-
namespace: string,
495-
taskRunName: string,
496-
): Promise<string> =>
497-
getFilteredRecord<any>(
498-
namespace,
499-
DataType.Log,
500-
AND(
501-
EQ(`data.spec.resource.kind`, 'TaskRun'),
502-
EQ(`data.spec.resource.name`, taskRunName),
503-
),
504-
{ limit: 1 },
505-
).then((x) =>
506-
x?.[1]?.records.length > 0
507-
? getLog(x?.[1]?.records[0].name).then((response: string) => {
508-
return response;
509-
})
510-
: throw404(),
511-
);

0 commit comments

Comments
 (0)