Skip to content

Commit

Permalink
Merge pull request #1581 from upalatucci/create-volume-snapshot
Browse files Browse the repository at this point in the history
CNV-33095: add volumesnapshot option in the add bootable volume modal
  • Loading branch information
openshift-ci[bot] authored Oct 19, 2023
2 parents ea52dde + ed6d676 commit 5cd4de6
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 137 deletions.
7 changes: 6 additions & 1 deletion locales/en/plugin__kubevirt-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"--- Select PVC project ---": "--- Select PVC project ---",
"--- Select secret ---": "--- Select secret ---",
"--- Select sysprep ---": "--- Select sysprep ---",
"--- Select VolumeSnapshot name ---": "--- Select VolumeSnapshot name ---",
"--- Select VolumeSnapshot project ---": "--- Select VolumeSnapshot project ---",
", {{prefferedQualifiedNodesSize}} matching preferred Nodes found": ", {{prefferedQualifiedNodesSize}} matching preferred Nodes found",
"(default)": "(default)",
"(default) | ": "(default) | ",
Expand Down Expand Up @@ -1135,7 +1137,7 @@
"Upload a boot source (Quick start)": "Upload a boot source (Quick start)",
"Upload a new file to a PVC. A new PVC will be created.": "Upload a new file to a PVC. A new PVC will be created.",
"Upload a new file to PVC. a new PVC will be created.": "Upload a new file to PVC. a new PVC will be created.",
"Upload a new volume, or use an existing PersistentVolumeClaim (PVC) or DataSource.": "Upload a new volume, or use an existing PersistentVolumeClaim (PVC) or DataSource.",
"Upload a new volume, or use an existing PersistentVolumeClaim (PVC), VolumeSnapshot or DataSource.": "Upload a new volume, or use an existing PersistentVolumeClaim (PVC), VolumeSnapshot or DataSource.",
"Upload canceled": "Upload canceled",
"Upload cancelled": "Upload cancelled",
"Upload content from a container located in a registry accessible from the cluster. The container disk is meant to be used only for read-only filesystems such as CD-ROMs or for small short-lived throw-away VMs.": "Upload content from a container located in a registry accessible from the cluster. The container disk is meant to be used only for read-only filesystems such as CD-ROMs or for small short-lived throw-away VMs.",
Expand All @@ -1159,6 +1161,7 @@
"Use cron formatting to set when and how often to look for new imports.": "Use cron formatting to set when and how often to look for new imports.",
"Use existing": "Use existing",
"Use existing volume": "Use existing volume",
"Use existing volume snapshot": "Use existing volume snapshot",
"Use optimized access mode & volume mode settings from StorageProfile resource.": "Use optimized access mode & volume mode settings from StorageProfile resource.",
"Use our collection of resources to help you get started with virtualization.": "Use our collection of resources to help you get started with virtualization.",
"Use template size PVC": "Use template size PVC",
Expand Down Expand Up @@ -1244,6 +1247,8 @@
"Volume snapshot status": "Volume snapshot status",
"Volume Snapshot Status is a mechanism for reporting if a volume can be snapshotted or not.": "Volume Snapshot Status is a mechanism for reporting if a volume can be snapshotted or not.",
"Volumes project": "Volumes project",
"VolumeSnapshot name": "VolumeSnapshot name",
"VolumeSnapshot project": "VolumeSnapshot project",
"Warning": "Warning",
"Warnings": "Warnings",
"Weight": "Weight",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ const AddBootableVolumeModal: FC<AddBootableVolumeModalProps> = ({
obj={emptyDataSource}
submitBtnText={t('Save')}
>
{t('Upload a new volume, or use an existing PersistentVolumeClaim (PVC) or DataSource.')}
{t(
'Upload a new volume, or use an existing PersistentVolumeClaim (PVC), VolumeSnapshot or DataSource.',
)}
<Form className="pf-u-mt-md">
<SourceTypeSelection
formSelection={sourceType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const SourceTypeSelection: FC<SourceTypeSelectionProps> = ({
setFormSelection,
}) => {
const [isOpen, setIsOpen] = useState(false);
const { canCreateDS, canCreatePVC, loading } = useCanCreateBootableVolume(namespace);
const { canCreateDS, canCreatePVC, canCreateSnapshots, loading } =
useCanCreateBootableVolume(namespace);

const onSelect = useCallback(
(event, value) => {
Expand Down Expand Up @@ -53,6 +54,10 @@ const SourceTypeSelection: FC<SourceTypeSelectionProps> = ({
{t('Use existing volume')}
</SelectOption>

<SelectOption isDisabled={!canCreateSnapshots} value={DROPDOWN_FORM_SELECTION.USE_SNAPSHOT}>
{t('Use existing volume snapshot')}
</SelectOption>

<SelectOption
description={t(
'Creates a DataImportCron, which defines a cron job to poll and import the disk image.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import React, { FC } from 'react';
import xbytes from 'xbytes';

import { removeByteSuffix } from '@kubevirt-utils/components/CapacityInput/utils';
import DiskSourcePVCSelect from '@kubevirt-utils/components/DiskModal/DiskFormFields/DiskSourceFormSelect/components/DiskSourcePVCSelect';
import DiskSourceUploadPVC from '@kubevirt-utils/components/DiskModal/DiskFormFields/DiskSourceFormSelect/components/DiskSourceUploadPVC';
import HelpTextIcon from '@kubevirt-utils/components/HelpTextIcon/HelpTextIcon';
import { DataUpload } from '@kubevirt-utils/hooks/useCDIUpload/useCDIUpload';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { hasSizeUnit } from '@kubevirt-utils/resources/vm/utils/disk/size';
import {
Checkbox,
FormGroup,
PopoverPosition,
Split,
SplitItem,
TextInput,
} from '@patternfly/react-core';
import { FormGroup, TextInput } from '@patternfly/react-core';

import { AddBootableVolumeState, DROPDOWN_FORM_SELECTION } from '../../utils/constants';

import PVCSource from './components/PVCSource';
import SnapshotSource from './components/SnapshotSource';

type VolumeSourceProps = {
bootableVolume: AddBootableVolumeState;
setBootableVolumeField: (
Expand All @@ -36,10 +27,10 @@ const VolumeSource: FC<VolumeSourceProps> = ({
upload,
}) => {
const { t } = useKubevirtTranslation();
const { pvcName, pvcNamespace, registryURL, uploadFile, uploadFilename } = bootableVolume || {};
const { registryURL, uploadFile, uploadFilename } = bootableVolume || {};

if (sourceType === DROPDOWN_FORM_SELECTION.UPLOAD_IMAGE)
return (
const sourceComponentByType = {
[DROPDOWN_FORM_SELECTION.UPLOAD_IMAGE]: (
<DiskSourceUploadPVC
label={t('Upload PVC image')}
relevantUpload={upload}
Expand All @@ -48,10 +39,11 @@ const VolumeSource: FC<VolumeSourceProps> = ({
uploadFile={uploadFile}
uploadFileName={uploadFilename}
/>
);

if (sourceType === DROPDOWN_FORM_SELECTION.USE_REGISTRY)
return (
),
[DROPDOWN_FORM_SELECTION.USE_EXISTING_PVC]: (
<PVCSource bootableVolume={bootableVolume} setBootableVolumeField={setBootableVolumeField} />
),
[DROPDOWN_FORM_SELECTION.USE_REGISTRY]: (
<FormGroup
fieldId="volume-registry-url"
helperText={t('Example: quay.io/containerdisks/centos:7-2009')}
Expand All @@ -66,36 +58,16 @@ const VolumeSource: FC<VolumeSourceProps> = ({
value={registryURL}
/>
</FormGroup>
);

return (
<>
<DiskSourcePVCSelect
setDiskSize={(newSize) =>
setBootableVolumeField('size')(
hasSizeUnit(newSize)
? removeByteSuffix(newSize)
: removeByteSuffix(xbytes(Number(newSize), { iec: true, space: false })),
)
}
pvcNameSelected={pvcName}
pvcNamespaceSelected={pvcNamespace}
selectPVCName={setBootableVolumeField('pvcName')}
selectPVCNamespace={setBootableVolumeField('pvcNamespace')}
),
[DROPDOWN_FORM_SELECTION.USE_SNAPSHOT]: (
<SnapshotSource
bootableVolume={bootableVolume}
setBootableVolumeField={setBootableVolumeField}
/>
<Split hasGutter>
<SplitItem>
<Checkbox id="clone-pvc-checkbox" isChecked isDisabled label={t('Clone existing PVC')} />
</SplitItem>
<SplitItem>
<HelpTextIcon
bodyContent={t('This will create a cloned copy of the PVC in the destination project.')}
position={PopoverPosition.right}
/>
</SplitItem>
</Split>
</>
);
),
};

return sourceComponentByType[sourceType];
};

export default VolumeSource;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { FC } from 'react';
import xbytes from 'xbytes';

import {
AddBootableVolumeState,
SetBootableVolumeFieldType,
} from '@kubevirt-utils/components/AddBootableVolumeModal/utils/constants';
import { removeByteSuffix } from '@kubevirt-utils/components/CapacityInput/utils';
import DiskSourcePVCSelect from '@kubevirt-utils/components/DiskModal/DiskFormFields/DiskSourceFormSelect/components/DiskSourcePVCSelect';
import HelpTextIcon from '@kubevirt-utils/components/HelpTextIcon/HelpTextIcon';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { hasSizeUnit } from '@kubevirt-utils/resources/vm/utils/disk/size';
import { Checkbox, PopoverPosition, Split, SplitItem } from '@patternfly/react-core';

type PVCSourceProps = {
bootableVolume: AddBootableVolumeState;
setBootableVolumeField: SetBootableVolumeFieldType;
};

const PVCSource: FC<PVCSourceProps> = ({ bootableVolume, setBootableVolumeField }) => {
const { t } = useKubevirtTranslation();
const { pvcName, pvcNamespace } = bootableVolume || {};

return (
<>
<DiskSourcePVCSelect
setDiskSize={(newSize) =>
setBootableVolumeField('size')(
hasSizeUnit(newSize)
? removeByteSuffix(newSize)
: removeByteSuffix(xbytes(Number(newSize), { iec: true, space: false })),
)
}
pvcNameSelected={pvcName}
pvcNamespaceSelected={pvcNamespace}
selectPVCName={setBootableVolumeField('pvcName')}
selectPVCNamespace={setBootableVolumeField('pvcNamespace')}
/>
<Split hasGutter>
<SplitItem>
<Checkbox id="clone-pvc-checkbox" isChecked isDisabled label={t('Clone existing PVC')} />
</SplitItem>
<SplitItem>
<HelpTextIcon
bodyContent={t('This will create a cloned copy of the PVC in the destination project.')}
position={PopoverPosition.right}
/>
</SplitItem>
</Split>
</>
);
};

export default PVCSource;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { FC } from 'react';

import {
AddBootableVolumeState,
SetBootableVolumeFieldType,
} from '@kubevirt-utils/components/AddBootableVolumeModal/utils/constants';
import SelectSnapshot from '@kubevirt-utils/components/SelectSnapshot/SelectSnapshot';

type SnapshotSourceProps = {
bootableVolume: AddBootableVolumeState;
setBootableVolumeField: SetBootableVolumeFieldType;
};

const SnapshotSource: FC<SnapshotSourceProps> = ({ bootableVolume, setBootableVolumeField }) => {
const { snapshotName, snapshotNamespace } = bootableVolume || {};
return (
<SelectSnapshot
selectSnapshotName={setBootableVolumeField('snapshotName')}
selectSnapshotNamespace={setBootableVolumeField('snapshotNamespace')}
snapshotNameSelected={snapshotName}
snapshotNamespaceSelected={snapshotNamespace}
/>
);
};

export default SnapshotSource;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum DROPDOWN_FORM_SELECTION {
UPLOAD_IMAGE = 'upload',
USE_EXISTING_PVC = 'pvc',
USE_REGISTRY = 'registry',
USE_SNAPSHOT = 'snapshot',
}

export type AddBootableVolumeState = {
Expand All @@ -26,6 +27,8 @@ export type AddBootableVolumeState = {
registryURL: string;
retainRevisions: number;
size: string;
snapshotName: string;
snapshotNamespace: string;
storageClassName: string;
storageClassProvisioner: string;
uploadFile: File | string;
Expand All @@ -47,6 +50,8 @@ export const initialBootableVolumeState: AddBootableVolumeState = {
registryURL: null,
retainRevisions: 3,
size: DEFAULT_DISK_SIZE,
snapshotName: null,
snapshotNamespace: null,
storageClassName: null,
storageClassProvisioner: null,
uploadFile: null,
Expand Down
Loading

0 comments on commit 5cd4de6

Please sign in to comment.