From ba7ebef2fd37a2fcbc0a9ce4f2878b63feb7ddbd Mon Sep 17 00:00:00 2001 From: yzamir Date: Mon, 8 Apr 2024 11:57:16 +0300 Subject: [PATCH] Fix source OCP storage mapping Signed-off-by: yzamir --- .../views/migrate/reducer/reducer.ts | 10 ++++++ .../components/MapsSection/MapsSection.tsx | 36 ++++++++++++------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/reducer/reducer.ts b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/reducer/reducer.ts index 4559669c3..58afea630 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/reducer/reducer.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/reducer/reducer.ts @@ -330,6 +330,7 @@ const handlers: { }, [START_CREATE]({ flow, + receivedAsParams: { sourceProvider }, underConstruction: { plan, netMap, storageMap }, calculatedOnce: { sourceNetworkLabelToId, sourceStorageLabelToId }, calculatedPerNamespace: { networkMappings, storageMappings }, @@ -349,6 +350,15 @@ const handlers: { : { name: destination, namespace: plan.spec.targetNamespace, type: 'multus' }, })); storageMap.spec.map = storageMappings.map(({ source, destination }) => { + if (sourceProvider?.spec?.type === 'openshift') { + return { + source: { + name: source.replace(/^\//g, ''), + }, + destination: { storageClass: destination }, + }; + } + if (source === 'glance') { return { source: { diff --git a/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx b/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx index 254aa9ed9..16c676d92 100644 --- a/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx +++ b/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx @@ -67,7 +67,7 @@ export const MapsSection: React.FC = ({ obj }) => { const availableSources = sourceStorages?.filter((n) => !isStorageMapped(n?.id)); - const getInventoryStorageName = (id: string) => sourceStorages.find((s) => s.id === id)?.name; + const getInventoryStorageName = (id: string) => sourceStorages?.find((s) => s.id === id)?.name; const onAdd = () => availableSources.length > 0 && @@ -75,10 +75,15 @@ export const MapsSection: React.FC = ({ obj }) => { type: 'SET_MAP', payload: [ ...(state.StorageMap?.spec?.map || []), - { - source: availableSources[0], - destination: { storageClass: destinationStorages?.[0].name }, - }, + sourceProvider?.spec?.type === 'openshift' + ? { + source: { name: availableSources?.[0]?.name }, + destination: { storageClass: destinationStorages?.[0].name }, + } + : { + source: { id: availableSources?.[0]?.id }, + destination: { storageClass: destinationStorages?.[0].name }, + }, ], }); @@ -86,20 +91,26 @@ export const MapsSection: React.FC = ({ obj }) => { const currentDestinationStorage = destinationStorages.find( (n) => n.name == current.destination, ); - const currentSourceStorage = sourceStorages.find((n) => n?.name === current.source); + const currentSourceStorage = sourceStorages?.find((n) => n?.name === current.source); const nextDestinationStorage = destinationStorages.find((n) => n.name == next.destination); - const nextSourceStorage = sourceStorages.find((n) => n?.name === next.source); + const nextSourceStorage = sourceStorages?.find((n) => n?.name === next.source); // sanity check, names may not be valid if (!nextSourceStorage || !nextDestinationStorage) { return; } - const nextMap: V1beta1StorageMapSpecMap = { - source: { id: nextSourceStorage.id }, - destination: { storageClass: nextDestinationStorage.name }, - }; + const nextMap: V1beta1StorageMapSpecMap = + sourceProvider?.spec?.type === 'openshift' + ? { + source: { name: nextSourceStorage.name }, + destination: { storageClass: nextDestinationStorage.name }, + } + : { + source: { id: nextSourceStorage.id }, + destination: { storageClass: nextDestinationStorage.name }, + }; const payload = state?.StorageMap?.spec?.map?.map((map) => { return map?.source?.id === currentSourceStorage?.id && @@ -116,7 +127,7 @@ export const MapsSection: React.FC = ({ obj }) => { const onDelete = (current: Mapping) => { const references = storageNameToIDReference(state?.StorageMap?.status?.references || []); - const currentSourceStorage = sourceStorages.find((n) => n.name === current.source); + const currentSourceStorage = sourceStorages?.find((n) => n.name === current.source); dispatch({ type: 'SET_MAP', @@ -125,6 +136,7 @@ export const MapsSection: React.FC = ({ obj }) => { (map) => !( (map?.source?.id === currentSourceStorage?.id || + map?.source?.name === current.source || map?.source?.id === references[current.source]) && map.destination?.storageClass === current.destination ),