Skip to content

Commit

Permalink
Merge pull request #1084 from yaacov/alert-when-mapping-is-empty
Browse files Browse the repository at this point in the history
🐞 Alert when mapping is empty
  • Loading branch information
yaacov authored Apr 9, 2024
2 parents 3fd9e37 + c67ea1c commit fd838fe
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@
"Network interfaces": "Network interfaces",
"Network Map name re-generated": "Network Map name re-generated",
"Network map:": "Network map:",
"Network mapping is empty, make sure no mappings are required for this migration plan.": "Network mapping is empty, make sure no mappings are required for this migration plan.",
"Network mappings have been re-generated": "Network mappings have been re-generated",
"Network mappings is empty": "Network mappings is empty",
"NetworkAttachmentDefinitions": "NetworkAttachmentDefinitions",
"NetworkMap details": "NetworkMap details",
"NetworkMap YAML": "NetworkMap YAML",
Expand Down Expand Up @@ -400,7 +402,9 @@
"Storage domains": "Storage domains",
"Storage Map name re-generated": "Storage Map name re-generated",
"Storage map:": "Storage map:",
"Storage mapping is empty, make sure no mappings are required for this migration plan.": "Storage mapping is empty, make sure no mappings are required for this migration plan.",
"Storage mappings have been re-generated": "Storage mappings have been re-generated",
"Storage mappings is empty": "Storage mappings is empty",
"StorageMap details": "StorageMap details",
"StorageMap YAML": "StorageMap YAML",
"StorageMaps": "StorageMaps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const buildNetworkMessages = (
title: t('Network mappings have been re-generated'),
body: t('All discovered networks have been mapped to the default network.'),
},
NETWORK_MAPPING_EMPTY: {
title: t('Network mappings is empty'),
body: t(
'Network mapping is empty, make sure no mappings are required for this migration plan.',
),
},
MULTIPLE_NICS_ON_THE_SAME_NETWORK: {
title: t('Multiple NICs on the same network'),
body: t('VM(s) with multiple NICs on the same network were detected.'),
Expand Down Expand Up @@ -89,6 +95,12 @@ const buildStorageMessages = (
body: t('All storages detected on the selected VMs require a mapping.'),
blocker: true,
},
STORAGE_MAPPING_EMPTY: {
title: t('Storage mappings is empty'),
body: t(
'Storage mapping is empty, make sure no mappings are required for this migration plan.',
),
},
});

export type PlansCreateFormProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import {
Mapping,
MappingSource,
MULTIPLE_NICS_MAPPED_TO_POD_NETWORKING,
NETWORK_MAPPING_EMPTY,
NETWORK_MAPPING_REGENERATED,
NetworkAlerts,
OVIRT_NICS_WITH_EMPTY_PROFILE,
STORAGE_MAPPING_EMPTY,
STORAGE_MAPPING_REGENERATED,
StorageAlerts,
UNMAPPED_NETWORKS,
Expand Down Expand Up @@ -136,35 +138,53 @@ export const areMappingsEqual = (a: Mapping[], b: Mapping[]) => {
};

export const recalculateStorages = (draft) => {
const storageMappings = draft.calculatedPerNamespace.storageMappings;
draft.calculatedPerNamespace = {
...draft.calculatedPerNamespace,
...calculateStorages(draft),
};
executeStorageMappingValidation(draft);
reTestStorages(draft);
};

export const reTestStorages = (draft) => {
draft.alerts.storageMappings.warnings = [];

const storageMappings = draft.calculatedPerNamespace.storageMappings;
if (
storageMappings &&
storageMappings.length > 1 &&
!areMappingsEqual(storageMappings, draft.calculatedPerNamespace.storageMappings)
) {
addIfMissing<StorageAlerts>(STORAGE_MAPPING_REGENERATED, draft.alerts.storageMappings.warnings);
}
if (storageMappings?.length === 0) {
addIfMissing<StorageAlerts>(STORAGE_MAPPING_EMPTY, draft.alerts.storageMappings.warnings);
}
};

export const recalculateNetworks = (draft) => {
const networkMappings = draft.calculatedPerNamespace.networkMappings;
draft.calculatedPerNamespace = {
...draft.calculatedPerNamespace,
...calculateNetworks(draft),
};
executeNetworkMappingValidation(draft);
reTestNetworks(draft);
};

export const reTestNetworks = (draft) => {
draft.alerts.networkMappings.warnings = [];

const networkMappings = draft.calculatedPerNamespace.networkMappings;
if (
networkMappings &&
networkMappings.length !== 0 &&
!areMappingsEqual(networkMappings, draft.calculatedPerNamespace.networkMappings)
) {
addIfMissing<NetworkAlerts>(NETWORK_MAPPING_REGENERATED, draft.alerts.networkMappings.warnings);
}
if (networkMappings?.length === 0) {
addIfMissing<NetworkAlerts>(NETWORK_MAPPING_EMPTY, draft.alerts.networkMappings.warnings);
}
};

export const initCalculatedPerNamespaceSlice =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import {
generateUniqueName,
recalculateNetworks,
recalculateStorages,
reTestNetworks,
reTestStorages,
setTargetNamespace,
setTargetProvider,
validatePlanName,
Expand Down Expand Up @@ -393,6 +395,8 @@ const handlers: {
cpn.networkMappings = mappings;
}
executeNetworkMappingValidation(draft);

reTestNetworks(draft);
},
[DELETE_NETWORK_MAPPING](draft, { payload: { source } }: PageAction<CreateVmMigration, Mapping>) {
const { calculatedPerNamespace: cpn } = draft;
Expand All @@ -410,6 +414,8 @@ const handlers: {
);
}
executeNetworkMappingValidation(draft);

reTestNetworks(draft);
},
[REPLACE_NETWORK_MAPPING](
draft,
Expand All @@ -431,6 +437,8 @@ const handlers: {
cpn.networkMappings = mappings;
}
executeNetworkMappingValidation(draft);

reTestNetworks(draft);
},
[ADD_STORAGE_MAPPING](draft) {
const { calculatedPerNamespace: cpn } = draft;
Expand All @@ -445,6 +453,8 @@ const handlers: {
cpn.storageMappings = mappings;
}
executeStorageMappingValidation(draft);

reTestStorages(draft);
},
[DELETE_STORAGE_MAPPING](draft, { payload: { source } }: PageAction<CreateVmMigration, Mapping>) {
const { calculatedPerNamespace: cpn } = draft;
Expand All @@ -456,6 +466,8 @@ const handlers: {
cpn.storageMappings = mappings;
}
executeStorageMappingValidation(draft);

reTestStorages(draft);
},
[REPLACE_STORAGE_MAPPING](
draft,
Expand All @@ -477,6 +489,8 @@ const handlers: {
cpn.storageMappings = mappings;
}
executeStorageMappingValidation(draft);

reTestStorages(draft);
},
[REMOVE_ALERT](
{ alerts: { networkMappings, storageMappings } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface Mapping {

export const NET_MAP_NAME_REGENERATED = 'NET_MAP_NAME_REGENERATED';
export const NETWORK_MAPPING_REGENERATED = 'NETWORK_MAPPING_REGENERATED';
export const NETWORK_MAPPING_EMPTY = 'NETWORK_MAPPING_EMPTY';
export const OVIRT_NICS_WITH_EMPTY_PROFILE = 'OVIRT_NICS_WITH_EMPTY_PROFILE';
export const MULTIPLE_NICS_ON_THE_SAME_NETWORK = 'MULTIPLE_NICS_ON_THE_SAME_NETWORK';
export const UNMAPPED_NETWORKS = 'UNMAPPED_NETWORKS';
Expand All @@ -121,10 +122,12 @@ export const MULTIPLE_NICS_MAPPED_TO_POD_NETWORKING = 'MULTIPLE_NICS_MAPPED_TO_P
export const STORAGE_MAPPING_REGENERATED = 'STORAGE_MAPPING_REGENERATED';
export const STORAGE_MAP_NAME_REGENERATED = 'STORAGE_MAP_NAME_REGENERATED';
export const UNMAPPED_STORAGES = 'UNMAPPED_STORAGES';
export const STORAGE_MAPPING_EMPTY = 'STORAGE_MAPPING_EMPTY';

export type NetworkAlerts =
| typeof NET_MAP_NAME_REGENERATED
| typeof NETWORK_MAPPING_REGENERATED
| typeof NETWORK_MAPPING_EMPTY
| typeof UNMAPPED_NETWORKS
| typeof OVIRT_NICS_WITH_EMPTY_PROFILE
| typeof MULTIPLE_NICS_ON_THE_SAME_NETWORK
Expand All @@ -133,4 +136,5 @@ export type NetworkAlerts =
export type StorageAlerts =
| typeof STORAGE_MAPPING_REGENERATED
| typeof STORAGE_MAP_NAME_REGENERATED
| typeof STORAGE_MAPPING_EMPTY
| typeof UNMAPPED_STORAGES;

0 comments on commit fd838fe

Please sign in to comment.