-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2246 from upalatucci/step-3-storageclassmigration
CNV-36070: Storageclass migration select volumes
- Loading branch information
Showing
7 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/views/virtualmachines/migrate/tabs/VirtualMachineMigrationDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { Dispatch, FC, SetStateAction } from 'react'; | ||
|
||
import { IoK8sApiCoreV1PersistentVolumeClaim } from '@kubevirt-ui/kubevirt-api/kubernetes'; | ||
import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt'; | ||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { VirtualMachineModelGroupVersionKind } from '@kubevirt-utils/models'; | ||
import { getName, getNamespace } from '@kubevirt-utils/resources/shared'; | ||
import { ResourceLink } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { Radio, Stack, StackItem, Text, TextVariants, Title } from '@patternfly/react-core'; | ||
|
||
import { entireVMSelected } from '../utils'; | ||
|
||
import SelectMigrationDisksTable from './components/SelectMigrationDisksTable'; | ||
|
||
type VirtualMachineMigrationDetailsProps = { | ||
pvcs: IoK8sApiCoreV1PersistentVolumeClaim[]; | ||
selectedPVCs: IoK8sApiCoreV1PersistentVolumeClaim[]; | ||
setSelectedPVCs: Dispatch<SetStateAction<IoK8sApiCoreV1PersistentVolumeClaim[]>>; | ||
vm: V1VirtualMachine; | ||
}; | ||
|
||
const VirtualMachineMigrationDetails: FC<VirtualMachineMigrationDetailsProps> = ({ | ||
pvcs, | ||
selectedPVCs, | ||
setSelectedPVCs, | ||
vm, | ||
}) => { | ||
const { t } = useKubevirtTranslation(); | ||
|
||
const allVolumes = entireVMSelected(selectedPVCs); | ||
|
||
return ( | ||
<Stack hasGutter> | ||
<StackItem> | ||
<Title headingLevel="h2">{t('Migration details')}</Title> | ||
<Text component={TextVariants.p}> | ||
{t('Select the storage to migrate for')} | ||
<ResourceLink | ||
groupVersionKind={VirtualMachineModelGroupVersionKind} | ||
inline | ||
name={getName(vm)} | ||
namespace={getNamespace(vm)} | ||
/> | ||
</Text> | ||
</StackItem> | ||
<StackItem> | ||
<Radio | ||
id="all-volumes" | ||
isChecked={allVolumes} | ||
label={t('The entire VirtualMachine')} | ||
name="volumes" | ||
onChange={() => setSelectedPVCs(null)} | ||
/> | ||
<Radio | ||
id="selected-volumes" | ||
isChecked={!allVolumes} | ||
label={t('Selected volumes')} | ||
name="volumes" | ||
onChange={() => setSelectedPVCs(pvcs)} | ||
/> | ||
</StackItem> | ||
{!allVolumes && ( | ||
<StackItem> | ||
<SelectMigrationDisksTable | ||
pvcs={pvcs} | ||
selectedPVCs={selectedPVCs} | ||
setSelectedPVCs={setSelectedPVCs} | ||
vm={vm} | ||
/> | ||
</StackItem> | ||
)} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default VirtualMachineMigrationDetails; |
77 changes: 77 additions & 0 deletions
77
src/views/virtualmachines/migrate/tabs/components/SelectMigrationDisksTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { Dispatch, FC, SetStateAction } from 'react'; | ||
|
||
import { IoK8sApiCoreV1PersistentVolumeClaim } from '@kubevirt-ui/kubevirt-api/kubernetes'; | ||
import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt'; | ||
import { getName } from '@kubevirt-utils/resources/shared'; | ||
import { getVolumes } from '@kubevirt-utils/resources/vm'; | ||
import { readableSizeUnit } from '@kubevirt-utils/utils/units'; | ||
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'; | ||
|
||
import { columnNames } from './constants'; | ||
import { getTableDiskData } from './utils'; | ||
|
||
type SelectMigrationDisksTableProps = { | ||
pvcs: IoK8sApiCoreV1PersistentVolumeClaim[]; | ||
selectedPVCs: IoK8sApiCoreV1PersistentVolumeClaim[]; | ||
setSelectedPVCs: Dispatch<SetStateAction<IoK8sApiCoreV1PersistentVolumeClaim[]>>; | ||
vm: V1VirtualMachine; | ||
}; | ||
|
||
const SelectMigrationDisksTable: FC<SelectMigrationDisksTableProps> = ({ | ||
pvcs, | ||
selectedPVCs, | ||
setSelectedPVCs, | ||
vm, | ||
}) => { | ||
const tableData = getVolumes(vm)?.map((volume) => getTableDiskData(vm, volume, pvcs)); | ||
|
||
const selectableData = tableData.filter((data) => data.isSelectable); | ||
|
||
return ( | ||
<Table aria-label="Selectable table"> | ||
<Thead> | ||
<Tr> | ||
<Th | ||
select={{ | ||
isSelected: selectedPVCs?.length === selectableData.length, | ||
onSelect: (_event, isSelecting) => | ||
setSelectedPVCs(isSelecting ? selectableData.map((data) => data.pvc) : []), | ||
}} | ||
aria-label="Row select" | ||
/> | ||
<Th>{columnNames.name}</Th> | ||
<Th>{columnNames.drive}</Th> | ||
<Th>{columnNames.storageClass}</Th> | ||
<Th>{columnNames.size}</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{tableData.map((diskData, rowIndex) => ( | ||
<Tr key={diskData.name}> | ||
<Td | ||
select={{ | ||
isDisabled: !diskData.isSelectable, | ||
isSelected: Boolean( | ||
selectedPVCs.find((pvc) => getName(pvc) === getName(diskData.pvc)), | ||
), | ||
onSelect: (_event, isSelecting) => | ||
setSelectedPVCs((selection) => | ||
isSelecting | ||
? [...selection, diskData.pvc] | ||
: selection.filter((pvc) => getName(pvc) !== getName(diskData.pvc)), | ||
), | ||
rowIndex, | ||
}} | ||
/> | ||
<Td dataLabel={columnNames.name}>{diskData.name}</Td> | ||
<Td dataLabel={columnNames.drive}>{diskData.drive}</Td> | ||
<Td dataLabel={columnNames.storageClass}>{diskData.storageClass}</Td> | ||
<Td dataLabel={columnNames.size}>{readableSizeUnit(diskData?.size)}</Td> | ||
</Tr> | ||
))} | ||
</Tbody> | ||
</Table> | ||
); | ||
}; | ||
|
||
export default SelectMigrationDisksTable; |
6 changes: 6 additions & 0 deletions
6
src/views/virtualmachines/migrate/tabs/components/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const columnNames = { | ||
drive: 'Drive', | ||
name: 'Name', | ||
size: 'Size', | ||
storageClass: 'Storage class', | ||
}; |
34 changes: 34 additions & 0 deletions
34
src/views/virtualmachines/migrate/tabs/components/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { IoK8sApiCoreV1PersistentVolumeClaim } from '@kubevirt-ui/kubevirt-api/kubernetes'; | ||
import { V1VirtualMachine, V1Volume } from '@kubevirt-ui/kubevirt-api/kubevirt'; | ||
import { getName } from '@kubevirt-utils/resources/shared'; | ||
import { getDisks } from '@kubevirt-utils/resources/vm'; | ||
import { NO_DATA_DASH } from '@kubevirt-utils/resources/vm/utils/constants'; | ||
import { getPrintableDiskDrive } from '@kubevirt-utils/resources/vm/utils/disk/selectors'; | ||
import { convertToBaseValue, humanizeBinaryBytes } from '@kubevirt-utils/utils/humanize.js'; | ||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
|
||
export const getTableDiskData = ( | ||
vm: V1VirtualMachine, | ||
volume: V1Volume, | ||
pvcs: IoK8sApiCoreV1PersistentVolumeClaim[], | ||
) => { | ||
const volumeDisk = getDisks(vm)?.find((disk) => disk.name === volume.name); | ||
const volumePVC = pvcs?.find( | ||
(pvc) => | ||
getName(pvc) === volume.dataVolume?.name || | ||
getName(pvc) === volume.persistentVolumeClaim?.claimName, | ||
); | ||
|
||
const pvcSize = humanizeBinaryBytes( | ||
convertToBaseValue(volumePVC?.spec?.resources?.requests?.storage), | ||
); | ||
|
||
return { | ||
drive: getPrintableDiskDrive(volumeDisk), | ||
isSelectable: !volumeDisk?.shareable && !isEmpty(volumePVC), | ||
name: volume.name, | ||
pvc: volumePVC, | ||
size: pvcSize?.value === 0 ? NO_DATA_DASH : pvcSize?.string, | ||
storageClass: volumePVC?.spec?.storageClassName, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters