diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx index e0e60fa75..df7a1aab7 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx @@ -8,6 +8,7 @@ import { FlexItem, Popover, ProgressStep, ProgressStepper } from '@patternfly/re import { ResourcesAlmostFullIcon, ResourcesFullIcon } from '@patternfly/react-icons'; import { Table, Tr } from '@patternfly/react-table'; +import { isTaskCompletedByItsPipeline } from '../../../utils'; import { PlanVMsCellProps } from '../components'; import { NameCellRenderer } from '../components/NameCellRenderer'; import { VMData } from '../types'; @@ -222,7 +223,11 @@ const countTasks = (diskTransfer: V1beta1PlanStatusMigrationVmsPipeline) => { } const totalTasks = diskTransfer.tasks.length; - const completedTasks = diskTransfer.tasks.filter((task) => task.phase === 'Completed').length; + + // search num of completed tasks (either tasks that completed successfully or ones that aren't finished but their pipeline step is). + const completedTasks = diskTransfer.tasks.filter( + (task) => task.phase === 'Completed' || isTaskCompletedByItsPipeline(task.phase, diskTransfer), + ).length; return { totalTasks, completedTasks }; }; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx index 86cf9466e..02c398d7e 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx @@ -26,6 +26,7 @@ import { } from '@patternfly/react-core'; import { TaskIcon } from '@patternfly/react-icons'; +import { isTaskCompletedByItsPipeline } from '../../../utils'; import { PipelineTasksModal } from '../modals'; import { VMData } from '../types'; @@ -352,7 +353,11 @@ const getJobPhase = (job: IoK8sApiBatchV1Job) => { const getPipelineTasks = (pipeline: V1beta1PlanStatusMigrationVmsPipeline) => { const tasks = pipeline?.tasks || []; - const tasksCompleted = tasks.filter((c) => c.phase === 'Completed'); + + // search for all completed tasks (either tasks that completed successfully or ones that aren't finished but their pipeline step is). + const tasksCompleted = tasks.filter( + (c) => c.phase === 'Completed' || isTaskCompletedByItsPipeline(c.phase, pipeline), + ); return { total: tasks.length, completed: tasksCompleted.length, name: pipeline.name }; }; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx new file mode 100644 index 000000000..3001c7a60 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx @@ -0,0 +1,34 @@ +import { V1beta1PlanStatusMigrationVmsPipeline } from '@kubev2v/types'; + +/** + * Check if a given migration's pipeline step has completed successfully. + * + * @param {V1beta1PlanStatusMigrationVmsPipeline} pipeline - A given migration's pipeline step + * @returns {boolean} - True if the migration step has completed successfully, false otherwise. + */ +const hasPipelineCompleted = (pipeline: V1beta1PlanStatusMigrationVmsPipeline) => { + if (pipeline?.error) { + return false; + } + + switch (pipeline?.phase) { + case 'Completed': + return true; + case 'Pending': + case 'Running': + default: + return false; + } +}; + +/** + * Check if the task isn't marked as finished, but its contained pipeline step has completed successfully. + * + * @param {string } taskPhase A given task phase + * @param {V1beta1PlanStatusMigrationVmsPipeline} pipeline - A given migration's pipeline step which includes the task + * @returns {boolean} - Returns True if the task isn't marked as finished, but its contained pipeline step has completed successfully. + */ +export const isTaskCompletedByItsPipeline = ( + taskPhase: string, + pipeline: V1beta1PlanStatusMigrationVmsPipeline, +) => taskPhase === undefined && hasPipelineCompleted(pipeline); diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts index 01f07bcea..381ea7d02 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts @@ -4,6 +4,7 @@ export * from './constants'; export * from './getInventoryApiUrl'; export * from './getValueByJsonPath'; export * from './hasObjectChangedInGivenFields'; +export * from './hasPipelineCompleted'; export * from './hasPlanEditable'; export * from './hasPlanMappingsChanged'; export * from './mapMappingsIdsToLabels';