CreateImageWizard: initialize on-prem with host distro

Initialize the create image wizard with the host's distribution for the
on-premise frontend.
This commit is contained in:
Gianluca Zuccarelli 2025-01-23 14:07:38 +00:00 committed by Sanne Raymaekers
parent ed8254f962
commit 44af2f278b
4 changed files with 42 additions and 10 deletions

View file

@ -34,6 +34,7 @@ import Azure from './steps/TargetEnvironment/Azure';
import Gcp from './steps/TargetEnvironment/Gcp';
import TimezoneStep from './steps/Timezone';
import UsersStep from './steps/Users';
import { getHostDistro } from './utilities/getHostInfo';
import {
useFilesystemValidation,
useSnapshotValidation,
@ -192,6 +193,17 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
if (searchParams.get('target') === 'qcow2') {
dispatch(addImageType('guest-image'));
}
const initializeHostDistro = async () => {
const distro = await getHostDistro();
dispatch(changeDistribution(distro));
};
if (process.env.IS_ON_PREMISE) {
if (!searchParams.get('release')) {
initializeHostDistro();
}
}
// This useEffect hook should run *only* on mount and therefore has an empty
// dependency array. eslint's exhaustive-deps rule does not support this use.
// eslint-disable-next-line react-hooks/exhaustive-deps

View file

@ -17,6 +17,7 @@ import {
RHEL_9_FULL_SUPPORT,
RHEL_9_MAINTENANCE_SUPPORT,
RHEL_10_BETA,
ON_PREM_RELEASES,
} from '../../../../constants';
import { useAppDispatch, useAppSelector } from '../../../../store/hooks';
import { Distributions } from '../../../../store/imageBuilderApi';
@ -40,6 +41,8 @@ const ReleaseSelect = () => {
const isRHEL9BetaEnabled = useFlag('image-builder.rhel9.beta.enabled');
const isRHEL10BetaEnabled = useFlag('image-builder.rhel10.beta.enabled');
const releases = process.env.IS_ON_PREMISE ? ON_PREM_RELEASES : RELEASES;
const handleSelect = (_event: React.MouseEvent, selection: Distributions) => {
dispatch(changeDistribution(selection));
setIsOpen(false);
@ -75,7 +78,11 @@ const ReleaseSelect = () => {
const setSelectOptions = () => {
const options: ReactElement[] = [];
const filteredRhel = new Map(
[...RELEASES].filter(([key]) => {
[...releases].filter(([key]) => {
if (process.env.IS_ON_PREMISE) {
return key === distribution;
}
if (key === RHEL_9_BETA) {
return isRHEL9BetaEnabled;
}
@ -99,7 +106,7 @@ const ReleaseSelect = () => {
value={key}
description={setDescription(key as Distributions)}
>
{RELEASES.get(key)}
{releases.get(key)}
</SelectOption>
);
});
@ -114,14 +121,17 @@ const ReleaseSelect = () => {
variant={SelectVariant.single}
onToggle={() => setIsOpen(!isOpen)}
onSelect={handleSelect}
selections={RELEASES.get(distribution)}
selections={releases.get(distribution)}
isOpen={isOpen}
{...(!showDevelopmentOptions && {
loadingVariant: {
text: 'Show options for further development of RHEL',
onClick: handleExpand,
},
})}
{...(!showDevelopmentOptions &&
// Hide this for on-prem since the host
// could be centos or fedora
!process.env.IS_ON_PREMISE && {
loadingVariant: {
text: 'Show options for further development of RHEL',
onClick: handleExpand,
},
})}
>
{setSelectOptions()}
</Select>

View file

@ -24,6 +24,7 @@ import {
import { FSReviewTable } from './ReviewStepTables';
import {
ON_PREM_RELEASES,
RELEASES,
RHEL_8,
RHEL_8_FULL_SUPPORT,
@ -93,6 +94,7 @@ const ExpirationWarning = () => {
export const ImageOutputList = () => {
const distribution = useAppSelector(selectDistribution);
const arch = useAppSelector(selectArchitecture);
const releases = process.env.IS_ON_PREMISE ? ON_PREM_RELEASES : RELEASES;
return (
<TextContent>
{distribution === RHEL_8 && (
@ -118,7 +120,7 @@ export const ImageOutputList = () => {
Release
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{RELEASES.get(distribution)}
{releases.get(distribution)}
</TextListItem>
<TextListItem component={TextListItemVariants.dt}>
Architecture

View file

@ -0,0 +1,8 @@
import { read_os_release } from 'os-release';
import { Distributions } from '../../../store/imageBuilderApi';
export const getHostDistro = async () => {
const osRel = await read_os_release();
return `${osRel.ID}-${osRel.VERSION_ID}` as Distributions;
};