diff --git a/src/views/virtualmachines/actions/VirtualMachineActionFactory.tsx b/src/views/virtualmachines/actions/VirtualMachineActionFactory.tsx index ddca60b11..4e97141fe 100644 --- a/src/views/virtualmachines/actions/VirtualMachineActionFactory.tsx +++ b/src/views/virtualmachines/actions/VirtualMachineActionFactory.tsx @@ -149,7 +149,7 @@ export const VirtualMachineActionFactory = { label: t('Storage'), }; }, - migrationActions: (...migrationActions): ActionDropdownItemType => ({ + migrationActions: (migrationActions): ActionDropdownItemType => ({ id: 'migration-menu', label: 'Migration', options: migrationActions, diff --git a/src/views/virtualmachines/actions/components/VirtualMachineMigration/utils.ts b/src/views/virtualmachines/actions/components/VirtualMachineMigration/utils.ts index f6ad0b20a..bd0de6f4e 100644 --- a/src/views/virtualmachines/actions/components/VirtualMachineMigration/utils.ts +++ b/src/views/virtualmachines/actions/components/VirtualMachineMigration/utils.ts @@ -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}`, @@ -156,7 +158,7 @@ export const migrateVM = async ( patchData.push({ op: 'add', path: '/spec/updateVolumesStrategy', - value: 'migration', + value: 'Migration', }); try { diff --git a/src/views/virtualmachines/actions/hooks/useVirtualMachineActionsProvider.ts b/src/views/virtualmachines/actions/hooks/useVirtualMachineActionsProvider.ts index 528f78f8b..49aa8020b 100644 --- a/src/views/virtualmachines/actions/hooks/useVirtualMachineActionsProvider.ts +++ b/src/views/virtualmachines/actions/hooks/useVirtualMachineActionsProvider.ts @@ -34,6 +34,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), @@ -44,14 +48,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) @@ -63,7 +67,7 @@ const useVirtualMachineActionsProvider: UseVirtualMachineActionsProvider = ( pauseOrUnpause, VirtualMachineActionFactory.clone(vm, createModal), VirtualMachineActionFactory.snapshot(vm, createModal), - VirtualMachineActionFactory.migrationActions(migrateOrCancelMigrationCompute, migrateStorage), + VirtualMachineActionFactory.migrationActions(migrationActions), VirtualMachineActionFactory.copySSHCommand(vm, virtctlCommand), VirtualMachineActionFactory.moveToFolder(vm, createModal), VirtualMachineActionFactory.delete(vm, createModal),