Skip to content

Commit

Permalink
fix(KFLUXUI-253): tekton results should filter unknown status record out
Browse files Browse the repository at this point in the history
  • Loading branch information
testcara committed Dec 16, 2024
1 parent 61e9ed9 commit 0b59a41
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/utils/__tests__/tekton-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ const mockRecordsList = {
},
{
data: {
// {"key":"test2"}
value: 'eyJrZXkiOiJ0ZXN0MiJ9',
// {"status":{"conditions":[{"status":"Unknown"},{"status":"Failed"}]}}
value:
'eyJzdGF0dXMiOnsiY29uZGl0aW9ucyI6W3sic3RhdHVzIjoiVW5rbm93biJ9LHsic3RhdHVzIjoiRmFpbGVkIn1dfX0K',
},
},
],
} as RecordsList;

const mockResponseCheck = [[{ key: 'test1' }, { key: 'test2' }], mockRecordsList] as [
const mockResponseCheck = [
[{ key: 'test1' }, { status: { conditions: [{ status: 'Unknown' }, { status: 'Failed' }] } }],
mockRecordsList,
] as [unknown[], RecordsList];
const mockPipelineRunReponseCheck = [[{ key: 'test1' }], mockRecordsList] as [
unknown[],
RecordsList,
];

const mockLogsRecordsList = {
nextPageToken: null,
records: [
Expand Down Expand Up @@ -551,7 +555,7 @@ describe('tekton-results', () => {
describe('getPipelineRuns', () => {
it('should return record list and decoded value', async () => {
commonFetchJSONMock.mockReturnValue(mockRecordsList);
expect(await getPipelineRuns('test-ws', 'test-ns')).toEqual(mockResponseCheck);
expect(await getPipelineRuns('test-ws', 'test-ns')).toEqual(mockPipelineRunReponseCheck);
});

it('should query tekton results with options', async () => {
Expand Down
14 changes: 11 additions & 3 deletions src/utils/tekton-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ export const getFilteredRecord = async <R extends K8sResourceCommon>(
return value;
};

const getFilteredPipelineRuns = (
const getFilteredPipelineRuns = async (
workspace: string,
namespace: string,
filter: string,
options?: TektonResultsOptions,
nextPageToken?: string,
cacheKey?: string,
) =>
getFilteredRecord<PipelineRunKindV1Beta1>(
): Promise<[PipelineRunKindV1Beta1[], RecordsList]> => {
const [originalPipelineRuns, list] = await getFilteredRecord<PipelineRunKindV1Beta1>(
workspace,
namespace,
[DataType.PipelineRun, DataType.PipelineRun_v1beta1],
Expand All @@ -303,6 +303,14 @@ const getFilteredPipelineRuns = (
nextPageToken,
cacheKey,
);
// When pipelines are running, the etcd would keep their results.
// deleting pipelines frome ectd would make unknown tekton results.
// Just to get meaningful test runs, we need to filter 'unknown' out.
const filteredPipelineRuns = originalPipelineRuns.filter((pipelinerun) => {
return pipelinerun.status?.conditions?.every((c) => c.status !== 'Unknown') ?? true;
});
return [filteredPipelineRuns, list];
};

const getFilteredTaskRuns = (
workspace: string,
Expand Down

0 comments on commit 0b59a41

Please sign in to comment.