From 7c5062b3a5c73dc0fcdd0bd4b0fdcbcf8cbd5f5c Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Fri, 13 Dec 2024 21:43:46 +0800 Subject: [PATCH] fix(KFLUXUI-253): tekton results should filter unknown status record out --- src/utils/__tests__/tekton-results.spec.ts | 15 ++++++++++----- src/utils/tekton-results.ts | 14 +++++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/utils/__tests__/tekton-results.spec.ts b/src/utils/__tests__/tekton-results.spec.ts index 327b115..0776e06 100644 --- a/src/utils/__tests__/tekton-results.spec.ts +++ b/src/utils/__tests__/tekton-results.spec.ts @@ -51,18 +51,23 @@ 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: [ @@ -551,7 +556,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 () => { diff --git a/src/utils/tekton-results.ts b/src/utils/tekton-results.ts index 8b95771..a91b21c 100644 --- a/src/utils/tekton-results.ts +++ b/src/utils/tekton-results.ts @@ -286,15 +286,15 @@ export const getFilteredRecord = async ( return value; }; -const getFilteredPipelineRuns = ( +const getFilteredPipelineRuns = async ( workspace: string, namespace: string, filter: string, options?: TektonResultsOptions, nextPageToken?: string, cacheKey?: string, -) => - getFilteredRecord( +): Promise<[PipelineRunKindV1Beta1[], RecordsList]> => { + const [originalPipelineRuns, list] = await getFilteredRecord( workspace, namespace, [DataType.PipelineRun, DataType.PipelineRun_v1beta1], @@ -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,