Skip to content

Commit

Permalink
Merge pull request #13614 from Lucifergene/OCPBUGS-29513-PLR-Custom-S…
Browse files Browse the repository at this point in the history
…tatus

OCPBUGS-29513: Update the Pipeline List and Details Pages to acknowledge Custom Task
  • Loading branch information
openshift-merge-bot[bot] committed Mar 11, 2024
2 parents 77d383d + be338ae commit 03cecd0
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
"No workspaces are associated with this pipeline.": "No workspaces are associated with this pipeline.",
"{{triggerBindingLabel}} details": "{{triggerBindingLabel}} details",
"TriggerTemplate details": "TriggerTemplate details",
"Approval Task": "Approval Task",
"Custom Task": "Custom Task",
"Embedded task": "Embedded task",
"Embedded PipelineResource": "Embedded PipelineResource",
"Embedded Pipeline": "Embedded Pipeline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,26 @@ export const getPipelineTaskLinks = (pipeline: PipelineKind): PipelineTaskLinks
if (!tasks) return [];
return tasks?.map((task) =>
task.taskRef
? {
resourceKind: getSafeTaskResourceKind(task.taskRef.kind),
name: task.taskRef.name,
qualifier: task.name,
}
? task.taskRef.kind === 'ClusterTask' || task.taskRef.kind === 'Task'
? {
resourceKind: getSafeTaskResourceKind(task.taskRef.kind),
name: task.taskRef.name,
qualifier: task.name,
}
: {
resourceKind: task.taskRef?.kind,
name:
task.taskRef?.kind === 'ApprovalTask'
? i18next.t('pipelines-plugin~Approval Task')
: i18next.t('pipelines-plugin~Custom Task'),
qualifier: task.name,
disableLink: true,
}
: {
resourceKind: 'EmbeddedTask',
name: i18next.t('pipelines-plugin~Embedded task'),
qualifier: task.name,
disableLink: true,
},
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type ResourceModelLink = {
resourceKind: string;
name: string;
qualifier?: string;
disableLink?: boolean;
};

type DynamicResourceLinkListProps = {
Expand Down Expand Up @@ -35,10 +36,10 @@ const DynamicResourceLinkList: React.FC<DynamicResourceLinkListProps> = ({
<dl>
{title && <dt>{title}</dt>}
<dd>
{links.map(({ name, resourceKind, qualifier = '' }) => {
let linkName = name;
{links.map(({ name, resourceKind, qualifier = '', disableLink = false }) => {
let linkName = qualifier;
if (qualifier?.length > 0 && name !== qualifier) {
linkName += ` (${qualifier})`;
linkName += ` (${name})`;
}
return (
<div key={`${resourceKind}/${linkName}`}>
Expand All @@ -47,6 +48,7 @@ const DynamicResourceLinkList: React.FC<DynamicResourceLinkListProps> = ({
resourceName={name}
displayName={linkName}
namespace={namespace}
disableLink={disableLink}
/>
</div>
);
Expand Down
126 changes: 104 additions & 22 deletions frontend/packages/pipelines-plugin/src/test-data/pipeline-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export enum PipelineExampleNames {
EMBEDDED_PIPELINE_SPEC = 'embedded-pipeline-spec',
PIPELINE_WITH_FINALLY = 'pipeline-with-finally',
RESULTS = 'results-pipeline',
CUSTOM_TASK_PIPELINE = 'custom-task-pipeline',
}

type CombinedPipelineTestData = {
Expand All @@ -54,42 +55,88 @@ const pipelineSpec: PipelineSpecData = {
tasks: [
{
name: 'hello-world-1',
taskRef: { name: 'hello-world-1' },
taskRef: { kind: 'Task', name: 'hello-world-1' },
},
{
name: 'hello-world-truncate-more-than-20-char',
taskRef: { name: 'hello-world-truncate-more-than-20-char' },
taskRef: { kind: 'Task', name: 'hello-world-truncate-more-than-20-char' },
},
],
},
[PipelineExampleNames.PARTIAL_PIPELINE]: {
tasks: [
{ name: 'hello-world-1', taskRef: { name: 'hello-world-1' } },
{ name: 'hello-world-1', taskRef: { kind: 'Task', name: 'hello-world-1' } },
{
name: 'hello-world-truncate-more-than-20-char',
taskRef: { name: 'hello-world-truncate-more-than-20-char' },
taskRef: { kind: 'Task', name: 'hello-world-truncate-more-than-20-char' },
},
{ name: 'hello-world-3', taskRef: { name: 'hello-world-3' } },
{ name: 'hello-world-3', taskRef: { kind: 'Task', name: 'hello-world-3' } },
],
},
[PipelineExampleNames.CUSTOM_TASK_PIPELINE]: {
tasks: [
{ name: 'hello-world-1', taskRef: { kind: 'Task', name: 'hello-world-1' } },
{
name: 'hello-world-custom-task-2',
taskRef: { kind: 'ApprovalTask', name: 'hello-world-custom-task-2' },
},
{ name: 'hello-world-3', taskRef: { kind: 'Task', name: 'hello-world-3' } },
],
},
[PipelineExampleNames.COMPLEX_PIPELINE]: {
tasks: [
{ name: 'build-app', taskRef: { name: 'noop-task' } },
{ name: 'analyse-code', runAfter: ['build-app'], taskRef: { name: 'noop-task' } },
{ name: 'style-checks', runAfter: ['build-app'], taskRef: { name: 'noop-task' } },
{ name: 'find-bugs', runAfter: ['build-app'], taskRef: { name: 'noop-task' } },
{ name: 'build-app', taskRef: { kind: 'Task', name: 'noop-task' } },
{
name: 'analyse-code',
runAfter: ['build-app'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'style-checks',
runAfter: ['build-app'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{ name: 'find-bugs', runAfter: ['build-app'], taskRef: { kind: 'Task', name: 'noop-task' } },
{
name: 'build-image',
runAfter: ['find-bugs', 'style-checks', 'analyse-code'],
taskRef: { name: 'noop-task' },
},
{ name: 'deploy-image', runAfter: ['build-image'], taskRef: { name: 'noop-task' } },
{ name: 'test-suite-1', runAfter: ['deploy-image'], taskRef: { name: 'noop-task' } },
{ name: 'test-suite-2', runAfter: ['deploy-image'], taskRef: { name: 'noop-task' } },
{ name: 'test-suite-3', runAfter: ['deploy-image'], taskRef: { name: 'noop-task' } },
{ name: 'test-suite-4', runAfter: ['deploy-image'], taskRef: { name: 'noop-task' } },
{ name: 'test-suite-5', runAfter: ['deploy-image'], taskRef: { name: 'noop-task' } },
{ name: 'test-suite-6', runAfter: ['deploy-image'], taskRef: { name: 'noop-task' } },
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'deploy-image',
runAfter: ['build-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'test-suite-1',
runAfter: ['deploy-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'test-suite-2',
runAfter: ['deploy-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'test-suite-3',
runAfter: ['deploy-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'test-suite-4',
runAfter: ['deploy-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'test-suite-5',
runAfter: ['deploy-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'test-suite-6',
runAfter: ['deploy-image'],
taskRef: { kind: 'Task', name: 'noop-task' },
},
{
name: 'verify',
runAfter: [
Expand All @@ -100,7 +147,7 @@ const pipelineSpec: PipelineSpecData = {
'test-suite-5',
'test-suite-6',
],
taskRef: { name: 'noop-task' },
taskRef: { kind: 'Task', name: 'noop-task' },
},
],
finally: [],
Expand Down Expand Up @@ -388,17 +435,17 @@ const pipelineSpec: PipelineSpecData = {
tasks: [
{
name: 'hello-world-1',
taskRef: { name: 'hello-world-1' },
taskRef: { kind: 'Task', name: 'hello-world-1' },
},
{
name: 'hello-world-2',
taskRef: { name: 'hello-world-2' },
taskRef: { kind: 'Task', name: 'hello-world-2' },
},
],
finally: [
{
name: 'run-anyway',
taskRef: { name: 'run-anyway' },
taskRef: { kind: 'Task', name: 'run-anyway' },
},
],
},
Expand Down Expand Up @@ -733,6 +780,41 @@ export const pipelineTestData: PipelineTestData = {
},
},
},
[PipelineExampleNames.CUSTOM_TASK_PIPELINE]: {
dataSource: 'custom-task-pipeline',
pipeline: {
apiVersion: 'tekton.dev/v1alpha1',
kind: 'Pipeline',
metadata: {
name: 'custom-task-pipeline',
namespace: 'tekton-pipelines',
},
spec: pipelineSpec[PipelineExampleNames.CUSTOM_TASK_PIPELINE],
},
pipelineRuns: {
[DataState.PIPELINE_RUN_PENDING]: {
apiVersion: 'tekton.dev/v1alpha1',
kind: 'PipelineRun',
metadata: {
name: 'custom-task-pipeline-3tt7aw',
namespace: 'tekton-pipelines',
labels: { [TektonResourceLabel.pipeline]: 'custom-task-pipeline' },
},
spec: {
pipelineRef: { name: 'custom-task-pipeline' },
},
status: {
pipelineSpec: pipelineSpec[PipelineExampleNames.CUSTOM_TASK_PIPELINE],
conditions: [
{
status: 'True',
type: 'Succeeded',
},
],
},
},
},
},
[PipelineExampleNames.COMPLEX_PIPELINE]: {
dataSource: 'complex-pipeline',
pipeline: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getResourceModelFromBindingKind,
shouldHidePipelineRunStop,
shouldHidePipelineRunCancel,
totalPipelineRunCustomTasks,
} from '../pipeline-augment';
import { testData } from './pipeline-augment-test-data';

Expand Down Expand Up @@ -503,3 +504,17 @@ describe('getResourceModelFromBindingKind', () => {
expect(getResourceModelFromBindingKind('Nothing special')).toBe(null);
});
});

describe('PipelineAugment test correct task status state is shown when there is custom tasks', () => {
it('should not count custom tasks in TaskStatus', () => {
const customTaskPipeline = pipelineTestData[PipelineExampleNames.CUSTOM_TASK_PIPELINE];
const taskStatus = getTaskStatus(
customTaskPipeline.pipelineRuns[DataState.PIPELINE_RUN_PENDING],
customTaskPipeline.pipeline,
[],
);
const totalTasks = totalPipelineRunTasks(customTaskPipeline.pipeline);
const customTaskCount = totalPipelineRunCustomTasks(customTaskPipeline.pipeline);
expect(taskStatus.Pending).toEqual(totalTasks - customTaskCount);
});
});
17 changes: 16 additions & 1 deletion frontend/packages/pipelines-plugin/src/utils/pipeline-augment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,27 @@ export const totalPipelineRunTasks = (executedPipeline: PipelineKind): number =>
return totalTasks + finallyTasks;
};

export const totalPipelineRunCustomTasks = (executedPipeline: PipelineKind): number => {
if (!executedPipeline) {
return 0;
}
const totalCustomTasks =
(executedPipeline.spec?.tasks || []).filter(
(task) => task.taskRef?.kind !== 'Task' && task.taskRef?.kind !== 'ClusterTask',
).length ?? 0;
const finallyCustomTasks =
(executedPipeline.spec?.finally || []).filter(
(task) => task.taskRef?.kind !== 'Task' && task.taskRef?.kind !== 'ClusterTask',
).length ?? 0;
return totalCustomTasks + finallyCustomTasks;
};

export const getTaskStatus = (
pipelinerun: PipelineRunKind,
pipeline: PipelineKind,
taskRuns: TaskRunKind[],
): TaskStatus => {
const totalTasks = totalPipelineRunTasks(pipeline);
const totalTasks = totalPipelineRunTasks(pipeline) - totalPipelineRunCustomTasks(pipeline);
const plrTasks = (): string[] => {
if (pipelinerun?.status?.taskRuns) {
return Object.keys(pipelinerun.status.taskRuns);
Expand Down

0 comments on commit 03cecd0

Please sign in to comment.