Skip to content

Commit

Permalink
Merge pull request #1077 from yaacov/fix-source-ocp-storage-mapping
Browse files Browse the repository at this point in the history
🐞 Fix source OCP storage mapping
  • Loading branch information
yaacov authored Apr 8, 2024
2 parents c0e66ed + ba7ebef commit 414b1bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ const handlers: {
},
[START_CREATE]({
flow,
receivedAsParams: { sourceProvider },
underConstruction: { plan, netMap, storageMap },
calculatedOnce: { sourceNetworkLabelToId, sourceStorageLabelToId },
calculatedPerNamespace: { networkMappings, storageMappings },
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,50 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ 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 &&
dispatch({
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 },
},
],
});

const onReplace = ({ current, next }) => {
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 &&
Expand All @@ -116,7 +127,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ 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',
Expand All @@ -125,6 +136,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
(map) =>
!(
(map?.source?.id === currentSourceStorage?.id ||
map?.source?.name === current.source ||
map?.source?.id === references[current.source]) &&
map.destination?.storageClass === current.destination
),
Expand Down

0 comments on commit 414b1bb

Please sign in to comment.