Skip to content

Commit

Permalink
Merge pull request #2115 from upalatucci/fix-diskmodal-1
Browse files Browse the repository at this point in the history
CNV-44890: fix diskmodal issues
  • Loading branch information
openshift-merge-bot[bot] authored Aug 6, 2024
2 parents e9f0f4f + 9b6f1ec commit 8ea6061
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
29 changes: 21 additions & 8 deletions src/utils/components/DiskModal/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {
V1Volume,
} from '@kubevirt-ui/kubevirt-api/kubevirt';
import { t } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { buildOwnerReference, getAnnotation, getName } from '@kubevirt-utils/resources/shared';
import {
buildOwnerReference,
getAnnotation,
getName,
getNamespace,
} from '@kubevirt-utils/resources/shared';
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';
Expand Down Expand Up @@ -105,9 +110,11 @@ const getDataVolumeHotplugPromise = (
},
};

return k8sCreate({ data: resultDataVolume, model: DataVolumeModel }).then(() =>
addPersistentVolume(vm, bodyRequestAddVolume),
) as Promise<void>;
return k8sCreate({
data: resultDataVolume,
model: DataVolumeModel,
ns: getNamespace(resultDataVolume),
}).then(() => addPersistentVolume(vm, bodyRequestAddVolume)) as Promise<void>;
};

const getPersistentVolumeClaimHotplugPromise = (
Expand Down Expand Up @@ -143,11 +150,17 @@ export const hotplugPromise = (vmObj: V1VirtualMachine, diskState: V1DiskFormSta
return getPersistentVolumeClaimHotplugPromise(vmObj, pvcName, diskState.disk);
}

diskState.dataVolumeTemplate.metadata.ownerReferences = [
buildOwnerReference(vmObj, { blockOwnerDeletion: false }),
];
const dataVolume = produce(diskState.dataVolumeTemplate, (draftDataVolumeTemplate) => {
draftDataVolumeTemplate.metadata.ownerReferences = [
buildOwnerReference(vmObj, { blockOwnerDeletion: false }),
];

draftDataVolumeTemplate.metadata.namespace = getNamespace(vmObj);
draftDataVolumeTemplate.kind = DataVolumeModel.kind;
draftDataVolumeTemplate.apiVersion = `${DataVolumeModel.apiGroup}/${DataVolumeModel.apiVersion}`;
});

return getDataVolumeHotplugPromise(vmObj, diskState.dataVolumeTemplate, diskState.disk);
return getDataVolumeHotplugPromise(vmObj, dataVolume, diskState.disk);
};

export const produceVMDisks = (
Expand Down
15 changes: 7 additions & 8 deletions src/utils/resources/vm/utils/disk/rowData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export const getDiskRowDataLayout = (
storageClass: NO_DATA_DASH,
};

if (device?.dataVolumeTemplate) {
const pvcSize = device?.pvc?.spec?.resources?.requests?.storage;
const dataVolumeCustomSize =
device?.dataVolumeTemplate?.spec?.storage?.resources?.requests?.storage;

if (device?.dataVolumeTemplate && (dataVolumeCustomSize || pvcSize)) {
diskRowDataObject.size = humanizeBinaryBytes(
convertToBaseValue(
device?.dataVolumeTemplate?.spec?.storage?.resources?.requests?.storage ||
device?.pvc?.spec?.resources?.requests?.storage,
),
convertToBaseValue(dataVolumeCustomSize || pvcSize),
).string;

return diskRowDataObject;
Expand All @@ -57,9 +58,7 @@ export const getDiskRowDataLayout = (
if (device?.pvc) {
diskRowDataObject.source = device?.pvc?.metadata?.name;
diskRowDataObject.sourceStatus = device?.pvc?.status?.phase;
diskRowDataObject.size = humanizeBinaryBytes(
convertToBaseValue(device?.pvc?.spec?.resources?.requests?.storage),
).string;
diskRowDataObject.size = humanizeBinaryBytes(convertToBaseValue(pvcSize)).string;
diskRowDataObject.storageClass = device?.pvc?.spec?.storageClassName;
}

Expand Down

0 comments on commit 8ea6061

Please sign in to comment.