Skip to content

Commit

Permalink
Merge pull request #1006 from yaacov/jobs-in-plna-vm-list
Browse files Browse the repository at this point in the history
🐾 Add jobs to plans vm list
  • Loading branch information
yaacov authored Mar 21, 2024
2 parents f2872e4 + fb7c8c3 commit 46997d1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
const currentDestinationNet = destinationNetworks.find(
(n) => OpenShiftNetworkAttachmentDefinitionToName(n) == current.destination,
) || { type: 'pod' };
const currentSourceNet = sourceNetworks.find((n) => n.name === current.source);
const currentSourceNet = sourceNetworks.find((n) => n?.name === current.source);

dispatch({
type: 'SET_MAP',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useForkliftTranslation } from 'src/utils/i18n';

import { loadUserSettings, ResourceFieldFactory } from '@kubev2v/common';
import {
IoK8sApiBatchV1Job,
IoK8sApiCoreV1Pod,
MigrationModelGroupVersionKind,
V1beta1Migration,
Expand Down Expand Up @@ -88,7 +89,7 @@ const fieldsMetadataFactory: ResourceFieldFactory = (t) => [
{
resourceFieldId: 'status',
jsonPath: (obj: VMData) => {
const completed = obj.statusVM?.pipeline.filter((p) => p.phase === 'Completed');
const completed = obj.statusVM?.pipeline.filter((p) => p?.phase === 'Completed');

return (completed || []).length;
},
Expand Down Expand Up @@ -142,6 +143,21 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
: (podsDict[p.metadata.labels.vmID] = [p]),
);

const [jobs, jobsLoaded, jobsLoadError] = useK8sWatchResource<IoK8sApiBatchV1Job[]>({
groupVersionKind: { kind: 'Job', group: 'batch', version: 'v1' },
namespaced: true,
isList: true,
namespace: plan?.spec?.targetNamespace,
selector: { matchLabels: { plan: plan?.metadata?.uid } },
});

const jobsDict: Record<string, IoK8sApiBatchV1Job[]> = {};
(jobs && jobsLoaded && !jobsLoadError ? jobs : []).forEach((j) =>
jobsDict[j.metadata.labels.vmID]
? jobsDict[j.metadata.labels.vmID].push(j)
: (jobsDict[j.metadata.labels.vmID] = [j]),
);

const [selectedIds, setSelectedIds] = useState([]);
const [expandedIds, setExpandedIds] = useState([]);
const [userSettings] = useState(() => loadUserSettings({ pageId: 'PlanVirtualMachines' }));
Expand All @@ -157,6 +173,7 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
specVM: m,
statusVM: vmDict[m.id],
pods: podsDict[m.id],
jobs: jobsDict[m.id],
targetNamespace: plan?.spec?.targetNamespace,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const cellRenderers: Record<string, React.FC<PlanVMsCellProps>> = {
return <Timestamp timestamp={value} />;
},
transfer: (props: PlanVMsCellProps) => {
const diskTransfer = props.data.statusVM?.pipeline.find((p) => p.name === 'DiskTransfer');
const diskTransfer = props.data.statusVM?.pipeline.find((p) => p?.name === 'DiskTransfer');
const annotations: { unit: string } = diskTransfer?.annotations as undefined;

return annotations?.unit ? (
Expand All @@ -63,12 +63,12 @@ const cellRenderers: Record<string, React.FC<PlanVMsCellProps>> = {
const pipeline = props.data.statusVM?.pipeline;
let lastRunningItem: V1beta1PlanStatusMigrationVmsPipeline;

if (pipeline[0].phase === 'Pending') {
if (pipeline[0]?.phase === 'Pending') {
lastRunningItem = pipeline[0];
} else if (pipeline[pipeline.length - 1].phase === 'Completed') {
} else if (pipeline[pipeline.length - 1]?.phase === 'Completed') {
lastRunningItem = pipeline[pipeline.length - 1];
} else {
const lastNonePendingIndex = pipeline.findIndex((p) => p.phase === 'Pending') - 1;
const lastNonePendingIndex = pipeline.findIndex((p) => p?.phase === 'Pending') - 1;
lastRunningItem = pipeline[lastNonePendingIndex];
}

Expand All @@ -79,7 +79,7 @@ const cellRenderers: Record<string, React.FC<PlanVMsCellProps>> = {
showClose={false}
alertSeverityVariant={alertSeverityVariant}
headerIcon={getIcon(lastRunningItem)}
headerContent={lastRunningItem.name}
headerContent={lastRunningItem?.name}
bodyContent={
<Table variant="compact">
<Tr onPointerEnterCapture={undefined} onPointerLeaveCapture={undefined}>
Expand Down Expand Up @@ -120,13 +120,13 @@ const cellRenderers: Record<string, React.FC<PlanVMsCellProps>> = {
>
{pipeline.map((p) => (
<ProgressStep
key={p.name}
key={p?.name}
variant={getVariant(p)}
icon={getIcon(p)}
id={p.name}
titleId={p.name}
id={p?.name}
titleId={p?.name}
>
{p.name}
{p?.name}
</ProgressStep>
))}
</ProgressStepper>
Expand Down Expand Up @@ -154,7 +154,7 @@ const getVariant: GetVariantType = (p) => {
return 'danger';
}

switch (p.phase) {
switch (p?.phase) {
case 'Completed':
return 'success';
case 'Pending':
Expand All @@ -171,7 +171,7 @@ const gePopoverVariant: GetPopoverVariantType = (p) => {
return 'danger';
}

switch (p.phase) {
switch (p?.phase) {
case 'Completed':
return 'success';
case 'Pending':
Expand All @@ -187,7 +187,7 @@ const getIcon: GetIconType = (p) => {
return <ResourcesAlmostFullIcon />;
}

switch (p.phase) {
switch (p?.phase) {
case 'Completed':
return <ResourcesFullIcon />;
case 'Pending':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SectionHeading from 'src/components/headers/SectionHeading';
import { useForkliftTranslation } from 'src/utils/i18n';

import { RowProps, TableComposable, Tbody, Td, Th, Thead, Tr } from '@kubev2v/common';
import { V1beta1PlanStatusMigrationVmsPipeline } from '@kubev2v/types';
import { IoK8sApiBatchV1Job, V1beta1PlanStatusMigrationVmsPipeline } from '@kubev2v/types';
import { ResourceLink, Timestamp } from '@openshift-console/dynamic-plugin-sdk';
import Status from '@openshift-console/dynamic-plugin-sdk/lib/app/components/status/Status';
import { Flex, FlexItem, PageSection } from '@patternfly/react-core';
Expand All @@ -21,6 +21,7 @@ export const MigrationVirtualMachinesRowExtended: React.FC<RowProps<VMData>> = (
const pipeline = props.resourceData.statusVM?.pipeline;
const conditions = props.resourceData.statusVM?.conditions;
const pods = props.resourceData.pods;
const jobs = props.resourceData.jobs;
const success = conditions?.find((c) => c.type === 'Succeeded' && c.status === 'True');

const getStatusLabel = (status: string) => {
Expand Down Expand Up @@ -52,7 +53,7 @@ export const MigrationVirtualMachinesRowExtended: React.FC<RowProps<VMData>> = (
version: 'v1',
kind: 'VirtualMachine',
}}
name={props.resourceData.statusVM.name}
name={props.resourceData.statusVM?.name}
namespace={props.resourceData.targetNamespace}
/>
</Td>
Expand Down Expand Up @@ -93,6 +94,37 @@ export const MigrationVirtualMachinesRowExtended: React.FC<RowProps<VMData>> = (
</>
)}

{(jobs || []).length > 0 && (
<>
<SectionHeading
text={'Jobs'}
className="forklift-page-plan-details-vm-status__section-header"
/>
<TableComposable aria-label="Expandable table" variant="compact">
<Tbody>
{(jobs || []).map((job) => (
<Tr key={job.metadata.uid}>
<Td>
<Flex>
<FlexItem>
<ResourceLink
groupVersionKind={{ group: 'batch', version: 'v1', kind: 'Job' }}
name={job?.metadata?.name}
namespace={job?.metadata?.namespace}
/>
</FlexItem>
<FlexItem>
<Status status={getJobPhase(job)}></Status>
</FlexItem>
</Flex>
</Td>
</Tr>
))}
</Tbody>
</TableComposable>
</>
)}

<SectionHeading
text={'Conditions'}
className="forklift-page-plan-details-vm-status__section-header"
Expand Down Expand Up @@ -161,7 +193,7 @@ const getIcon: GetIconType = (p) => {
return <ResourcesAlmostFullIcon color="red" />;
}

switch (p.phase) {
switch (p?.phase) {
case 'Completed':
return <ResourcesFullIcon color="green" />;
case 'Pending':
Expand All @@ -172,3 +204,20 @@ const getIcon: GetIconType = (p) => {
return <ResourcesEmptyIcon color="grey" />;
}
};

const getJobPhase = (job: IoK8sApiBatchV1Job) => {
const conditions = job?.status?.conditions || [];

const conditionFailed = conditions.find((c) => c.type === 'Failed' && c.status === 'True');
const conditionComplete = conditions.find((c) => c.type === 'Complete' && c.status === 'True');

if (conditionFailed) {
return 'Error';
}

if (conditionComplete) {
return 'Complete';
}

return 'Pending';
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const PlanVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) => {
specVM: m,
statusVM: vmDict[m.id],
pods: [],
jobs: [],
targetNamespace: plan?.spec?.targetNamespace,
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
IoK8sApiBatchV1Job,
IoK8sApiCoreV1Pod,
V1beta1PlanSpecVms,
V1beta1PlanStatusMigrationVms,
Expand All @@ -8,5 +9,6 @@ export type VMData = {
specVM: V1beta1PlanSpecVms;
statusVM?: V1beta1PlanStatusMigrationVms;
pods: IoK8sApiCoreV1Pod[];
jobs: IoK8sApiBatchV1Job[];
targetNamespace: string;
};

0 comments on commit 46997d1

Please sign in to comment.