Skip to content

Commit

Permalink
Bug 2047371 - live snapshot is allowed with hotplugs
Browse files Browse the repository at this point in the history
Signed-off-by: Aviv Turgeman <aturgema@redhat.com>
  • Loading branch information
avivtur committed Jan 30, 2022
1 parent cffe401 commit e2c32f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@
"To take a snapshot you can either edit an existing disk to add a snapshot-supported storage class or add a new disk with a compatible storage class defined. For further details, please contact your cluster admin.": "To take a snapshot you can either edit an existing disk to add a snapshot-supported storage class or add a new disk with a compatible storage class defined. For further details, please contact your cluster admin.",
"Learn more about snapshots": "Learn more about snapshots",
"Take Snapshot": "Take Snapshot",
"Can not create virtual machine snapshot which includes hotplug volume while VM is running": "Can not create virtual machine snapshot which includes hotplug volume while VM is running",
"Snapshot only includes disks backed by a snapshot-supported storage class": "Snapshot only includes disks backed by a snapshot-supported storage class",
"Snapshot Name": "Snapshot Name",
"unsupported approve checkbox": "unsupported approve checkbox",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
cancel,
isVMRunningOrExpectedRunning,
snapshots,
isHotplugExists,
} = props;
const { t } = useTranslation();
const vmName = getName(vmLikeEntity);
Expand All @@ -64,6 +65,7 @@ const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
const hasUnsupportedVolumes = unsupportedVolumes.length > 0;

const userNeedsToAckWarning = hasUnsupportedVolumes || isVMRunningOrExpectedRunning;
const isLiveSnapshotBlocked = isHotplugExists && isVMRunningOrExpectedRunning;

const submit = async (e) => {
e.preventDefault();
Expand All @@ -87,17 +89,23 @@ const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
<ModalBody>
{hasSupportedVolumes && (
<Alert
title={t(
'kubevirt-plugin~Snapshot only includes disks backed by a snapshot-supported storage class',
)}
title={
isLiveSnapshotBlocked
? t(
'kubevirt-plugin~Can not create virtual machine snapshot which includes hotplug volume while VM is running',
)
: t(
'kubevirt-plugin~Snapshot only includes disks backed by a snapshot-supported storage class',
)
}
isInline
variant={AlertVariant.info}
className="co-m-form-row"
/>
)}

<Form onSubmit={submit}>
{hasSupportedVolumes && (
{hasSupportedVolumes && !isLiveSnapshotBlocked && (
<>
<FormRow title={t('kubevirt-plugin~Snapshot Name')} fieldId={asId('name')} isRequired>
<TextInput
Expand Down Expand Up @@ -135,7 +143,7 @@ const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
</FormRow>
)}

{hasSupportedVolumes && userNeedsToAckWarning && (
{hasSupportedVolumes && userNeedsToAckWarning && !isLiveSnapshotBlocked && (
<FormRow fieldId="unsupported-approve-checkbox">
<Checkbox
id="approve-checkbox"
Expand All @@ -153,7 +161,10 @@ const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
submitButtonText={t('kubevirt-plugin~Save')}
errorMessage={errorMessage}
isDisabled={
inProgress || (hasUnsupportedVolumes && !approveUnsupported) || !hasSupportedVolumes
inProgress ||
(hasUnsupportedVolumes && !approveUnsupported) ||
!hasSupportedVolumes ||
isLiveSnapshotBlocked
}
inProgress={inProgress}
onSubmit={submit}
Expand All @@ -172,5 +183,6 @@ export type SnapshotsModalProps = {
vmLikeEntity: VMLikeEntityKind;
isVMRunningOrExpectedRunning: boolean;
snapshots: VMSnapshot[];
isHotplugExists: boolean;
} & ModalComponentProps &
HandlePromiseProps;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
const SupportedSnapshotVolumesList = ({ supportedVolumes }: SupportedSnapshotVolumesListProps) => {
const { t } = useTranslation();

if (supportedVolumes) {
if (!supportedVolumes) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { VirtualMachineSnapshotModel } from '../../models';
import { kubevirtReferenceForModel } from '../../models/kubevirtReferenceForModel';
import { getName, getNamespace } from '../../selectors';
import { isVMI } from '../../selectors/check-type';
import { getHotplugDiskNames } from '../../selectors/disks/hotplug';
import { getVmSnapshotVmName } from '../../selectors/snapshot/snapshot';
import { isVMRunningOrExpectedRunning } from '../../selectors/vm/selectors';
import { asVM } from '../../selectors/vm/vm';
Expand Down Expand Up @@ -113,6 +114,7 @@ export const VMSnapshotsPage: React.FC<VMTabProps> = ({ obj: vmLikeEntity, vmis:
const filteredSnapshots = snapshots.filter((snap) => getVmSnapshotVmName(snap) === vmName);
const isDisabled = isLocked;

const isHotplugExists = getHotplugDiskNames(vmi)?.length > 0;
return (
<div className="co-m-list">
{!isVMI(vmLikeEntity) && (
Expand All @@ -131,6 +133,7 @@ export const VMSnapshotsPage: React.FC<VMTabProps> = ({ obj: vmLikeEntity, vmis:
vmi,
),
snapshots,
isHotplugExists,
}).result,
)
}
Expand Down

0 comments on commit e2c32f3

Please sign in to comment.