Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Jan 15, 2020
1 parent eea69ac commit c0847fe
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export const PODS = 'Pods';
export const BY_USED = 'By Used Capacity';
export const BY_REQUESTED = 'By Requested Capacity';
export const OCS_OPERATOR = 'ocs-operator';
export const INDEPENDENT_FLAG = 'INDEPENDENT_FLAG';
2 changes: 1 addition & 1 deletion frontend/packages/ceph-storage-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
STORAGE_HEALTH_QUERIES,
} from './constants/queries';
import { getCephHealthState } from './components/dashboard-page/storage-dashboard/status-card/utils';
import { INDEPENDENT_FLAG } from './constants';

type ConsumedExtensions =
| ModelFeatureFlag
Expand All @@ -33,7 +34,6 @@ type ConsumedExtensions =
| ClusterServiceVersionAction;

const CEPH_FLAG = 'CEPH';
const INDEPENDENT_FLAG = 'INDEPENDENT_FLAG';
const apiObjectRef = referenceForModel(models.OCSServiceModel);

const plugin: Plugin<ConsumedExtensions> = [
Expand Down
5 changes: 0 additions & 5 deletions frontend/packages/console-plugin-sdk/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
isProjectDashboardInventoryItem,
isReduxReducer,
isDashboardsOverviewInventoryItemReplacement,
isFeatureAction,
} from './typings';

/**
Expand Down Expand Up @@ -179,10 +178,6 @@ export class ExtensionRegistry {
public getDashboardsOverviewInventoryItemReplacements() {
return this.extensions.filter(isDashboardsOverviewInventoryItemReplacement);
}

public getFeatureAction() {
return this.extensions.filter(isFeatureAction);
}
}

type ExtensionWithFlags = Extension<{ required?: string | string[]; blocker?: string | string[] }>;
1 change: 0 additions & 1 deletion frontend/packages/console-shared/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ export enum FLAGS {
CONSOLE_NOTIFICATION = 'CONSOLE_NOTIFICATION',
CONSOLE_EXTERNAL_LOG_LINK = 'CONSOLE_EXTERNAL_LOG_LINK',
CONSOLE_YAML_SAMPLE = 'CONSOLE_YAML_SAMPLE',
BAREMETAL = 'BAREMETAL',
}
3 changes: 2 additions & 1 deletion frontend/packages/metal3-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"dependencies": {
"@console/plugin-sdk": "0.0.0-fixed",
"@console/shared": "0.0.0-fixed"
"@console/shared": "0.0.0-fixed",
"@console/ocs-independent-plugin": "0.0.0-fixed"
},
"consolePlugin": {
"entry": "src/plugin.tsx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ export const HOST_HARDWARE_ERROR_STATES = [HOST_STATUS_POWER_MANAGEMENT_ERROR];
export const HOST_HEALTH_OK = 'Host is healthy';
export const HOST_HEALTH_ERROR = 'Host is in an error state';
export const HOST_HEALTH_LOADING = 'Loading host health data';
export const BAREMETAL = 'BAREMETAL';
15 changes: 15 additions & 0 deletions frontend/packages/metal3-plugin/src/feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { k8sGet, K8sResourceKind } from '@console/internal/module/k8s';
import { InfrastructureModel } from '@console/internal/models';
import { getInfrastructurePlatform } from '@console/shared';
import { setFlag } from '@console/ocs-independent-plugin/src/feature';
import { BAREMETAL } from './constants';

export const detectBaremetalPlatform = (dispatch) =>
k8sGet(InfrastructureModel, 'cluster').then(
(infra: K8sResourceKind) =>
dispatch(setFlag(BAREMETAL, getInfrastructurePlatform(infra) === 'BareMetal')),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(err) => {
dispatch(setFlag(BAREMETAL, false));
},
);
32 changes: 22 additions & 10 deletions frontend/packages/metal3-plugin/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ import {
DashboardsOverviewResourceActivity,
DashboardsOverviewInventoryItemReplacement,
DashboardsInventoryItemGroup,
ActionFeatureFlag,
} from '@console/plugin-sdk';
import { referenceForModel } from '@console/internal/module/k8s';
import { MachineModel, NodeModel } from '@console/internal/models';
import { FLAGS } from '@console/shared/src/constants';
import { BareMetalHostModel, NodeMaintenanceModel } from './models';
import { getBMHStatusGroups } from './components/baremetal-hosts/dashboard/utils';
import { getBMNStatusGroups } from './components/baremetal-nodes/dashboard/utils';
import { getHostPowerStatus } from './selectors';
import { HOST_POWER_STATUS_POWERING_OFF, HOST_POWER_STATUS_POWERING_ON } from './constants';
import {
HOST_POWER_STATUS_POWERING_OFF,
HOST_POWER_STATUS_POWERING_ON,
BAREMETAL,
} from './constants';
import { BareMetalHostKind } from './types';
import { detectBaremetalPlatform } from './feature';

type ConsumedExtensions =
| DashboardsOverviewInventoryItem
Expand All @@ -34,6 +39,7 @@ type ConsumedExtensions =
| RoutePage
| ModelFeatureFlag
| ModelDefinition
| ActionFeatureFlag
| DashboardsOverviewResourceActivity;

const METAL3_FLAG = 'METAL3';
Expand All @@ -52,14 +58,20 @@ const plugin: Plugin<ConsumedExtensions> = [
flag: METAL3_FLAG,
},
},
{
type: 'FeatureFlag/Action',
properties: {
detect: detectBaremetalPlatform,
},
},
{
type: 'NavItem/ResourceNS',
properties: {
section: 'Compute',
componentProps: {
name: 'Bare Metal Hosts',
resource: referenceForModel(BareMetalHostModel),
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
mergeBefore: 'ComputeSeparator',
},
Expand Down Expand Up @@ -93,7 +105,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-hosts/add-baremetal-host/AddBareMetalHostPage' /* webpackChunkName: "metal3-baremetalhost" */
).then((m) => m.default),
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
{
Expand All @@ -109,7 +121,7 @@ const plugin: Plugin<ConsumedExtensions> = [
},
],
mapper: getBMNStatusGroups,
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
{
Expand All @@ -135,7 +147,7 @@ const plugin: Plugin<ConsumedExtensions> = [
],
model: BareMetalHostModel,
mapper: getBMHStatusGroups,
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
{
Expand All @@ -147,7 +159,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-nodes/BareMetalNodesPage' /* webpackChunkName: "node" */
).then((m) => m.default),
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
{
Expand All @@ -159,7 +171,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-nodes/BareMetalNodeDetailsPage' /* webpackChunkName: "node" */
).then((m) => m.default),
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
{
Expand All @@ -176,7 +188,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/maintenance/MaintenanceDashboardActivity' /* webpackChunkName: "node-maintenance" */
).then((m) => m.default),
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
{
Expand All @@ -202,7 +214,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-hosts/dashboard/BareMetalStatusActivity' /* webpackChunkName: "metal3-powering" */
).then((m) => m.default),
required: [FLAGS.BAREMETAL, METAL3_FLAG],
required: [BAREMETAL, METAL3_FLAG],
},
},
];
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/ocs-independent-plugin/src/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const INDEPENDENT_FLAG = 'INDEPENDENT_FLAG';
24 changes: 24 additions & 0 deletions frontend/packages/ocs-independent-plugin/src/feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { k8sGet } from '@console/internal/module/k8s';
import { action } from 'typesafe-actions';
import { OCSServiceModel } from './models';
import { INDEPENDENT_FLAG } from './consts';

enum ActionType {
SetFlag = 'setFlag',
ClearSSARFlags = 'clearSSARFlags',
}

export const setFlag = (flag: string, value: boolean) =>
action(ActionType.SetFlag, { flag, value });

export const detectIndependentMode = (dispatch) =>
k8sGet(OCSServiceModel, 'ocs-storagecluster', 'openshift-storage')
.then(() => {
// eslint-disable-next-line no-console
console.log('Independent mode is active');
dispatch(setFlag(INDEPENDENT_FLAG, true));
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((err) => {
dispatch(setFlag(INDEPENDENT_FLAG, false));
});
27 changes: 7 additions & 20 deletions frontend/packages/ocs-independent-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
import {
DashboardsTab,
FeatureAction,
ModelDefinition,
ModelFeatureFlag,
Plugin,
DashboardsCard,
ActionFeatureFlag,
} from '@console/plugin-sdk';
import { k8sGet } from '@console/internal/module/k8s';
import { GridPosition } from '@console/shared/src/components/dashboard/DashboardGrid';
import { OCSServiceModel } from './models';
import { OCSServiceModel } from '@console/ceph-storage-plugin/src/models';
import { detectIndependentMode } from './feature';
import { INDEPENDENT_FLAG } from './consts';

type ConsumedExtensions =
| DashboardsTab
| DashboardsCard
| FeatureAction
| ActionFeatureFlag
| ModelFeatureFlag
| ModelDefinition;

const INDEPENDENT_FLAG = 'INDEPENDENT_FLAG';

const detectIndependentMode = (dispatch) =>
k8sGet(OCSServiceModel, 'ocs-storagecluster', 'openshift-storage')
.then(() => {
// eslint-disable-next-line no-console
console.log('Independent mode is active');
dispatch({ type: 'setFlag', payload: { flag: INDEPENDENT_FLAG, value: true } });
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((err) => {
dispatch({ type: 'setFlag', payload: { flag: INDEPENDENT_FLAG, value: true } });
});

const plugin: Plugin<ConsumedExtensions> = [
{
type: 'FeatureFlag/Model',
Expand All @@ -40,9 +27,9 @@ const plugin: Plugin<ConsumedExtensions> = [
},
},
{
type: 'Feature/Action',
type: 'FeatureFlag/Action',
properties: {
featureDetector: detectIndependentMode,
detect: detectIndependentMode,
},
},
{
Expand Down
27 changes: 5 additions & 22 deletions frontend/public/actions/features.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { Dispatch } from 'react-redux';
import * as _ from 'lodash-es';
import { ActionType as Action, action } from 'typesafe-actions';
import { getInfrastructurePlatform } from '@console/shared/src/selectors';
import { FLAGS } from '@console/shared/src/constants';
import {
GroupModel,
InfrastructureModel,
SelfSubjectAccessReviewModel,
UserModel,
} from '../models';
import { k8sBasePath, ClusterVersionKind, k8sCreate, k8sGet, K8sResourceKind } from '../module/k8s';
import { FLAGS } from '@console/shared/src/constants/common';
import { GroupModel, SelfSubjectAccessReviewModel, UserModel } from '../models';
import { k8sBasePath, ClusterVersionKind, k8sCreate } from '../module/k8s';
import { receivedResources } from './k8s';
import { coFetchJSON } from '../co-fetch';
import { MonitoringRoutes } from '../reducers/monitoring';
Expand All @@ -26,7 +20,8 @@ export const defaults = _.mapValues(FLAGS, (flag) =>
flag === FLAGS.AUTH_ENABLED ? !window.SERVER_FLAGS.authDisabled : undefined,
);

export const setFlag = (flag: FLAGS, value: boolean) => action(ActionType.SetFlag, { flag, value });
export const setFlag = (flag: FLAGS | string, value: boolean) =>
action(ActionType.SetFlag, { flag, value });

const retryFlagDetection = (dispatch, cb) => {
setTimeout(() => cb(dispatch), 15000);
Expand Down Expand Up @@ -166,17 +161,6 @@ const detectOpenShift = (dispatch) =>
: handleError(err, FLAGS.OPENSHIFT, dispatch, detectOpenShift),
);

const detectBaremetalPlatform = (dispatch) =>
k8sGet(InfrastructureModel, 'cluster').then(
(infra: K8sResourceKind) =>
dispatch(setFlag(FLAGS.BAREMETAL, getInfrastructurePlatform(infra) === 'BareMetal')),
(err) => {
_.get(err, 'response.status') === 404
? dispatch(setFlag(FLAGS.BAREMETAL, false))
: handleError(err, FLAGS.BAREMETAL, dispatch, detectBaremetalPlatform);
},
);

const clusterVersionPath = `${k8sBasePath}/apis/config.openshift.io/v1/clusterversions/version`;
const detectClusterVersion = (dispatch) =>
coFetchJSON(clusterVersionPath).then(
Expand Down Expand Up @@ -294,7 +278,6 @@ export const detectFeatures = () => (dispatch: Dispatch) =>
[
detectOpenShift,
// TODO(vojtech): move this flag definition to metal3-plugin via ActionFeatureFlag extension
detectBaremetalPlatform,
detectCanCreateProject,
detectMonitoringURLs,
detectClusterVersion,
Expand Down

0 comments on commit c0847fe

Please sign in to comment.