Skip to content

Commit

Permalink
Merge pull request kubevirt-ui#2217 from upalatucci/fix-run-on-cloning
Browse files Browse the repository at this point in the history
CNV-49299: use runStrategy on cloning
  • Loading branch information
openshift-merge-bot[bot] authored Oct 20, 2024
2 parents a5ac2b0 + 77b3d39 commit 63503da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/utils/components/CloneVMModal/CloneVMModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useEffect, useState } from 'react';
import React, { FC, useEffect, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom-v5-compat';

import { VirtualMachineModelRef } from '@kubevirt-ui/kubevirt-api/console';
Expand Down Expand Up @@ -41,6 +41,13 @@ const CloneVMModal: FC<CloneVMModalProps> = ({ headerText, isOpen, onClose, sour
),
);

const vmUseRunning = useMemo(
() =>
(source as V1VirtualMachine)?.spec?.running !== undefined &&
(source as V1VirtualMachine)?.spec?.running !== null,
[source],
);

const [startCloneVM, setStartCloneVM] = useState(false);

const [initialCloneRequest, setInitialCloneRequest] = useState<V1alpha1VirtualMachineClone>();
Expand All @@ -64,13 +71,13 @@ const CloneVMModal: FC<CloneVMModalProps> = ({ headerText, isOpen, onClose, sour

useEffect(() => {
if (cloneRequest?.status?.phase === CLONING_STATUSES.SUCCEEDED) {
startCloneVM && runVM(cloneName, namespace);
startCloneVM && runVM(cloneName, namespace, vmUseRunning);

navigate(`/k8s/ns/${namespace}/${VirtualMachineModelRef}/${cloneName}`);

onClose();
}
}, [cloneRequest, startCloneVM, cloneName, namespace, onClose, navigate]);
}, [cloneRequest, startCloneVM, cloneName, namespace, onClose, navigate, vmUseRunning]);

return (
<TabModal
Expand Down
18 changes: 12 additions & 6 deletions src/utils/components/CloneVMModal/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ export const cloneVM = (
});
};

export const runVM = (vmName: string, vmNamespace: string) =>
export const runVM = (vmName: string, vmNamespace: string, useRunning = false) =>
k8sPatch({
data: [
{
op: 'replace',
path: '/spec/runStrategy',
value: RUNSTRATEGY_ALWAYS,
},
useRunning
? {
op: 'replace',
path: '/spec/running',
value: true,
}
: {
op: 'replace',
path: '/spec/runStrategy',
value: RUNSTRATEGY_ALWAYS,
},
],
model: VirtualMachineModel,
resource: {
Expand Down

0 comments on commit 63503da

Please sign in to comment.