Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node maintenance status to BareMetal Nodes and BareMetal Hosts #3628

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 43 additions & 2 deletions frontend/packages/console-app/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ import {
DashboardsOverviewResourceActivity,
DashboardsOverviewHealthURLSubsystem,
DashboardsOverviewHealthPrometheusSubsystem,
DashboardsOverviewInventoryItem,
} from '@console/plugin-sdk';
import { ClusterVersionModel } from '@console/internal/models';
import {
ClusterVersionModel,
NodeModel,
PodModel,
StorageClassModel,
PersistentVolumeClaimModel,
} from '@console/internal/models';
import { referenceForModel } from '@console/internal/module/k8s';
import {
getNodeStatusGroups,
getPodStatusGroups,
getPVCStatusGroups,
} from '@console/shared/src/components/dashboard/inventory-card/utils';
import {
isClusterUpdateActivity,
getClusterUpdateTimestamp,
Expand All @@ -30,7 +42,8 @@ type ConsumedExtensions =
| Perspective
| DashboardsOverviewResourceActivity
| DashboardsOverviewHealthURLSubsystem<any>
| DashboardsOverviewHealthPrometheusSubsystem;
| DashboardsOverviewHealthPrometheusSubsystem
| DashboardsOverviewInventoryItem;

const plugin: Plugin<ConsumedExtensions> = [
{
Expand Down Expand Up @@ -94,6 +107,34 @@ const plugin: Plugin<ConsumedExtensions> = [
popupTitle: 'Control Plane status',
},
},
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
model: NodeModel,
mapper: getNodeStatusGroups,
},
},
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
model: PodModel,
mapper: getPodStatusGroups,
},
},
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
model: StorageClassModel,
},
},
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
model: PersistentVolumeClaimModel,
mapper: getPVCStatusGroups,
useAbbr: true,
},
},
];

export default plugin;
2 changes: 1 addition & 1 deletion frontend/packages/console-app/src/status/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeKind } from '@console/internal/module/k8s';
import { isNodeReady } from '@console/shared';
import { isNodeReady } from '@console/shared/src/selectors/node';

export const nodeStatus = (node: NodeKind) => (isNodeReady(node) ? 'Ready' : 'Not Ready');
5 changes: 0 additions & 5 deletions frontend/packages/console-demo-plugin/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ const plugin: Plugin<ConsumedExtensions> = [
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
resource: {
isList: true,
kind: RouteModel.kind,
prop: 'routes',
},
model: RouteModel,
mapper: getRouteStatusGroups,
expandedComponent: () =>
Expand Down
5 changes: 5 additions & 0 deletions frontend/packages/console-plugin-sdk/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
isDashboardsOverviewPrometheusActivity,
isProjectDashboardInventoryItem,
isReduxReducer,
isDashboardsOverviewInventoryItemReplacement,
} from './typings';

/**
Expand Down Expand Up @@ -158,6 +159,10 @@ export class ExtensionRegistry {
public getProjectDashboardInventoryItems() {
return this.extensions.filter(isProjectDashboardInventoryItem);
}

public getDashboardsOverviewInventoryItemReplacements() {
return this.extensions.filter(isDashboardsOverviewInventoryItemReplacement);
}
}

type ExtensionWithFlags = Extension<{ required?: string | string[] }>;
23 changes: 15 additions & 8 deletions frontend/packages/console-plugin-sdk/src/typings/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,18 @@ namespace ExtensionProperties {
}

export interface DashboardsOverviewInventoryItem extends DashboardsExtensionProperties {
/** Resource which will be fetched and grouped by `mapper` function. */
resource: FirehoseResource;
/** The model for `resource` which will be fetched. The model is used for getting model's label or abbr. */
model: K8sKind;

/** Function which will map various statuses to groups. */
mapper?: StatusGroupMapper;

/** Additional resources which will be fetched and passed to `mapper` function. */
additionalResources?: FirehoseResource[];

/** The model for `resource` which will be fetched. The model is used for getting model's label or abbr. */
model: K8sKind;

/** Defines whether model's label or abbr should be used when rendering the item. Defaults to false (label). */
useAbbr?: boolean;

/** Function which will map various statuses to groups. */
mapper: StatusGroupMapper;

/** Loader for the component which will be used when item is expanded. */
expandedComponent?: LazyLoader<ExpandedComponentProps>;
}
Expand Down Expand Up @@ -274,6 +271,16 @@ export interface ProjectDashboardInventoryItem
export const isProjectDashboardInventoryItem = (e: Extension): e is ProjectDashboardInventoryItem =>
e.type === 'Project/Dashboard/Inventory/Item';

export interface DashboardsOverviewInventoryItemReplacement
extends Extension<ExtensionProperties.DashboardsOverviewInventoryItem> {
type: 'Dashboards/Overview/Inventory/Item/Replacement';
}

export const isDashboardsOverviewInventoryItemReplacement = (
e: Extension,
): e is DashboardsOverviewInventoryItemReplacement =>
e.type === 'Dashboards/Overview/Inventory/Item/Replacement';

export type DashboardCardSpan = 4 | 6 | 12;

export type K8sActivityProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ const StatusLink = connectToFlags<StatusLinkProps>(
return null;
}
const statusItems = encodeURIComponent(statusIDs.join(','));
const namespacePath = namespace ? `ns/${namespace}` : 'all-namespaces';
const path = basePath || `/k8s/${namespacePath}/${kind.plural}`;
const path = basePath || resourcePathFromModel(kind, null, namespace);
const to =
filterType && statusItems.length > 0 ? `${path}?rowFilter-${filterType}=${statusItems}` : path;
const statusGroupIcons = getStatusGroupIcons(flags);
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/console-shared/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { K8sResourceKind } from '@console/internal/module/k8s';
import { FirehoseResult } from '@console/internal/components/utils';
import { getUID } from '../selectors';
import { FirehoseResult } from '@console/internal/components/utils/types';
import { getUID } from '../selectors/common';

export type EntityMap<A> = { [propertyName: string]: A };
export type K8sEntityMap<A extends K8sResourceKind> = EntityMap<A>;
Expand Down
5 changes: 0 additions & 5 deletions frontend/packages/kubevirt-plugin/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ const plugin: Plugin<ConsumedExtensions> = [
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
resource: {
isList: true,
kind: models.VirtualMachineModel.kind,
prop: 'vms',
},
additionalResources: [
{
isList: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/metal3-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"@console/shared": "0.0.0-fixed"
},
"consolePlugin": {
"entry": "src/plugin.ts"
"entry": "src/plugin.tsx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const BMH_STATUS_GROUP_MAPPER = {
[InventoryStatusGroup.NOT_MAPPED]: HOST_SUCCESS_STATES,
[InventoryStatusGroup.PROGRESS]: HOST_PROGRESS_STATES,
[InventoryStatusGroup.ERROR]: HOST_ERROR_STATES,
'node-maintenance': ['maintenance'],
};

export const getBMHStatusGroups: StatusGroupMapper = (
Expand Down Expand Up @@ -41,6 +42,11 @@ export const getBMHStatusGroups: StatusGroupMapper = (
count: 0,
filterType: 'host-status',
},
'node-maintenance': {
statusIDs: ['maintenance'],
count: 0,
filterType: 'host-status',
},
};

const maintenancesByNodeName = createBasicLookup(maintenances, getNodeMaintenanceNodeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ const hostStatesToFilterMap = Object.freeze({
title: 'Error',
states: HOST_ERROR_STATES,
},
maintenance: {
title: 'Maintenance',
states: Object.keys(NODE_STATUS_TITLES),
},
other: {
title: 'Other',
states: [...Object.keys(HOST_STATUS_TITLES), ...Object.keys(NODE_STATUS_TITLES)],
states: Object.keys(HOST_STATUS_TITLES),
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { StatusGroupMapper } from '@console/shared/src/components/dashboard/inventory-card/InventoryItem';
import { createBasicLookup } from '@console/shared/src/utils/utils';
import { getName } from '@console/shared/src/selectors/common';
import { NodeKind } from '@console/internal/module/k8s';
import { InventoryStatusGroup } from '@console/shared/src/components/dashboard/inventory-card/status-group';
import { getNodeMaintenanceNodeName } from '../../../selectors';
import { bareMetalNodeStatus } from '../../../status/baremetal-node-status';
import { NODE_STATUS_TITLES } from '../../../constants';

const BMN_STATUS_GROUP_MAPPER = {
[InventoryStatusGroup.PROGRESS]: ['Not Ready'],
[InventoryStatusGroup.NOT_MAPPED]: ['Ready'],
'node-maintenance': Object.keys(NODE_STATUS_TITLES),
};

export const getBMNStatusGroups: StatusGroupMapper = (nodes: NodeKind[], { maintenaces }) => {
const groups = {
[InventoryStatusGroup.NOT_MAPPED]: {
statusIDs: ['ready'],
count: 0,
filterType: 'bare-metal-node-status',
},
[InventoryStatusGroup.PROGRESS]: {
statusIDs: ['notReady'],
count: 0,
filterType: 'bare-metal-node-status',
},
'node-maintenance': {
statusIDs: ['maintenance'],
count: 0,
filterType: 'bare-metal-node-status',
},
};
const maintenancesByNodeName = createBasicLookup(maintenaces, getNodeMaintenanceNodeName);
nodes.forEach((node) => {
const nodeName = getName(node);
const nodeMaintenance = maintenancesByNodeName[nodeName];
const { status } = bareMetalNodeStatus({ node, nodeMaintenance });
const group =
Object.keys(BMN_STATUS_GROUP_MAPPER).find((key) =>
BMN_STATUS_GROUP_MAPPER[key].includes(status),
) || InventoryStatusGroup.NOT_MAPPED;
groups[group].count++;
});
return groups;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as _ from 'lodash';
import * as React from 'react';
import { MaintenanceIcon } from '@patternfly/react-icons';
import {
DashboardsOverviewInventoryItem,
Plugin,
Expand All @@ -9,15 +11,20 @@ import {
ModelFeatureFlag,
ModelDefinition,
DashboardsOverviewResourceActivity,
DashboardsOverviewInventoryItemReplacement,
DashboardsInventoryItemGroup,
} from '@console/plugin-sdk';
import { referenceForModel } from '@console/internal/module/k8s';
import { MachineModel, NodeModel } from '@console/internal/models';
import { FLAGS } from '@console/internal/const';
import { BareMetalHostModel, NodeMaintenanceModel } from './models';
import { getBMHStatusGroups } from './components/baremetal-hosts/dashboard/utils';
import { getBMNStatusGroups } from './components/baremetal-nodes/dashboard/utils';

type ConsumedExtensions =
| DashboardsOverviewInventoryItem
| DashboardsOverviewInventoryItemReplacement
| DashboardsInventoryItemGroup
| ResourceNSNavItem
| ResourceListPage
| ResourceDetailsPage
Expand Down Expand Up @@ -86,14 +93,25 @@ const plugin: Plugin<ConsumedExtensions> = [
required: [FLAGS.BAREMETAL, METAL3_FLAG],
},
},
{
type: 'Dashboards/Overview/Inventory/Item/Replacement',
properties: {
model: NodeModel,
additionalResources: [
{
isList: true,
kind: referenceForModel(NodeMaintenanceModel),
prop: 'maintenaces',
optional: true,
},
],
mapper: getBMNStatusGroups,
required: [FLAGS.BAREMETAL, METAL3_FLAG],
},
},
{
type: 'Dashboards/Overview/Inventory/Item',
properties: {
resource: {
isList: true,
kind: referenceForModel(BareMetalHostModel),
prop: 'hosts',
},
additionalResources: [
{
isList: true,
Expand All @@ -108,7 +126,7 @@ const plugin: Plugin<ConsumedExtensions> = [
{
isList: true,
kind: referenceForModel(NodeMaintenanceModel),
prop: 'maintenaces',
prop: 'maintenances',
optional: true,
},
],
Expand Down Expand Up @@ -158,6 +176,14 @@ const plugin: Plugin<ConsumedExtensions> = [
required: [FLAGS.BAREMETAL, METAL3_FLAG],
},
},
{
type: 'Dashboards/Inventory/Item/Group',
properties: {
id: 'node-maintenance',
icon: <MaintenanceIcon />,
required: [FLAGS.BAREMETAL, METAL3_FLAG],
},
},
];

export default plugin;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
import { getName } from '@console/shared/src/selectors';
import { getName } from '@console/shared/src/selectors/common';
import { MachineKind } from '@console/internal/module/k8s';
import {
BareMetalHostDisk,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NodeKind, K8sResourceKind } from '@console/internal/module/k8s';
import { nodeStatus } from '@console/app/src/status/node';
import { isNodeUnschedulable } from '@console/shared';
import { isNodeUnschedulable } from '@console/shared/src/selectors/node';
import { StatusProps } from '../components/types';
import { BareMetalHostKind } from '../types';
import { isHostPoweredOn } from '../selectors';
Expand Down