From d31fea62de1b8b832623bf3522de54720d31f747 Mon Sep 17 00:00:00 2001 From: Ugo Palatucci Date: Wed, 18 Sep 2024 09:19:46 +0200 Subject: [PATCH] CNV-44913 missing storage settings on other disk modal --- src/utils/components/DiskModal/OtherDiskModal.tsx | 6 +++++- src/utils/components/DiskModal/utils/helpers.ts | 11 ++++++++++- src/utils/resources/vm/utils/disk/rowData.ts | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/utils/components/DiskModal/OtherDiskModal.tsx b/src/utils/components/DiskModal/OtherDiskModal.tsx index d041e4d5d..88d0bda7a 100644 --- a/src/utils/components/DiskModal/OtherDiskModal.tsx +++ b/src/utils/components/DiskModal/OtherDiskModal.tsx @@ -13,8 +13,9 @@ import DiskInterfaceSelect from './components/DiskInterfaceSelect/DiskInterfaceS import DiskNameInput from './components/DiskNameInput/DiskNameInput'; import DiskTypeSelect from './components/DiskTypeSelect/DiskTypeSelect'; import PendingChanges from './components/PendingChanges'; +import StorageClassAndPreallocation from './components/StorageClassAndPreallocation/StorageClassAndPreallocation'; import { getDefaultCreateValues, getDefaultEditValues } from './utils/form'; -import { diskModalTitle } from './utils/helpers'; +import { diskModalTitle, doesDataVolumeTemplateHaveDisk } from './utils/helpers'; import { submit } from './utils/submit'; import { SourceTypes, V1DiskFormState, V1DiskModalProps } from './utils/types'; @@ -50,6 +51,9 @@ const OtherDiskModal: FC = ({ editDiskName, isOpen, onClose, o + {doesDataVolumeTemplateHaveDisk(vm, editDiskName) && ( + + )} diff --git a/src/utils/components/DiskModal/utils/helpers.ts b/src/utils/components/DiskModal/utils/helpers.ts index 2e90507d0..de27f5c7e 100644 --- a/src/utils/components/DiskModal/utils/helpers.ts +++ b/src/utils/components/DiskModal/utils/helpers.ts @@ -22,7 +22,7 @@ import { import { ANNOTATIONS } from '@kubevirt-utils/resources/template'; import { getBootDisk, getDataVolumeTemplates, getVolumes } from '@kubevirt-utils/resources/vm'; import { getOperatingSystem } from '@kubevirt-utils/resources/vm/utils/operation-system/operationSystem'; -import { ensurePath } from '@kubevirt-utils/utils/utils'; +import { ensurePath, isEmpty } from '@kubevirt-utils/utils/utils'; import { k8sCreate } from '@openshift-console/dynamic-plugin-sdk'; import { addPersistentVolume, removeVolume } from '@virtualmachines/actions/actions'; @@ -229,3 +229,12 @@ export const diskModalTitle = (isEditDisk: boolean, isVMRunning: boolean) => { export const getOS = (vm: V1VirtualMachine) => getAnnotation(vm?.spec?.template, ANNOTATIONS.os) || getOperatingSystem(vm); + +export const doesDataVolumeTemplateHaveDisk = (vm: V1VirtualMachine, diskName: string) => { + const diskVolume = getVolumes(vm)?.find((volume) => volume.name === diskName); + const dataVolumeTemplate = getDataVolumeTemplates(vm)?.find( + (dv) => getName(dv) === diskVolume?.dataVolume?.name, + ); + + return !isEmpty(dataVolumeTemplate); +}; diff --git a/src/utils/resources/vm/utils/disk/rowData.ts b/src/utils/resources/vm/utils/disk/rowData.ts index 345679ded..110a59938 100644 --- a/src/utils/resources/vm/utils/disk/rowData.ts +++ b/src/utils/resources/vm/utils/disk/rowData.ts @@ -40,7 +40,7 @@ export const getDiskRowDataLayout = ( namespace: device?.pvc?.metadata?.namespace, size: NO_DATA_DASH, source: OTHER, - storageClass: NO_DATA_DASH, + storageClass: device?.dataVolumeTemplate?.spec?.storage?.storageClassName || NO_DATA_DASH, }; const pvcSize = device?.pvc?.spec?.resources?.requests?.storage;