From 77b3d396c77cff4afa3c0e59d624e546cdcbec54 Mon Sep 17 00:00:00 2001 From: Ugo Palatucci Date: Mon, 7 Oct 2024 14:47:40 +0200 Subject: [PATCH] CNV-49299: use runStrategy on cloning --- .../components/CloneVMModal/CloneVMModal.tsx | 13 ++++++++++--- .../components/CloneVMModal/utils/helpers.tsx | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/utils/components/CloneVMModal/CloneVMModal.tsx b/src/utils/components/CloneVMModal/CloneVMModal.tsx index 30b5af157..caab8ea7f 100644 --- a/src/utils/components/CloneVMModal/CloneVMModal.tsx +++ b/src/utils/components/CloneVMModal/CloneVMModal.tsx @@ -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'; @@ -41,6 +41,13 @@ const CloneVMModal: FC = ({ 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(); @@ -64,13 +71,13 @@ const CloneVMModal: FC = ({ 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 ( +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: {