From 83e44a825f9fa3adfc74cd6b019d8035303437ea 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 deleted record out --- src/utils/__tests__/tekton-results.spec.ts | 22 ++++++++++++---- src/utils/tekton-results.ts | 29 +++++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/utils/__tests__/tekton-results.spec.ts b/src/utils/__tests__/tekton-results.spec.ts index 327b115..a8c3de6 100644 --- a/src/utils/__tests__/tekton-results.spec.ts +++ b/src/utils/__tests__/tekton-results.spec.ts @@ -51,18 +51,30 @@ const mockRecordsList = { }, { data: { - // {"key":"test2"} - value: 'eyJrZXkiOiJ0ZXN0MiJ9', + // {"status":{"conditions":[{"status":"Unknown","type":"Succeeded","reason":"Running"}]}} + value: + 'eyJzdGF0dXMiOnsiY29uZGl0aW9ucyI6W3sic3RhdHVzIjoiVW5rbm93biIsInR5cGUiOiJTdWNjZWVkZWQiLCJyZWFzb24iOiJSdW5uaW5nIn1dfX0=', }, }, ], } as RecordsList; -const mockResponseCheck = [[{ key: 'test1' }, { key: 'test2' }], mockRecordsList] as [ +const mockResponseCheck = [ + [ + { key: 'test1' }, + { + status: { + conditions: [{ status: 'Unknown', reason: 'Running', type: 'Succeeded' }], + }, + }, + ], + mockRecordsList, +] as [unknown[], RecordsList]; + +const mockPipelineRunReponseCheck = [[{ key: 'test1' }], mockRecordsList] as [ unknown[], RecordsList, ]; - const mockLogsRecordsList = { nextPageToken: null, records: [ @@ -551,7 +563,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..0a10485 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], @@ -304,6 +304,29 @@ const getFilteredPipelineRuns = ( cacheKey, ); + /* + When pipelineruns are running, the etcd would keep their results. + While the tekton record would keep the conditions as: + "conditions": [ + { + "type": "Unknown", + "reason": "Succeeded", + "status": "Running", + ... + Deleting pipelines from etcd makes the tekton record would be never updated as others. + So for those tekton results, it is useless to users and we need to filter them out. + Otherwise, these jobs would be always shown as 'Running' and bring unexpected troubles. + */ + const filteredPipelineRuns = originalPipelineRuns.filter((pipelinerun) => { + return ( + pipelinerun.status?.conditions?.every( + (c) => !(c.status === 'Unknown' && c.type === 'Succeeded' && c.reason === 'Running'), + ) ?? true + ); + }); + return [filteredPipelineRuns, list]; +}; + const getFilteredTaskRuns = ( workspace: string, namespace: string,