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-41386: fix volume snapshot storage size #1909

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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { kubevirtConsole } from '@kubevirt-utils/utils/utils';
import { useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
import { Form, PopoverPosition, Title } from '@patternfly/react-core';

import { VolumeSnapshotKind } from '../SelectSnapshot/types';

import SchedulingSettings from './components/SchedulingSettings';
import SourceTypeSelection from './components/SourceTypeSelection/SourceTypeSelection';
import VolumeDestination from './components/VolumeDestination/VolumeDestination';
Expand All @@ -38,6 +40,7 @@ type AddBootableVolumeModalProps = {
onCreateVolume?: (
source: BootableVolume,
pvcSource?: IoK8sApiCoreV1PersistentVolumeClaim,
volumeSnapshotSource?: VolumeSnapshotKind,
) => void;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const BootableVolumeListModal: FC<BootableVolumeListModalProps> = ({
const { t } = useKubevirtTranslation();

const { instanceTypeVMState, onSelectCreatedVolume } = useInstanceTypeVMStore();
const { pvcSource, selectedBootableVolume } = instanceTypeVMState;
const { pvcSource, selectedBootableVolume, volumeSnapshotSource } = instanceTypeVMState;
const selectedBootableVolumeState = useState<BootableVolume>(selectedBootableVolume);

const onSave = () => {
onSelectCreatedVolume(selectedBootableVolumeState[0], pvcSource);
onSelectCreatedVolume(selectedBootableVolumeState[0], pvcSource, volumeSnapshotSource);
onClose();
};
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, MouseEvent } from 'react';

import { InstanceTypeVMStore } from '@catalog/CreateFromInstanceTypes/state/utils/types';
import { getTemplateOSIcon, getVolumeNameOSIcon } from '@catalog/templatescatalog/utils/os-icons';
import { V1beta1DataSource } from '@kubevirt-ui/kubevirt-api/containerized-data-importer/models';
import { IoK8sApiCoreV1PersistentVolumeClaim } from '@kubevirt-ui/kubevirt-api/kubernetes';
Expand Down Expand Up @@ -28,10 +29,7 @@ type BootableVolumeRowProps = {
activeColumnIDs: string[];
bootableVolume: BootableVolume;
rowData: {
bootableVolumeSelectedState: [
BootableVolume,
(selectedVolume: BootableVolume, pvcSource: IoK8sApiCoreV1PersistentVolumeClaim) => void,
];
bootableVolumeSelectedState: [BootableVolume, InstanceTypeVMStore['onSelectCreatedVolume']];
favorites: [isFavorite: boolean, updaterFavorites: (val: boolean) => void];
preference: V1beta1VirtualMachineClusterPreference;
pvcSource: IoK8sApiCoreV1PersistentVolumeClaim;
Expand Down Expand Up @@ -64,7 +62,7 @@ const BootableVolumeRow: FC<BootableVolumeRowProps> = ({
isClickable
isRowSelected={getName(selectedBootableVolume) === bootVolumeName}
isSelectable
onClick={() => setSelectedBootableVolume(bootableVolume, pvcSource)}
onClick={() => setSelectedBootableVolume(bootableVolume, pvcSource, volumeSnapshotSource)}
>
<TableData
favorites={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SSHSecretDetails } from '@kubevirt-utils/components/SSHSecretModal/util
import VirtualMachineDescriptionItem from '@kubevirt-utils/components/VirtualMachineDescriptionItem/VirtualMachineDescriptionItem';
import useDefaultStorageClass from '@kubevirt-utils/hooks/useDefaultStorage/useDefaultStorageClass';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { getVolumeSnapshotSize } from '@kubevirt-utils/resources/bootableresources/selectors';
import { getName } from '@kubevirt-utils/resources/shared';
import { formatBytes } from '@kubevirt-utils/resources/vm/utils/disk/size';
import { DescriptionList } from '@patternfly/react-core';
Expand All @@ -32,8 +33,10 @@ const DetailsRightGrid: FC = () => {
vmNamespaceTarget,
} = useInstanceTypeVMStore();

const { pvcSource, sshSecretCredentials } = instanceTypeVMState;
const pvcDiskSize = pvcSource?.spec?.resources?.requests?.storage;
const { pvcSource, sshSecretCredentials, volumeSnapshotSource } = instanceTypeVMState;

const pvcDiskSize =
pvcSource?.spec?.resources?.requests?.storage || getVolumeSnapshotSize(volumeSnapshotSource);
const sizeData = formatBytes(pvcDiskSize);

const setSSHCredentials = (credentials: SSHSecretDetails) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import VirtualMachineModel from '@kubevirt-ui/kubevirt-api/console/models/Virtua
import { IoK8sApiCoreV1PersistentVolumeClaim } from '@kubevirt-ui/kubevirt-api/kubernetes';
import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { getInstanceTypeFromVolume } from '@kubevirt-utils/components/AddBootableVolumeModal/utils/utils';
import { VolumeSnapshotKind } from '@kubevirt-utils/components/SelectSnapshot/types';
import { DEFAULT_PREFERENCE_LABEL } from '@kubevirt-utils/resources/bootableresources/constants';
import { BootableVolume } from '@kubevirt-utils/resources/bootableresources/types';
import { getLabel } from '@kubevirt-utils/resources/shared';
Expand Down Expand Up @@ -32,11 +33,13 @@ export const useInstanceTypeVMStore = create<InstanceTypeVMStore>()((set, get) =
onSelectCreatedVolume: (
selectedVolume: BootableVolume,
pvcSource: IoK8sApiCoreV1PersistentVolumeClaim,
volumeSnapshotSource: VolumeSnapshotKind,
) =>
set(
produce<InstanceTypeVMStore>(({ instanceTypeVMState }) => {
instanceTypeVMState.selectedBootableVolume = selectedVolume;
instanceTypeVMState.pvcSource = pvcSource;
instanceTypeVMState.volumeSnapshotSource = volumeSnapshotSource;
instanceTypeVMState.selectedInstanceType = {
name: getInstanceTypeFromVolume(selectedVolume),
namespace: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const instanceTypeVMInitialState: InstanceTypeVMState = {
selectedStorageClass: null,
sshSecretCredentials: initialSSHCredentials,
vmName: '',
volumeSnapshotSource: null,
};

export const instanceTypeVMStoreInitialState: InstanceTypeVMStoreState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type InstanceTypeVMState = {
selectedStorageClass: string;
sshSecretCredentials: SSHSecretDetails;
vmName: string;
volumeSnapshotSource: VolumeSnapshotKind;
};

export enum instanceTypeActionType {
Expand Down Expand Up @@ -76,6 +77,7 @@ type InstanceTypeVMStoreActions = {
onSelectCreatedVolume: (
selectedVolume: BootableVolume,
pvcSource: IoK8sApiCoreV1PersistentVolumeClaim,
volumeSnapshotSource: VolumeSnapshotKind,
) => void;
resetInstanceTypeVMState: () => void;
setInstanceTypeVMState: Dispatch<InstanceTypeAction>;
Expand Down
Loading