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-52060: add storage info to datavolumeTemplate in make persistent #2321

Merged
merged 1 commit into from
Dec 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const MakePersistentModal: FC<MakePersistentModalProps> = ({
}) => {
const { t } = useKubevirtTranslation();

const makePersistent = () => {
const makePersistent = async () => {
const volumeToPersist = getVMIVolumes(vmi).find((vmiVolume) => vmiVolume.name === volume?.name);

const vmPersistent = persistVolume(vm, vmi, volumeToPersist);
const vmPersistent = await persistVolume(vm, vmi, volumeToPersist);

return updateDisks(vmPersistent);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import produce from 'immer';
import { WritableDraft } from 'immer/dist/internal';

import { DEFAULT_PREFERENCE_LABEL } from '@catalog/CreateFromInstanceTypes/utils/constants';
import DataVolumeModel from '@kubevirt-ui/kubevirt-api/console/models/DataVolumeModel';
import { V1beta1DataVolume } from '@kubevirt-ui/kubevirt-api/containerized-data-importer/models';
import {
V1beta1StorageSpec,
V1Disk,
V1VirtualMachine,
V1VirtualMachineInstance,
Expand All @@ -24,6 +27,7 @@ import { DiskRowDataLayout } from '@kubevirt-utils/resources/vm/utils/disk/const
import { getVMIDevices } from '@kubevirt-utils/resources/vmi';
import { ClaimPropertySets } from '@kubevirt-utils/types/storage';
import { ensurePath, isEmpty } from '@kubevirt-utils/utils/utils';
import { k8sGet } from '@openshift-console/dynamic-plugin-sdk';

export const createBootableVolumeFromDisk = async (
diskObj: DiskRowDataLayout,
Expand Down Expand Up @@ -61,11 +65,20 @@ const addDiskToVM = (draftVM: WritableDraft<V1VirtualMachine>, diskToPersist: V1
draftVM.spec.template.spec.domain.devices.disks = disks;
};

const addDataVolumeToVM = (draftVM: WritableDraft<V1VirtualMachine>, dataVolumeName: string) => {
const addDataVolumeToVM = async (
draftVM: WritableDraft<V1VirtualMachine>,
dataVolumeName: string,
) => {
const dataVolumeTemplates = getDataVolumeTemplates(draftVM);

if (dataVolumeTemplates.find((dataVolume) => dataVolume.metadata.name === dataVolumeName)) return;

const originDataVolume = await k8sGet<V1beta1DataVolume>({
model: DataVolumeModel,
name: dataVolumeName,
ns: getNamespace(draftVM),
});

dataVolumeTemplates.push({
metadata: {
name: dataVolumeName,
Expand All @@ -77,6 +90,7 @@ const addDataVolumeToVM = (draftVM: WritableDraft<V1VirtualMachine>, dataVolumeN
namespace: getNamespace(draftVM),
},
},
storage: originDataVolume?.spec?.storage as V1beta1StorageSpec,
},
});
};
Expand All @@ -94,7 +108,7 @@ export const persistVolume = (
vmi: V1VirtualMachineInstance,
volumeToPersist: V1Volume,
) =>
produce(vm, (draftVM) => {
produce(vm, async (draftVM) => {
ensurePath(draftVM, 'spec.template.spec.domain.devices');

const vmVolumes = getVolumes(draftVM);
Expand All @@ -119,7 +133,7 @@ export const persistVolume = (
addDiskToVM(draftVM, diskToPersist);

if (!isEmpty(volumeToPersist?.dataVolume?.name))
addDataVolumeToVM(draftVM, volumeToPersist?.dataVolume?.name);
await addDataVolumeToVM(draftVM, volumeToPersist?.dataVolume?.name);

return draftVM;
});
Loading