Skip to content

Commit

Permalink
Add feature guard for Multus
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Dec 4, 2020
1 parent b02ebbf commit e30ae8f
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 62 deletions.
Expand Up @@ -120,7 +120,13 @@ const makeAutoDiscoveryCall = (
});
};

const CreateSC: React.FC<CreateSCProps> = ({ match, hasNoProvSC, mode, lsoNs }) => {
const CreateSC: React.FC<CreateSCProps> = ({
match,
hasNoProvSC,
mode,
lsoNs,
supportedFeatures,
}) => {
const [state, dispatch] = React.useReducer(reducer, initialState);
const [discoveriesData, discoveriesLoaded, discoveriesLoadError] = useK8sWatchResource<
K8sResourceKind[]
Expand Down Expand Up @@ -195,13 +201,25 @@ const CreateSC: React.FC<CreateSCProps> = ({ match, hasNoProvSC, mode, lsoNs })
{
id: CreateStepsSC.CONFIGURE,
name: 'Configure',
component: <Configure dispatch={dispatch} state={state} mode={mode} />,
component: (
<Configure
dispatch={dispatch}
state={state}
mode={mode}
supportedFeatures={supportedFeatures}
/>
),
},
{
id: CreateStepsSC.REVIEWANDCREATE,
name: 'Review and Create',
component: (
<ReviewAndCreate state={state} inProgress={inProgress} errorMessage={errorMessage} />
<ReviewAndCreate
state={state}
inProgress={inProgress}
errorMessage={errorMessage}
supportedFeatures={supportedFeatures}
/>
),
},
];
Expand Down Expand Up @@ -346,6 +364,7 @@ type CreateSCProps = {
setHasNoProvSC: React.Dispatch<React.SetStateAction<boolean>>;
mode: string;
lsoNs: string;
supportedFeatures?: string;
};

export default CreateSC;
Expand Up @@ -2,10 +2,16 @@ import * as React from 'react';
import { Form } from '@patternfly/react-core';
import { State, Action } from '../state';
import { EncryptionFormGroup, NetworkFormGroup } from '../../../install-wizard/configure';
import { NetworkType } from '../../../types';
import { NetworkType, SupportedFeatures } from '../../../types';

export const Configure: React.FC<ConfigureProps> = ({ state, dispatch, mode }) => {
export const Configure: React.FC<ConfigureProps> = ({
state,
dispatch,
mode,
supportedFeatures,
}) => {
const { networkType: nwType, clusterNetwork, publicNetwork } = state;
const isMultusSupported = supportedFeatures.includes(SupportedFeatures.MULTUS);

const setNetworkType = (networkType: NetworkType) => {
dispatch({ type: 'setNetworkType', value: networkType });
Expand All @@ -24,13 +30,15 @@ export const Configure: React.FC<ConfigureProps> = ({ state, dispatch, mode }) =
return (
<Form noValidate={false}>
<EncryptionFormGroup state={state} dispatch={dispatch} mode={mode} />
<NetworkFormGroup
networkType={nwType}
setNetworkType={setNetworkType}
setNetwork={setNetwork}
publicNetwork={publicNetwork}
clusterNetwork={clusterNetwork}
/>
{isMultusSupported && (
<NetworkFormGroup
networkType={nwType}
setNetworkType={setNetworkType}
setNetwork={setNetwork}
publicNetwork={publicNetwork}
clusterNetwork={clusterNetwork}
/>
)}
</Form>
);
};
Expand All @@ -39,4 +47,5 @@ type ConfigureProps = {
state: State;
dispatch: React.Dispatch<Action>;
mode: string;
supportedFeatures?: string;
};
Expand Up @@ -16,17 +16,19 @@ import {
NodesCard,
RequestErrors,
} from '../../../install-wizard/review-and-create';
import { NetworkType } from '../../../types';
import { NetworkType, SupportedFeatures } from '../../../types';

export const ReviewAndCreate: React.FC<ReviewAndCreateProps> = ({
state,
errorMessage,
inProgress,
supportedFeatures,
}) => {
const { nodes, encryption, enableMinimal, storageClass, kms, networkType, publicNetwork } = state;
const { cpu, memory, zones } = getNodeInfo(state.nodes);
const scName = getName(storageClass);
const emptyRequiredField = nodes.length < MINIMUM_NODES && !scName && !memory && !cpu;
const isMultusSupported = supportedFeatures.includes(SupportedFeatures.MULTUS);

return (
<>
Expand Down Expand Up @@ -69,11 +71,13 @@ export const ReviewAndCreate: React.FC<ReviewAndCreateProps> = ({
</ReviewListBody>
</>
)}
<ReviewListBody
validation={networkType === NetworkType.MULTUS && !publicNetwork && VALIDATIONS.NETWORK}
>
<p>Using {NetworkTypeLabels[networkType]}</p>
</ReviewListBody>
{isMultusSupported && (
<ReviewListBody
validation={networkType === NetworkType.MULTUS && !publicNetwork && VALIDATIONS.NETWORK}
>
<p>Using {NetworkTypeLabels[networkType]}</p>
</ReviewListBody>
)}
</dl>
{emptyRequiredField && (
<ValidationMessage
Expand All @@ -90,4 +94,5 @@ type ReviewAndCreateProps = {
errorMessage: string;
inProgress: boolean;
state: State;
supportedFeatures?: string[];
};
Expand Up @@ -15,15 +15,15 @@ import { filterSCWithNoProv } from '../../../utils/install';
import CreateSC from './create-sc/create-sc';
import './attached-devices.scss';

const goToLSOInstallationPage = () => {
const goToLSOInstallationPage = () =>
history.push(
'/operatorhub/all-namespaces?details-item=local-storage-operator-redhat-operators-openshift-marketplace',
);
};

export const CreateAttachedDevicesCluster: React.FC<CreateAttachedDevicesClusterProps> = ({
match,
mode,
supportedFeatures,
}) => {
const { appName, ns } = match.params;
const [hasNoProvSC, setHasNoProvSC] = React.useState(false);
Expand Down Expand Up @@ -93,11 +93,13 @@ export const CreateAttachedDevicesCluster: React.FC<CreateAttachedDevicesCluster
match={match}
lsoNs={lsoNs}
mode={mode}
supportedFeatures={supportedFeatures}
/>
);
};

type CreateAttachedDevicesClusterProps = {
match: RouterMatch<{ appName: string; ns: string }>;
mode: string;
supportedFeatures?: string[];
};
Expand Up @@ -22,14 +22,14 @@ const InstallCluster: React.FC<InstallClusterProps> = ({ match }) => {
url,
} = match;

const [isIndependent, setIndependent] = React.useState(false);
const [isIndepModeSupportedPlatform, setIndepModeSupportedPlatform] = React.useState(false);
const [independentReqdKeys, setIndependentReqdKeys] = React.useState<{ [key: string]: string[] }>(
null,
);
const [downloadFile, setDownloadFile] = React.useState(null);
const [mode, setMode] = React.useState(MODES.INTERNAL);
const [clusterServiceVersion, setClusterServiceVersion] = React.useState(null);
const [supportedFeatures, setSupportedFeatures] = React.useState([]);

const handleModeChange = (event: React.FormEvent<HTMLInputElement>) => {
const { value } = event.currentTarget;
Expand All @@ -39,25 +39,20 @@ const InstallCluster: React.FC<InstallClusterProps> = ({ match }) => {
React.useEffect(() => {
k8sGet(ClusterServiceVersionModel, appName, ns)
.then((clusterServiceVersionObj) => {
// Todo(bipuladh): Remove this check in 4.7
const isIndependentSupported = getAnnotations(clusterServiceVersionObj)[
OCS_SUPPORT_ANNOTATION
].includes('external');
if (isIndependentSupported) {
setIndependent(true);
const { configMaps = [], secrets = [], storageClasses = [] } = getRequiredKeys(
clusterServiceVersionObj,
);
setIndependentReqdKeys({ configMaps, secrets, storageClasses });
setDownloadFile(
createDownloadFile(
getAnnotations(clusterServiceVersionObj)?.[
'external.features.ocs.openshift.io/export-script'
],
),
);
}

setSupportedFeatures(
JSON.parse(clusterServiceVersionObj.metadata.annotation?.[OCS_SUPPORT_ANNOTATION]),
);
const { configMaps = [], secrets = [], storageClasses = [] } = getRequiredKeys(
clusterServiceVersionObj,
);
setIndependentReqdKeys({ configMaps, secrets, storageClasses });
setDownloadFile(
createDownloadFile(
getAnnotations(clusterServiceVersionObj)?.[
'external.features.ocs.openshift.io/export-script'
],
),
);
try {
setClusterServiceVersion(clusterServiceVersionObj);
} catch (e) {
Expand Down Expand Up @@ -117,13 +112,15 @@ const InstallCluster: React.FC<InstallClusterProps> = ({ match }) => {
{
value: MODES.EXTERNAL,
title: MODES.EXTERNAL,
disabled: !isIndependent || !isIndepModeSupportedPlatform,
disabled: !isIndepModeSupportedPlatform,
},
]}
onChange={handleModeChange}
/>
</div>
{mode === MODES.INTERNAL && <CreateInternalCluster match={match} mode={mode} />}
{mode === MODES.INTERNAL && (
<CreateInternalCluster match={match} mode={mode} supportedFeatures={supportedFeatures} />
)}
{mode === MODES.EXTERNAL && (
<CreateExternalCluster
match={match}
Expand All @@ -132,7 +129,11 @@ const InstallCluster: React.FC<InstallClusterProps> = ({ match }) => {
/>
)}
{mode === MODES.ATTACHED_DEVICES && (
<CreateAttachedDevicesCluster match={match} mode={mode} />
<CreateAttachedDevicesCluster
match={match}
mode={mode}
supportedFeatures={supportedFeatures}
/>
)}
</>
);
Expand Down
Expand Up @@ -2,10 +2,16 @@ import * as React from 'react';
import { Form } from '@patternfly/react-core';
import { InternalClusterAction, InternalClusterState, ActionType } from '../reducer';
import { EncryptionFormGroup, NetworkFormGroup } from '../../install-wizard/configure';
import { NetworkType } from '../../types';
import { NetworkType, SupportedFeatures } from '../../types';

export const Configure: React.FC<ConfigureProps> = ({ state, dispatch, mode }) => {
export const Configure: React.FC<ConfigureProps> = ({
state,
dispatch,
mode,
supportedFeatures,
}) => {
const { networkType: nwType, publicNetwork, clusterNetwork } = state;
const isMultusSupported = supportedFeatures.includes(SupportedFeatures.MULTUS);

const setNetworkType = (networkType: NetworkType) =>
dispatch({ type: ActionType.SET_NETWORK_TYPE, payload: networkType });
Expand All @@ -18,13 +24,15 @@ export const Configure: React.FC<ConfigureProps> = ({ state, dispatch, mode }) =
return (
<Form noValidate={false}>
<EncryptionFormGroup state={state} dispatch={dispatch} mode={mode} />
<NetworkFormGroup
setNetworkType={setNetworkType}
setNetwork={setNetwork}
networkType={nwType}
publicNetwork={publicNetwork}
clusterNetwork={clusterNetwork}
/>
{isMultusSupported && (
<NetworkFormGroup
setNetworkType={setNetworkType}
setNetwork={setNetwork}
networkType={nwType}
publicNetwork={publicNetwork}
clusterNetwork={clusterNetwork}
/>
)}
</Form>
);
};
Expand All @@ -33,4 +41,5 @@ type ConfigureProps = {
state: InternalClusterState;
dispatch: React.Dispatch<InternalClusterAction>;
mode: string;
supportedFeatures?: string[];
};
Expand Up @@ -17,12 +17,13 @@ import {
NodesCard,
RequestErrors,
} from '../../install-wizard/review-and-create';
import { NetworkType } from '../../types';
import { NetworkType, SupportedFeatures } from '../../types';

export const ReviewAndCreate: React.FC<ReviewAndCreateProps> = ({
state,
errorMessage,
inProgress,
supportedFeatures,
}) => {
const {
nodes,
Expand All @@ -38,6 +39,7 @@ export const ReviewAndCreate: React.FC<ReviewAndCreateProps> = ({
const scName = getName(storageClass);
const emptyRequiredField =
nodes.length < MINIMUM_NODES && !zones.size && !scName && !memory && !cpu;
const isMultusSupported = supportedFeatures.includes(SupportedFeatures.MULTUS);

return (
<>
Expand Down Expand Up @@ -77,7 +79,6 @@ export const ReviewAndCreate: React.FC<ReviewAndCreateProps> = ({
<p>{pluralize(zones.size, 'zone')}</p>
</ReviewListBody>
{/* @TODO: Update the check from Configure when adding more items */}
<ReviewListTitle text="Configure" />
{(encryption.clusterWide || encryption.storageClass) && (
<>
<ReviewListTitle text="Configure" />
Expand All @@ -92,11 +93,13 @@ export const ReviewAndCreate: React.FC<ReviewAndCreateProps> = ({
</ReviewListBody>
</>
)}
<ReviewListBody
validation={networkType === NetworkType.MULTUS && !publicNetwork && VALIDATIONS.NETWORK}
>
<p>Using {NetworkTypeLabels[networkType]}</p>
</ReviewListBody>
{isMultusSupported && (
<ReviewListBody
validation={networkType === NetworkType.MULTUS && !publicNetwork && VALIDATIONS.NETWORK}
>
<p>Using {NetworkTypeLabels[networkType]}</p>
</ReviewListBody>
)}
</dl>
{emptyRequiredField && (
<ValidationMessage
Expand All @@ -113,4 +116,5 @@ type ReviewAndCreateProps = {
errorMessage: string;
inProgress: boolean;
state: InternalClusterState;
supportedFeatures?: string[];
};

0 comments on commit e30ae8f

Please sign in to comment.