Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNV-49299: use runStrategy on cloning #2217

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about when running can be false? there are also cases where someone would like to pass a different runStrategy the Always?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If rspec.running is false, it means that the user used this attribute to run/stop the VM so we'll use the same s[attribute changing the spec.running . If it's not in the vm spec it means that we'll use runStrategy

I can at this point call the vm API action to run the vm, so the backend will choose what strategy use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runStrategies that start vms are Always and RerunOnFailure

);

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
Loading