Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions frontend/__tests__/components/cluster-settings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
} from '../../public/components/cluster-settings/cluster-settings';
import { GlobalConfigPage } from '../../public/components/cluster-settings/global-config';
import { Firehose, HorizontalNav, ResourceLink, Timestamp } from '../../public/components/utils';
import { AddCircleOIcon } from '@patternfly/react-icons';

jest.mock('react-i18next', () => {
const reactI18next = require.requireActual('react-i18next');
Expand All @@ -44,6 +43,15 @@ jest.mock('@console/internal/components/utils/k8s-watch-hook', () => ({
useK8sWatchResource: jest.fn(),
}));

jest.mock('react-redux', () => {
const ActualReactRedux = require.requireActual('react-redux');
return {
...ActualReactRedux,
useSelector: jest.fn(),
useDispatch: jest.fn(),
};
});

const i18nNS = 'cluster-settings';

describe('Cluster Settings page', () => {
Expand All @@ -68,19 +76,13 @@ describe('Cluster Settings page', () => {
.find(Firehose)
.at(0)
.props().resources.length,
).toBe(2);
).toBe(1);
expect(
wrapper
.find(Firehose)
.at(0)
.props().resources[0].kind,
).toBe('config.openshift.io~v1~ClusterVersion');
expect(
wrapper
.find(Firehose)
.at(0)
.props().resources[1].kind,
).toBe('autoscaling.openshift.io~v1~ClusterAutoscaler');
expect(
wrapper
.find(Firehose)
Expand All @@ -93,12 +95,6 @@ describe('Cluster Settings page', () => {
.at(0)
.props().resources[0].isList,
).toBe(false);
expect(
wrapper
.find(Firehose)
.at(0)
.props().resources[1].isList,
).toBe(true);
});
it('should render the HorizontalNav Component with the props', () => {
expect(wrapper.find(HorizontalNav).exists()).toBe(true);
Expand Down Expand Up @@ -168,7 +164,6 @@ describe('Cluster Version Details Table page', () => {
expect(wrapper.find(UpdatesGraph).exists()).toBe(true);
expect(wrapper.find(UpdateInProgress).exists()).toBe(false);
expect(wrapper.find(ResourceLink).exists()).toBe(true);
expect(wrapper.find(AddCircleOIcon).exists()).toBe(true);
expect(wrapper.find(Timestamp).exists()).toBe(true);
});
it('should render correct values of ClusterVersionDetailsTable component', () => {
Expand Down Expand Up @@ -198,24 +193,6 @@ describe('Cluster Version Details Table page', () => {
.at(0)
.props().name,
).toEqual('version');
expect(
wrapper
.find(Link)
.childAt(1)
.text(),
).toEqual(`${i18nNS}~Create autoscaler`);
expect(
wrapper
.find(ResourceLink)
.at(0)
.props().name,
).toEqual('version');
expect(
wrapper
.find(Link)
.childAt(1)
.text(),
).toEqual(`${i18nNS}~Create autoscaler`);
expect(
wrapper
.find(Timestamp)
Expand Down
1 change: 1 addition & 0 deletions frontend/__tests__/reducers/features.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('featureReducer', () => {
[FLAGS.CONSOLE_NOTIFICATION]: false,
[FLAGS.CONSOLE_EXTERNAL_LOG_LINK]: false,
[FLAGS.CONSOLE_YAML_SAMPLE]: false,
[FLAGS.CLUSTER_AUTOSCALER]: false,
}),
);
});
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/console-shared/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export enum FLAGS {
CAN_LIST_PACKAGE_MANIFEST = 'CAN_LIST_PACKAGE_MANIFEST',
CAN_CREATE_PROJECT = 'CAN_CREATE_PROJECT',
CAN_LIST_VSC = 'CAN_LIST_VSC',
CLUSTER_AUTOSCALER = 'CLUSTER_AUTOSCALER',
SHOW_OPENSHIFT_START_GUIDE = 'SHOW_OPENSHIFT_START_GUIDE',
SERVICE_CATALOG = 'SERVICE_CATALOG',
CLUSTER_API = 'CLUSTER_API',
Expand Down
57 changes: 36 additions & 21 deletions frontend/public/components/cluster-settings/cluster-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
EmptyBox,
ExternalLink,
Firehose,
FirehoseResource,
HorizontalNav,
openshiftHelpBase,
ResourceLink,
Expand All @@ -89,6 +90,8 @@ import {
RedExclamationCircleIcon,
YellowExclamationTriangleIcon,
} from '@console/shared';
import { useFlag } from '@console/shared/src/hooks/flag';
import { FLAGS } from '@console/shared/src/constants';

const cancelUpdate = (cv: ClusterVersionKind) => {
k8sPatch(ClusterVersionModel, cv, [{ path: '/spec/desiredUpdate', op: 'remove' }]).catch(
Expand Down Expand Up @@ -875,24 +878,28 @@ export const ClusterVersionDetailsTable: React.FC<ClusterVersionDetailsTableProp
<dd>
<ResourceLink kind={referenceForModel(ClusterVersionModel)} name={cv.metadata.name} />
</dd>
<dt>{t('cluster-settings~Cluster autoscaler')}</dt>
<dd>
{_.isEmpty(autoscalers) ? (
<Link to={`${resourcePathFromModel(ClusterAutoscalerModel)}/~new`}>
<AddCircleOIcon className="co-icon-space-r" />
{t('cluster-settings~Create autoscaler')}
</Link>
) : (
autoscalers.map((autoscaler) => (
<div key={autoscaler.metadata.uid}>
<ResourceLink
kind={clusterAutoscalerReference}
name={autoscaler.metadata.name}
/>
</div>
))
)}
</dd>
{autoscalers && (
<>
<dt>{t('cluster-settings~Cluster autoscaler')}</dt>
<dd>
{_.isEmpty(autoscalers) ? (
<Link to={`${resourcePathFromModel(ClusterAutoscalerModel)}/~new`}>
<AddCircleOIcon className="co-icon-space-r" />
{t('cluster-settings~Create autoscaler')}
</Link>
) : (
autoscalers.map((autoscaler) => (
<div key={autoscaler.metadata.uid}>
<ResourceLink
kind={clusterAutoscalerReference}
name={autoscaler.metadata.name}
/>
</div>
))
)}
</dd>
</>
)}
</dl>
</div>
</div>
Expand Down Expand Up @@ -960,11 +967,19 @@ export const ClusterOperatorTabPage: React.FC<ClusterOperatorTabPageProps> = ({

export const ClusterSettingsPage: React.FC<ClusterSettingsPageProps> = ({ match }) => {
const { t } = useTranslation();
const hasClusterAutoscaler = useFlag(FLAGS.CLUSTER_AUTOSCALER);
const title = t('cluster-settings~Cluster Settings');
const resources = [
const resources: FirehoseResource[] = [
{ kind: clusterVersionReference, name: 'version', isList: false, prop: 'obj' },
{ kind: clusterAutoscalerReference, isList: true, prop: 'autoscalers', optional: true },
];
if (hasClusterAutoscaler) {
resources.push({
kind: clusterAutoscalerReference,
isList: true,
prop: 'autoscalers',
optional: true,
});
}
const resourceKeys = _.map(resources, 'prop');
const pages = [
{
Expand Down Expand Up @@ -1098,7 +1113,7 @@ type UpdateInProgressProps = {

type ClusterVersionDetailsTableProps = {
obj: ClusterVersionKind;
autoscalers: K8sResourceKind[];
autoscalers?: K8sResourceKind[];
};

type ClusterVersionConditionsLinkProps = {
Expand Down
2 changes: 2 additions & 0 deletions frontend/public/reducers/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@console/plugin-sdk/src/api/subscribeToExtensions';
import {
ChargebackReportModel,
ClusterAutoscalerModel,
ClusterServiceClassModel,
ConsoleCLIDownloadModel,
ConsoleExternalLogLinkModel,
Expand Down Expand Up @@ -38,6 +39,7 @@ export const defaults = _.mapValues(FLAGS, (flag) =>

export const baseCRDs = {
[referenceForModel(ChargebackReportModel)]: FLAGS.CHARGEBACK,
[referenceForModel(ClusterAutoscalerModel)]: FLAGS.CLUSTER_AUTOSCALER,
[referenceForModel(ClusterServiceClassModel)]: FLAGS.SERVICE_CATALOG,
[referenceForModel(ConsoleLinkModel)]: FLAGS.CONSOLE_LINK,
[referenceForModel(ConsoleCLIDownloadModel)]: FLAGS.CONSOLE_CLI_DOWNLOAD,
Expand Down