Skip to content

Commit

Permalink
not all disk types can be selected as the boot source
Browse files Browse the repository at this point in the history
  • Loading branch information
glekner committed Nov 3, 2020
1 parent b23c266 commit 1792c00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
Expand Up @@ -84,7 +84,7 @@ export const setStoragesTabValidity = (options: UpdateOptions) => {
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,5 @@
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 = 'Boot disks can not have a blank source';
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,31 @@ 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 ||
[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 +65,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 1792c00

Please sign in to comment.