forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tekton): add support for downloading task and pipelinerun logs (j…
…anus-idp#1014) * feat(tekton): add support for downloading task and pipelinerun logs * add unit tests * refactor code and add more unit tests * add logs streaming in dev mode
- Loading branch information
1 parent
2e4a6ad
commit f588292
Showing
20 changed files
with
723 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../topology/src/utils/pod-log-utils.test.ts → .../utils/downloader/logs-downloader.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './date'; | ||
export * from './pipeline'; | ||
export * from './unit-conversion'; | ||
export * from './downloader/logs-downloader'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { V1Pod } from '@kubernetes/client-node'; | ||
|
||
import { PipelineRunKind } from '@janus-idp/shared-react'; | ||
|
||
export const testPipelineRun: PipelineRunKind = { | ||
apiVersion: 'tekton.dev/v1', | ||
kind: 'PipelineRun', | ||
metadata: { | ||
name: 'test-pipeline-8e09zm', | ||
uid: '17080e46-1ff6-4f15-99e9-e32f603d7cc8', | ||
creationTimestamp: new Date('2023-12-12T06:38:29Z'), | ||
labels: { | ||
'backstage.io/kubernetes-id': 'developer-portal', | ||
'janus-idp.io/tekton': 'developer-portal', | ||
'tekton.dev/build-namespace': 'karthik', | ||
'tekton.dev/pipeline': 'new-pipeline', | ||
}, | ||
}, | ||
spec: { | ||
pipelineRef: { | ||
name: 'new-pipeline', | ||
}, | ||
}, | ||
status: { | ||
completionTime: '2023-12-12T06:39:12Z', | ||
pipelineSpec: { tasks: [] }, | ||
conditions: [ | ||
{ | ||
lastTransitionTime: '2023-12-12T06:39:12Z', | ||
message: 'Tasks Completed: 3 (Failed: 0, Cancelled 0), Skipped: 0', | ||
reason: 'Succeeded', | ||
status: 'True', | ||
type: 'Succeeded', | ||
}, | ||
], | ||
startTime: '2023-12-12T06:38:29Z', | ||
}, | ||
}; | ||
|
||
export const testPods: V1Pod[] = [ | ||
{ | ||
metadata: { | ||
name: 'test-pipeline-8e09zm-task1-pod', | ||
namespace: 'karthik', | ||
uid: 'bd868fde-1b37-4168-a780-f1772c5924e3', | ||
resourceVersion: '379524', | ||
labels: { | ||
'app.kubernetes.io/managed-by': 'tekton-pipelines', | ||
'backstage.io/kubernetes-id': 'developer-portal', | ||
'janus-idp.io/tekton': 'developer-portal', | ||
'tekton.dev/clusterTask': 'tkn', | ||
'tekton.dev/memberOf': 'tasks', | ||
'tekton.dev/pipeline': 'test-pipeline', | ||
'tekton.dev/pipelineRun': 'test-pipeline-8e09zm', | ||
'tekton.dev/pipelineTask': 'task1', | ||
'tekton.dev/taskRun': 'test-pipeline-8e09zm-task1', | ||
}, | ||
}, | ||
spec: { | ||
volumes: [ | ||
{ | ||
name: 'tekton-internal-workspace', | ||
emptyDir: {}, | ||
}, | ||
], | ||
containers: [ | ||
{ | ||
name: 'step-tkn', | ||
}, | ||
], | ||
}, | ||
status: { | ||
phase: 'Succeeded', | ||
conditions: [], | ||
startTime: new Date('2023-12-08T12:19:29Z'), | ||
}, | ||
}, | ||
{ | ||
metadata: { | ||
name: 'test-pipeline-8e09zm-sbom-task-pod', | ||
namespace: 'karthik', | ||
uid: '055cc13a-bd3e-414e-9eb6-e6cb72870578', | ||
resourceVersion: '379623', | ||
labels: { | ||
'backstage.io/kubernetes-id': 'developer-portal', | ||
'janus-idp.io/tekton': 'developer-portal', | ||
'tekton.dev/pipeline': 'test-pipeline', | ||
'tekton.dev/pipelineRun': 'test-pipeline-8e09zm', | ||
'tekton.dev/pipelineTask': 'sbom-task', | ||
'tekton.dev/task': 'sbom-task', | ||
'tekton.dev/taskRun': 'test-pipeline-8e09zm-sbom-task', | ||
}, | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: 'step-print-sbom-results', | ||
}, | ||
], | ||
}, | ||
status: { | ||
phase: 'Succeeded', | ||
conditions: [], | ||
|
||
startTime: new Date('2023-12-08T12:19:38Z'), | ||
}, | ||
}, | ||
]; | ||
|
||
export const testPipelineRunPods: { | ||
pipelineRun: PipelineRunKind; | ||
pods: V1Pod[]; | ||
} = { | ||
pipelineRun: testPipelineRun, | ||
pods: testPods, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
plugins/tekton/src/components/PipelineRunLogs/PipelineRunLogDownloader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
|
||
import { V1Pod } from '@kubernetes/client-node'; | ||
import { Flex, FlexItem } from '@patternfly/react-core'; | ||
|
||
import { PipelineRunKind } from '@janus-idp/shared-react'; | ||
|
||
import { | ||
TEKTON_PIPELINE_RUN, | ||
TEKTON_PIPELINE_TASK, | ||
TEKTON_PIPELINE_TASKRUN, | ||
} from '../../consts/tekton-const'; | ||
import PodLogsDownloadLink from './PodLogsDownloadLink'; | ||
|
||
const PipelineRunLogDownloader: React.FC<{ | ||
pods: V1Pod[]; | ||
pipelineRun: PipelineRunKind; | ||
activeTask: string | undefined; | ||
}> = ({ pods, pipelineRun, activeTask }) => { | ||
const filteredPods: V1Pod[] = pods?.filter( | ||
(p: V1Pod) => | ||
p?.metadata?.labels?.[TEKTON_PIPELINE_RUN] === | ||
pipelineRun?.metadata?.name, | ||
); | ||
|
||
const sortedPods: V1Pod[] = React.useMemo( | ||
() => | ||
Array.from(filteredPods)?.sort( | ||
(a: V1Pod, b: V1Pod) => | ||
new Date(a?.status?.startTime as Date).getTime() - | ||
new Date(b?.status?.startTime as Date).getTime(), | ||
), | ||
[filteredPods], | ||
); | ||
|
||
const activeTaskPod: V1Pod = | ||
sortedPods.find( | ||
(sp: V1Pod) => | ||
sp.metadata?.labels?.[TEKTON_PIPELINE_TASKRUN] === activeTask, | ||
) ?? sortedPods[sortedPods.length - 1]; | ||
|
||
return sortedPods.length > 0 ? ( | ||
<Flex | ||
data-testid="pipelinerun-logs-downloader" | ||
justifyContent={{ default: 'justifyContentFlexEnd' }} | ||
> | ||
<FlexItem> | ||
<PodLogsDownloadLink | ||
data-testid="download-task-logs" | ||
pods={activeTaskPod ? [activeTaskPod] : []} | ||
fileName={`${ | ||
activeTaskPod?.metadata?.labels?.[TEKTON_PIPELINE_TASK] ?? 'task' | ||
}.log`} | ||
downloadTitle="Download" | ||
/> | ||
</FlexItem> | ||
<FlexItem> | ||
<PodLogsDownloadLink | ||
data-testid="download-pipelinerun-logs" | ||
pods={sortedPods} | ||
fileName={`${pipelineRun?.metadata?.name ?? 'pipelinerun'}.log`} | ||
downloadTitle="Download all tasks logs" | ||
/> | ||
</FlexItem> | ||
</Flex> | ||
) : null; | ||
}; | ||
export default PipelineRunLogDownloader; |
Oops, something went wrong.