Skip to content

Commit 414b1bb

Browse files
authored
Merge pull request #1077 from yaacov/fix-source-ocp-storage-mapping
🐞 Fix source OCP storage mapping
2 parents c0e66ed + ba7ebef commit 414b1bb

File tree

2 files changed

+34
-12
lines changed
  • packages/forklift-console-plugin/src/modules

2 files changed

+34
-12
lines changed

packages/forklift-console-plugin/src/modules/Providers/views/migrate/reducer/reducer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ const handlers: {
330330
},
331331
[START_CREATE]({
332332
flow,
333+
receivedAsParams: { sourceProvider },
333334
underConstruction: { plan, netMap, storageMap },
334335
calculatedOnce: { sourceNetworkLabelToId, sourceStorageLabelToId },
335336
calculatedPerNamespace: { networkMappings, storageMappings },
@@ -349,6 +350,15 @@ const handlers: {
349350
: { name: destination, namespace: plan.spec.targetNamespace, type: 'multus' },
350351
}));
351352
storageMap.spec.map = storageMappings.map(({ source, destination }) => {
353+
if (sourceProvider?.spec?.type === 'openshift') {
354+
return {
355+
source: {
356+
name: source.replace(/^\//g, ''),
357+
},
358+
destination: { storageClass: destination },
359+
};
360+
}
361+
352362
if (source === 'glance') {
353363
return {
354364
source: {

packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,50 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
6767

6868
const availableSources = sourceStorages?.filter((n) => !isStorageMapped(n?.id));
6969

70-
const getInventoryStorageName = (id: string) => sourceStorages.find((s) => s.id === id)?.name;
70+
const getInventoryStorageName = (id: string) => sourceStorages?.find((s) => s.id === id)?.name;
7171

7272
const onAdd = () =>
7373
availableSources.length > 0 &&
7474
dispatch({
7575
type: 'SET_MAP',
7676
payload: [
7777
...(state.StorageMap?.spec?.map || []),
78-
{
79-
source: availableSources[0],
80-
destination: { storageClass: destinationStorages?.[0].name },
81-
},
78+
sourceProvider?.spec?.type === 'openshift'
79+
? {
80+
source: { name: availableSources?.[0]?.name },
81+
destination: { storageClass: destinationStorages?.[0].name },
82+
}
83+
: {
84+
source: { id: availableSources?.[0]?.id },
85+
destination: { storageClass: destinationStorages?.[0].name },
86+
},
8287
],
8388
});
8489

8590
const onReplace = ({ current, next }) => {
8691
const currentDestinationStorage = destinationStorages.find(
8792
(n) => n.name == current.destination,
8893
);
89-
const currentSourceStorage = sourceStorages.find((n) => n?.name === current.source);
94+
const currentSourceStorage = sourceStorages?.find((n) => n?.name === current.source);
9095

9196
const nextDestinationStorage = destinationStorages.find((n) => n.name == next.destination);
92-
const nextSourceStorage = sourceStorages.find((n) => n?.name === next.source);
97+
const nextSourceStorage = sourceStorages?.find((n) => n?.name === next.source);
9398

9499
// sanity check, names may not be valid
95100
if (!nextSourceStorage || !nextDestinationStorage) {
96101
return;
97102
}
98103

99-
const nextMap: V1beta1StorageMapSpecMap = {
100-
source: { id: nextSourceStorage.id },
101-
destination: { storageClass: nextDestinationStorage.name },
102-
};
104+
const nextMap: V1beta1StorageMapSpecMap =
105+
sourceProvider?.spec?.type === 'openshift'
106+
? {
107+
source: { name: nextSourceStorage.name },
108+
destination: { storageClass: nextDestinationStorage.name },
109+
}
110+
: {
111+
source: { id: nextSourceStorage.id },
112+
destination: { storageClass: nextDestinationStorage.name },
113+
};
103114

104115
const payload = state?.StorageMap?.spec?.map?.map((map) => {
105116
return map?.source?.id === currentSourceStorage?.id &&
@@ -116,7 +127,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
116127

117128
const onDelete = (current: Mapping) => {
118129
const references = storageNameToIDReference(state?.StorageMap?.status?.references || []);
119-
const currentSourceStorage = sourceStorages.find((n) => n.name === current.source);
130+
const currentSourceStorage = sourceStorages?.find((n) => n.name === current.source);
120131

121132
dispatch({
122133
type: 'SET_MAP',
@@ -125,6 +136,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
125136
(map) =>
126137
!(
127138
(map?.source?.id === currentSourceStorage?.id ||
139+
map?.source?.name === current.source ||
128140
map?.source?.id === references[current.source]) &&
129141
map.destination?.storageClass === current.destination
130142
),

0 commit comments

Comments
 (0)