Skip to content

Commit

Permalink
Merge pull request #2315 from upalatucci/fix-updateVolumesStrategy
Browse files Browse the repository at this point in the history
CNV-51680: migrate or cancel migration and fix storage migration
  • Loading branch information
openshift-merge-bot[bot] authored Dec 13, 2024
2 parents 7c2e2de + 62a61c1 commit 3872fde
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const VirtualMachineActionFactory = {
label: t('Storage'),
};
},
migrationActions: (...migrationActions): ActionDropdownItemType => ({
migrationActions: (migrationActions): ActionDropdownItemType => ({
id: 'migration-menu',
label: 'Migration',
options: migrationActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import { getRandomChars, isEmpty } from '@kubevirt-utils/utils/utils';
import { k8sCreate, k8sDelete, k8sPatch, Patch } from '@openshift-console/dynamic-plugin-sdk';

const getBlankDataVolume = (
originName: string,
dataVolumeName: string,
namespace: string,
storageClassName: string,
storage: string,
): V1beta1DataVolume => {
const randomChars = getRandomChars();
const namePrefix = `clone-${originName}`.substring(0, MAX_NAME_LENGTH - 6 - randomChars.length);

const originName = dataVolumeName.replace(/-mig-\d+$/, '');
const namePrefix = `${originName}-mig`.substring(0, MAX_NAME_LENGTH - 5 - randomChars.length);

return {
apiVersion: `${DataVolumeModel.apiGroup}/${DataVolumeModel.apiVersion}`,
Expand Down Expand Up @@ -156,7 +158,7 @@ export const migrateVM = async (
patchData.push({
op: 'add',
path: '/spec/updateVolumesStrategy',
value: 'migration',
value: 'Migration',
});

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const useVirtualMachineActionsProvider: UseVirtualMachineActionsProvider = (
const printableStatus = vm?.status?.printableStatus;
const { Migrating, Paused } = printableVMStatus;

const isMigrating =
printableStatus === Migrating ||
(vmim && ![vmimStatuses.Failed, vmimStatuses.Succeeded].includes(vmim?.status?.phase));

const startOrStop = ((printableStatusMachine) => {
const map = {
default: VirtualMachineActionFactory.stop(vm),
Expand All @@ -50,14 +54,14 @@ const useVirtualMachineActionsProvider: UseVirtualMachineActionsProvider = (
return map[printableStatusMachine] || map.default;
})(printableStatus);

const migrateOrCancelMigrationCompute =
printableStatus === Migrating ||
(vmim && ![vmimStatuses.Failed, vmimStatuses.Succeeded].includes(vmim?.status?.phase))
? VirtualMachineActionFactory.cancelMigrationCompute(vm, vmim, isSingleNodeCluster)
: VirtualMachineActionFactory.migrateCompute(vm, isSingleNodeCluster);
const migrateCompute = VirtualMachineActionFactory.migrateCompute(vm, isSingleNodeCluster);

const migrateStorage = VirtualMachineActionFactory.migrateStorage(vm, createModal);

const migrationActions = isMigrating
? [VirtualMachineActionFactory.cancelMigrationCompute(vm, vmim, isSingleNodeCluster)]
: [migrateCompute, migrateStorage];

const pauseOrUnpause =
printableStatus === Paused
? VirtualMachineActionFactory.unpause(vm)
Expand All @@ -69,7 +73,7 @@ const useVirtualMachineActionsProvider: UseVirtualMachineActionsProvider = (
pauseOrUnpause,
VirtualMachineActionFactory.clone(vm, createModal),
VirtualMachineActionFactory.snapshot(vm, createModal),
VirtualMachineActionFactory.migrationActions(migrateOrCancelMigrationCompute, migrateStorage),
VirtualMachineActionFactory.migrationActions(migrationActions),
VirtualMachineActionFactory.copySSHCommand(vm, virtctlCommand),
treeViewEnabled &&
treeViewFoldersEnabled &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ describe('useVirtualMachineActionsProvider tests', () => {
'vm-action-delete',
]);

expect(migratingSubmenuIds).toEqual(['vm-action-cancel-migrate', 'vm-migrate-storage']);
expect(migratingSubmenuIds).toEqual(['vm-action-cancel-migrate']);
});
});

0 comments on commit 3872fde

Please sign in to comment.