Skip to content

Commit

Permalink
Add a fast Create Plan page - step 3
Browse files Browse the repository at this point in the history
Changes:
1. split state into slices
2. split reducer.tx - move state helper functions
3. improve typings for multus network type
4. create hooks to retrieve nic profiles and networks from the inventory
5. create a MappingList component for editing mappings
6. re-create state only when input queries are fully loaded
7. display source networks in 2 categories: networks used by the
   selected VMs and remaining networks on the provider
8. create network mapping based on information in the state

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Jan 29, 2024
1 parent 1e2d42d commit 840bb8f
Show file tree
Hide file tree
Showing 16 changed files with 1,416 additions and 191 deletions.
2 changes: 2 additions & 0 deletions packages/eslint-plugin/cspell.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ filesystems
bootloader
typeahead
immer
networkattachmentdefinitions
nicprofiles
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"A user name for connecting to the Red Hat Virtualization Manager (RHVM) API endpoint. Ensure the user name is in the format of username@user-domain. For example: admin@internal.": "A user name for connecting to the Red Hat Virtualization Manager (RHVM) API endpoint. Ensure the user name is in the format of username@user-domain. For example: admin@internal.",
"A user password for connecting to the Red Hat Virtualization Manager (RHVM) API endpoint.": "A user password for connecting to the Red Hat Virtualization Manager (RHVM) API endpoint.",
"Actions": "Actions",
"Add mapping": "Add mapping",
"Add source and target providers for the migration.": "Add source and target providers for the migration.",
"Application credential ID": "Application credential ID",
"Application credential name": "Application credential name",
Expand Down Expand Up @@ -84,6 +85,7 @@
"Defines the CPU limits allocated to the main container in the controller pod. The default value is 500 milliCPU.": "Defines the CPU limits allocated to the main container in the controller pod. The default value is 500 milliCPU.",
"Delete": "Delete",
"Delete {{model.label}}": "Delete {{model.label}}",
"Delete mapping": "Delete mapping",
"Delete Mapping": "Delete Mapping",
"Delete NetworkMap?": "Delete NetworkMap?",
"Delete Plan?": "Delete Plan?",
Expand Down Expand Up @@ -226,14 +228,17 @@
"Namespace is not defined": "Namespace is not defined",
"Network for data transfer": "Network for data transfer",
"Network interfaces": "Network interfaces",
"Network map:": "Network map:",
"NetworkAttachmentDefinitions": "NetworkAttachmentDefinitions",
"NetworkMaps": "NetworkMaps",
"NetworkMaps for virtualization": "NetworkMaps for virtualization",
"Networks": "Networks",
"Networks used by the selected VMs": "Networks used by the selected VMs",
"No credentials found.": "No credentials found.",
"No inventory data available.": "No inventory data available.",
"No NetworkMaps found in namespace <1>{namespace}</1>.": "No NetworkMaps found in namespace <1>{namespace}</1>.",
"No NetworkMaps found.": "No NetworkMaps found.",
"No networks in this category": "No networks in this category",
"No owner": "No owner",
"No Plans found in namespace <1>{namespace}</1>.": "No Plans found in namespace <1>{namespace}</1>.",
"No Plans found.": "No Plans found.",
Expand All @@ -246,6 +251,7 @@
"No secret.": "No secret.",
"No StorageMaps found in namespace <1>{namespace}</1>.": "No StorageMaps found in namespace <1>{namespace}</1>.",
"No StorageMaps found.": "No StorageMaps found.",
"No storages in this category": "No storages in this category",
"Not Ready": "Not Ready",
"Note: If 'Skip certificate validation' is selected, migrations from this provider will not be secure.<br><br> Insecure migration means that the transferred data is sent over an insecure connection and potentially sensitive data could be exposed.": "Note: If 'Skip certificate validation' is selected, migrations from this provider will not be secure.<br><br> Insecure migration means that the transferred data is sent over an insecure connection and potentially sensitive data could be exposed.",
"Note: Use the Manager CA certificate unless it was replaced by a third-party certificate, in which case use the Manager Apache CA certificate. <br><br>You can retrieve the Manager CA certificate at:<br><1>https://&#8249;rhv-host-example.com&#8250;/ovirt-engine/services/pki-resource?resource=ca-certificate&format=X509-PEM-CA</1> .": "Note: Use the Manager CA certificate unless it was replaced by a third-party certificate, in which case use the Manager Apache CA certificate. <br><br>You can retrieve the Manager CA certificate at:<br><1>https://&#8249;rhv-host-example.com&#8250;/ovirt-engine/services/pki-resource?resource=ca-certificate&format=X509-PEM-CA</1> .",
Expand Down Expand Up @@ -283,6 +289,8 @@
"OpenStack REST API user name.": "OpenStack REST API user name.",
"Operator": "Operator",
"Operator conditions define the current state of the controller": "Operator conditions define the current state of the controller",
"Other networks present on the source provider ": "Other networks present on the source provider ",
"Other storages present on the source provider ": "Other storages present on the source provider ",
"OvaPath": "OvaPath",
"Overview": "Overview",
"Owner": "Owner",
Expand Down Expand Up @@ -362,8 +370,10 @@
"Storage": "Storage",
"Storage classes": "Storage classes",
"Storage domains": "Storage domains",
"Storage map:": "Storage map:",
"StorageMaps": "StorageMaps",
"StorageMaps for virtualization": "StorageMaps for virtualization",
"Storages used by the selected VMs": "Storages used by the selected VMs",
"Succeeded": "Succeeded",
"Target and Source": "Target and Source",
"Target namespace": "Target namespace",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useMemo } from 'react';

import {
OpenShiftNetworkAttachmentDefinition,
OpenstackNetwork,
OVirtNetwork,
ProviderType,
V1beta1Provider,
VSphereNetwork,
} from '@kubev2v/types';

import useProviderInventory from './useProviderInventory';

export type InventoryNetwork =
| OpenShiftNetworkAttachmentDefinition
| OpenstackNetwork
| OVirtNetwork
| VSphereNetwork;

export const useSourceNetworks = (
provider: V1beta1Provider,
): [InventoryNetwork[], boolean, Error] => {
const providerType: ProviderType = provider?.spec?.type as ProviderType;
const {
inventory: networks,
loading,
error,
} = useProviderInventory<InventoryNetwork[]>({
provider,
subPath: providerType === 'openshift' ? '/networkattachmentdefinitions' : '/networks',
});

const typedNetworks = useMemo(
() =>
Array.isArray(networks)
? networks.map((net) => ({ ...net, providerType } as InventoryNetwork))
: [],
[networks],
);

return [typedNetworks, loading, error];
};

export const useOpenShiftNetworks = (
provider: V1beta1Provider,
): [OpenShiftNetworkAttachmentDefinition[], boolean, Error] => {
const isOpenShift = provider?.spec?.type === 'openshift';
const {
inventory: networks,
loading,
error,
} = useProviderInventory<OpenShiftNetworkAttachmentDefinition[]>({
provider,
subPath: isOpenShift ? '/networkattachmentdefinitions' : '',
});

const typedNetworks: OpenShiftNetworkAttachmentDefinition[] = useMemo(
() =>
Array.isArray(networks) ? networks.map((net) => ({ ...net, providerType: 'openshift' })) : [],
[networks],
);

return [typedNetworks, loading, error];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useMemo } from 'react';

import { OVirtNicProfile, V1beta1Provider } from '@kubev2v/types';

import useProviderInventory from './useProviderInventory';

/**
* Works only for oVirt
*/
export const useNicProfiles = (provider: V1beta1Provider): [OVirtNicProfile[], boolean, Error] => {
const isOVirt = provider?.spec?.type === 'ovirt';
const {
inventory: nicProfiles,
loading,
error,
} = useProviderInventory<OVirtNicProfile[]>({
provider,
subPath: isOVirt ? '/nicprofiles?detail=1' : '',
});

const stable = useMemo(() => {
if (!isOVirt) {
return [];
}
return Array.isArray(nicProfiles) ? nicProfiles : [];
}, [isOVirt, nicProfiles]);

return [stable, loading, error];
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './networkMapTemplate';
export * from './planTemplate';
export * from './providerTemplate';
export * from './secretTemplate';
export * from './storageMapTemplate';
// @endindex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { V1beta1NetworkMap } from '@kubev2v/types';

export const networkMapTemplate: V1beta1NetworkMap = {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'NetworkMap',
metadata: {
name: undefined,
namespace: undefined,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { V1beta1StorageMap } from '@kubev2v/types';

export const storageMapTemplate: V1beta1StorageMap = {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'StorageMap',
metadata: {
name: undefined,
namespace: undefined,
},
};
Loading

0 comments on commit 840bb8f

Please sign in to comment.