Skip to content

Commit

Permalink
refactoring (support multiple StorageSystems per ODF)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjalKatiyar committed Nov 23, 2023
1 parent 5117053 commit 8e17abd
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import './capacity-card.scss';

type CapacityMetricDatum = {
systemName: string;
namespace: string;
targetKind: string;
clusterName: string;
totalValue: HumanizeResult;
Expand Down Expand Up @@ -144,12 +145,20 @@ const headerColumns = (t: TFunction) => [
];

const getRow: GetRow = (
{ systemName, targetKind, clusterName, totalValue, usedValue, clusterURL },
{
systemName,
namespace: systemNamespace,
targetKind,
clusterName,
totalValue,
usedValue,
clusterURL,
},
index
) => {
const { apiGroup, apiVersion, kind } = getGVK(targetKind);
const systemKind = referenceForGroupVersionKind(apiGroup)(apiVersion)(kind);
const systemPath = getDashboardLink(systemKind, systemName);
const systemPath = getDashboardLink(systemKind, systemName, systemNamespace);
const isPercentage = !!totalValue;
const progress = isPercentage ? getPercentage(usedValue, totalValue) : 100;
const value = isPercentage
Expand Down Expand Up @@ -274,13 +283,15 @@ const SystemCapacityCard: React.FC = () => {
? usedCapacity?.data?.result?.reduce(
(acc: CapacityMetricDatumMap, usedMetric: PrometheusResult) => {
const systemName = usedMetric?.metric?.storage_system;
const namespace = usedMetric?.metric?.namespace;
const targetKind = usedMetric?.metric?.target_kind;
const clusterName = usedMetric?.metric?.cluster;
const clusterURL = ManagedClusterLink.hasOwnProperty(clusterName)
? ManagedClusterLink[clusterName]
: undefined;
acc[systemName + clusterName] = {
systemName,
namespace,
targetKind,
clusterName,
usedValue: humanizeBinaryBytes(usedMetric?.value?.[1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { generateDataFrames } from './utils';

type RowProps = {
systemName: string;
systemNamespace: string;
managedSystemKind: string;
managedSystemName: string;
currentLocation: string;
Expand All @@ -57,6 +58,7 @@ type GetRow = (
const getRow: GetRow = ({
managedSystemKind,
systemName,
systemNamespace,
iopsData,
throughputData,
latencyData,
Expand All @@ -67,7 +69,7 @@ const getRow: GetRow = ({
return [
<ResourceLink
key={systemName}
link={getDashboardLink(refKind, systemName)}
link={getDashboardLink(refKind, systemName, systemNamespace)}
resourceModel={ODFStorageSystem}
resourceName={systemName}
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as _ from 'lodash-es';

type DataFrame = {
systemName: string;
systemNamespace: string;
managedSystemKind: string;
managedSystemName: string;
currentLocation: string;
Expand Down Expand Up @@ -51,6 +52,7 @@ export const generateDataFrames = (
managedSystemKind: curr.spec.kind,
managedSystemName: curr.spec.name,
systemName: curr.metadata.name,
systemNamespace: curr.metadata.namespace,
currentLocation: '/',
iopsData: {
data: getDatForSystem(id, curr, humanizeIOPS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const StatusCard: React.FC = () => {
healthData
? healthData?.data?.result?.reduce((acc, curr) => {
const systemName = curr.metric.storage_system;
const systemNamespace = curr.metric.namespace;
const storageSystem = systems.find(
(system) => system.metadata.name === systemName
);
Expand All @@ -96,6 +97,7 @@ export const StatusCard: React.FC = () => {
link: getVendorDashboardLinkFromMetrics(
systemKind,
systemName,
systemNamespace,
ocsHealthStatus.errorComponent
),

Expand All @@ -109,7 +111,8 @@ export const StatusCard: React.FC = () => {
healthState: healthStateMap(curr.value[1]),
link: getVendorDashboardLinkFromMetrics(
systemKind,
systemName
systemName,
systemNamespace
),
};
return [...acc, systemData];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const SystemCapacityCard: React.FC = () => {
const totalMetric = getMetricForSystem(totalCapacity, system);
const datum = {
name: system.metadata.name,
namespace: system.metadata.namespace,
managedSystemName: system.spec.name,
managedSystemKind: referenceFor(apiGroup)(apiVersion)(kind),
usedValue: usedMetric
Expand Down
12 changes: 8 additions & 4 deletions packages/odf/components/system-list/odf-system-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { Kebab } from '@odf/shared/kebab/kebab';
import { ClusterServiceVersionModel } from '@odf/shared/models';
import { ODFStorageSystem } from '@odf/shared/models';
import { getName, getNamespace } from '@odf/shared/selectors';
import { Status } from '@odf/shared/status/Status';
import {
ClusterServiceVersionKind,
Expand Down Expand Up @@ -46,7 +47,7 @@ import { OperandStatus } from '../utils';
import ODFSystemLink from './system-link';

type SystemMetrics = {
[systeName: string]: {
[systeNameAndNamespace: string]: {
rawCapacity: HumanizeResult;
usedCapacity: HumanizeResult;
iops: HumanizeResult;
Expand Down Expand Up @@ -83,7 +84,7 @@ export const normalizeMetrics: MetricNormalize = (
return {};
}
return systems.reduce<SystemMetrics>((acc, curr) => {
acc[curr.metadata.name] = {
acc[getName(curr) + getNamespace(curr)] = {
rawCapacity: humanizeBinaryBytes(
rawCapacity.data.result.find(
(item) => item?.metric?.managedBy === curr.spec.name
Expand Down Expand Up @@ -246,10 +247,12 @@ const StorageSystemRow: React.FC<RowProps<StorageSystemKind, CustomData>> = ({
const { t } = useCustomTranslation();
const { apiGroup, apiVersion, kind } = getGVK(obj.spec.kind);
const systemKind = referenceForGroupVersionKind(apiGroup)(apiVersion)(kind);
const systemName = obj?.metadata?.name;
const systemName = getName(obj);
const systemNamespace = getNamespace(obj);
const { normalizedMetrics } = rowData;

const metrics = normalizedMetrics?.normalizedMetrics?.[systemName];
const metrics =
normalizedMetrics?.normalizedMetrics?.[systemName + systemNamespace];

const { rawCapacity, usedCapacity, iops, throughput, latency } =
metrics || {};
Expand All @@ -260,6 +263,7 @@ const StorageSystemRow: React.FC<RowProps<StorageSystemKind, CustomData>> = ({
kind={systemKind}
systemName={systemName}
providerName={systemName}
systemNamespace={systemNamespace}
/>
</TableData>
<TableData {...tableColumnInfo[1]} activeColumnIDs={activeColumnIDs}>
Expand Down
4 changes: 3 additions & 1 deletion packages/odf/components/system-list/system-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ type ODFSystemLinkProps = {
kind: string;
providerName: string;
systemName: string;
systemNamespace: string;
};

const ODFSystemLink: React.FC<ODFSystemLinkProps> = ({
kind,
systemName,
providerName,
systemNamespace,
}) => {
const path = `/odf/system/${kind}/${providerName}/overview`;
const path = `/odf/system/ns/${systemNamespace}/${kind}/${providerName}/overview`;
return (
<span>
<ResourceIcon resourceModel={ODFStorageSystem} />
Expand Down
3 changes: 2 additions & 1 deletion packages/odf/components/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ export const getAllZone = (nodes: WizardNodeState[]): Set<string> =>
export const getVendorDashboardLinkFromMetrics = (
systemKind: string,
systemName: string,
systemNamespace: string,
subComponent?: string
) =>
`/odf/system/${systemKind}/${systemName}/overview${
`/odf/system/ns/${systemNamespace}/${systemKind}/${systemName}/overview${
subComponent ? '/' + subComponent : ''
}`;

Expand Down
2 changes: 2 additions & 0 deletions packages/odf/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ export enum TimeUnits {
HOUR = 'Hour',
MIN = 'Min',
}

export const reduxReducerScope = 'odfConsoleRedux';
3 changes: 1 addition & 2 deletions packages/odf/redux/provider-hooks/useODFNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import * as React from 'react';
import { SubscriptionModel } from '@odf/shared/models';
import { getNamespace } from '@odf/shared/selectors';
import { SubscriptionKind } from '@odf/shared/types';
import { isAbortError } from '@odf/shared/utils';
import { k8sList } from '@openshift-console/dynamic-plugin-sdk';
import { useODFNamespaceDispatch } from '../dispatchers';

const FALLBACK_NAMESPACE = 'openshift-storage';
const SPEC_NAME = 'odf-operator';

const isAbortError = (err): boolean => err?.name === 'AbortError';

const namespaceDetector = async (maxAttempt = 5): Promise<string> => {
let attempt = 0;
let ns = null;
Expand Down
2 changes: 1 addition & 1 deletion packages/odf/redux/selectors/odf-namespace.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { reduxReducerScope } from '@odf/core/constants';
import { useSelector } from 'react-redux';
import { nsPayload } from '../actions';

export const odfNamespaceReducerName = 'odfInstallNs';
export const reduxReducerScope = 'odfConsoleRedux';

const getODFNamespace = (state): nsPayload =>
state.plugins?.[reduxReducerScope]?.[odfNamespaceReducerName] || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import './capacity-card.scss';

export type CapacityMetricDatum = {
name: string;
namespace?: string;
managedSystemName?: string;
managedSystemKind?: string;
totalValue?: HumanizeResult;
Expand Down Expand Up @@ -184,7 +185,11 @@ const CapacityCardRow: React.FC<CapacityCardRowProps> = ({
{data?.managedSystemKind ? (
<Tooltip content={data?.name}>
<ResourceLink
link={getDashboardLink(data?.managedSystemKind, data?.name)}
link={getDashboardLink(
data?.managedSystemKind,
data?.name,
data?.namespace
)}
resourceModel={resourceModel}
resourceName={data?.name}
className="odf-capacityCardLink--ellipsis"
Expand Down Expand Up @@ -317,7 +322,7 @@ const CapacityCard: React.FC<CapacityCardProps> = ({
const isPercentage = !!item?.totalValue;
return (
<CapacityCardRow
key={item.name}
key={item.name + item.namespace}
data={item}
isPercentage={isPercentage}
isRelative={relative}
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/types/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ export type CephClusterKind = K8sResourceCommon & {
phase?: string;
};
};

export type NoobaaSystemKind = K8sResourceCommon;
2 changes: 2 additions & 0 deletions packages/shared/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ export const isValidIP = (address) =>
/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
address
);

export const isAbortError = (err): boolean => err?.name === 'AbortError';
8 changes: 6 additions & 2 deletions packages/shared/src/utils/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import { TFunction } from 'i18next';

const DASH_PREFIX = '/odf/system';

export const getDashboardLink = (systemKind: string, systemName: string) =>
`${DASH_PREFIX}/${systemKind}/${systemName}/overview`;
export const getDashboardLink = (
systemKind: string,
systemName: string,
systemNamespace: string
) =>
`${DASH_PREFIX}/ns/${systemNamespace}/${systemKind}/${systemName}/overview`;

export const getWorstStatus = (
componentsHealth: SubsystemHealth[],
Expand Down
6 changes: 3 additions & 3 deletions plugins/odf/console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"type": "console.page/route",
"properties": {
"exact": true,
"path": "/odf/system/ocs.openshift.io~v1~StorageCluster/:systemName/ceph.rook.io~v1~CephBlockPool/create/~new",
"path": "/odf/system/ns/:namespace/ocs.openshift.io~v1~StorageCluster/:systemName/ceph.rook.io~v1~CephBlockPool/create/~new",
"component": {
"$codeRef": "createBlockPools.default"
}
Expand All @@ -142,7 +142,7 @@
{
"type": "console.page/route",
"properties": {
"path": "/odf/system/ocs.openshift.io~v1~StorageCluster/:systemName/ceph.rook.io~v1~CephBlockPool/:poolName",
"path": "/odf/system/ns/:namespace/ocs.openshift.io~v1~StorageCluster/:systemName/ceph.rook.io~v1~CephBlockPool/:poolName",
"exact": false,
"component": {
"$codeRef": "blockPoolDetailsPage.default"
Expand Down Expand Up @@ -212,7 +212,7 @@
{
"type": "console.page/route",
"properties": {
"path": "/odf/system/ocs.openshift.io~v1~StorageCluster/:systemName",
"path": "/odf/system/ns/:namespace/ocs.openshift.io~v1~StorageCluster/:systemName",
"exact": false,
"component": {
"$codeRef": "ocs.default"
Expand Down

0 comments on commit 8e17abd

Please sign in to comment.