Skip to content

Commit

Permalink
Merge pull request #7080 from glekner/update-storagebootsource
Browse files Browse the repository at this point in the history
not all disk types can be selected as the boot source
  • Loading branch information
openshift-merge-robot committed Nov 4, 2020
2 parents ea90110 + e6f2a85 commit c41b530
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
Expand Up @@ -80,11 +80,12 @@ export const setStoragesTabValidity = (options: UpdateOptions) => {
iGetIn(storageBundle, ['disk', 'bootOrder']) === 1 &&
(iGetIn(storageBundle, ['disk', 'disk']) || iGetIn(storageBundle, ['disk', 'cdrom'])) &&
(iGetIn(storageBundle, ['volume', 'persistentVolumeClaim']) ||
iGetIn(storageBundle, ['volume', 'containerDisk']) ||
iGetIn(storageBundle, ['dataVolume', 'spec', 'source', 'pvc']) ||
iGetIn(storageBundle, ['dataVolume', 'spec', 'source', 'http'])),
);
if (!hasBootSource) {
error = 'Please select the boot source.';
error = 'Please select a disk with a defined boot source.';
hasAllRequiredFilled = false;
}
}
Expand Down
@@ -1,3 +1,6 @@
export const ATTACH_CD = 'Attach CD-ROM';
export const NO_BOOTABLE_ATTACHED_DISK_ERROR = 'A bootable attached disk could not be found';
export const BOOTABLE_ATTACHED_DISK_MESSAGE =
'A boot source disk must have a source and can not be blank';
export const NO_BOOTABLE_ATTACHED_DISK_ERROR =
'This disk does not have a source defined and can not be used as a boot source';
export const SELECT_BOOTABLE_DISK = '--- Select Bootable Disk ---';
Expand Up @@ -5,7 +5,11 @@ import { VMWizardStorage } from '../../types';
import { FormRow } from '../../../form/form-row';
import { FormSelectPlaceholderOption } from '../../../form/form-select-placeholder-option';
import { ignoreCaseSort } from '../../../../utils/sort';
import { NO_BOOTABLE_ATTACHED_DISK_ERROR, SELECT_BOOTABLE_DISK } from '../../strings/storage';
import {
NO_BOOTABLE_ATTACHED_DISK_ERROR,
SELECT_BOOTABLE_DISK,
BOOTABLE_ATTACHED_DISK_MESSAGE,
} from '../../strings/storage';
import { VolumeWrapper } from '../../../../k8s/wrapper/vm/volume-wrapper';
import { DataVolumeWrapper } from '../../../../k8s/wrapper/vm/data-volume-wrapper';
import { DiskWrapper } from '../../../../k8s/wrapper/vm/disk-wrapper';
Expand All @@ -26,26 +30,32 @@ export const StorageBootSource: React.FC<StorageBootOrderProps> = ({
storages,
className,
}) => {
const filteredStorages = storages.filter(
({ volume, dataVolume }) =>
new VolumeWrapper(volume).getType() === VolumeType.PERSISTENT_VOLUME_CLAIM ||
[DataVolumeSourceType.PVC, DataVolumeSourceType.HTTP].includes(
new DataVolumeWrapper(dataVolume).getType(),
),
);
const hasStorages = filteredStorages.length > 0;

const selectedStorage = filteredStorages.find((storage) =>
const selectedStorage = storages.find((storage) =>
new DiskWrapper(storage.disk).isFirstBootableDevice(),
);

const isBootSourceValid =
new VolumeWrapper(selectedStorage?.volume).getType() === VolumeType.PERSISTENT_VOLUME_CLAIM ||
new VolumeWrapper(selectedStorage?.volume).getType() === VolumeType.CONTAINER_DISK ||
[DataVolumeSourceType.PVC, DataVolumeSourceType.HTTP].includes(
new DataVolumeWrapper(selectedStorage?.dataVolume).getType(),
);

return (
<Form className={className}>
<FormRow
title="Boot Source"
fieldId={STORAGE_BOOT_SOURCE}
validationMessage={!hasStorages && NO_BOOTABLE_ATTACHED_DISK_ERROR}
validationType={!hasStorages && ValidationErrorType.Error}
validationMessage={
selectedStorage
? !isBootSourceValid && NO_BOOTABLE_ATTACHED_DISK_ERROR
: BOOTABLE_ATTACHED_DISK_MESSAGE
}
validationType={
selectedStorage
? !isBootSourceValid && ValidationErrorType.Error
: ValidationErrorType.Info
}
isRequired
>
<FormSelect
Expand All @@ -56,11 +66,9 @@ export const StorageBootSource: React.FC<StorageBootOrderProps> = ({
isDisabled={isDisabled}
>
<FormSelectPlaceholderOption isDisabled placeholder={SELECT_BOOTABLE_DISK} />
{ignoreCaseSort(filteredStorages, null, (storage) => storage.disk?.name).map(
(storage) => (
<FormSelectOption key={storage.id} value={storage.id} label={storage.disk?.name} />
),
)}
{ignoreCaseSort(storages, null, (storage) => storage.disk?.name).map((storage) => (
<FormSelectOption key={storage.id} value={storage.id} label={storage.disk?.name} />
))}
</FormSelect>
</FormRow>
</Form>
Expand Down

0 comments on commit c41b530

Please sign in to comment.