Skip to content

Commit

Permalink
Merge pull request #1294 from bipuladh/fix-status-card
Browse files Browse the repository at this point in the history
Adds support for Noobaa standalone in cluster overview
  • Loading branch information
openshift-merge-bot[bot] authored Apr 17, 2024
2 parents 3d36d73 + a615dcd commit 7b4fc83
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
import * as React from 'react';
import { getCephsHealthState, WatchCephResources } from '@odf/ocs/utils';
import { healthStateMessage } from '@odf/shared/dashboards/status-card/states';
import { getNooBaaState } from '@odf/ocs/dashboards/object-service/status-card/statuses';
import { getCephsHealthState } from '@odf/ocs/utils';
import { healthStateMapping } from '@odf/shared/dashboards';
import { CephClusterModel } from '@odf/shared/models';
import { Status } from '@odf/shared/status/Status';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { referenceForModel } from '@odf/shared/utils';
import {
WatchK8sResults,
StatusPopupSection,
HealthState,
SubsystemHealth,
PrometheusHealthPopupProps,
FirehoseResource,
K8sResourceCommon,
PrometheusHealthHandler,
} from '@openshift-console/dynamic-plugin-sdk';
import * as _ from 'lodash-es';
import { Link } from 'react-router-dom-v5-compat';
import { Stack, StackItem } from '@patternfly/react-core';
import '@odf/shared/popup/status-popup.scss';

export const StoragePopover: React.FC<StoragePopoverProps> = ({ ceph }) => {
export const getStorageSystemHealthState: PrometheusHealthHandler = (
promMetrics,
t,
ceph
) => {
const isNoobaaOnly = _.isEmpty(ceph?.data);
if (!isNoobaaOnly) {
return getCephsHealthState({
ceph: {
data: ceph.data as K8sResourceCommon[],
loaded: ceph.loaded,
loadError: ceph.loadError,
},
});
} else {
return getNooBaaState(promMetrics, t, {
loaded: true,
loadError: '',
data: {},
});
}
};

export const StoragePopover: React.FC<PrometheusHealthPopupProps> = ({
responses,
k8sResult,
}) => {
const { t } = useCustomTranslation();

const health = getCephsHealthState({ ceph }, t);
const value = health.message || healthStateMessage(health.state, t);
const noobaaHealth = getNooBaaState(responses, t, {
loaded: true,
loadError: '',
data: {},
});
const cephData = k8sResult.data;
const isNoobaaOnly = _.isEmpty(k8sResult);
const cephHealthState: SubsystemHealth = getCephsHealthState(
{
ceph: {
data: cephData as K8sResourceCommon[],
loaded: k8sResult?.loaded,
loadError: k8sResult?.loadError,
},
},
t
);
const healthStatus: HealthState = isNoobaaOnly
? noobaaHealth?.state
: cephHealthState?.state;
const operatorName = t('Data Foundation');

return (
Expand All @@ -35,27 +84,19 @@ export const StoragePopover: React.FC<StoragePopoverProps> = ({ ceph }) => {
>
<div className="odf-status-popup__row">
<Link to="/odf">{operatorName}</Link>
<Status
key="ocs"
status={
health.state === HealthState.OK && !value ? t('Healthy') : value
}
/>
{healthStateMapping[healthStatus]}
</div>
</StatusPopupSection>
</StackItem>
</Stack>
);
};

export { getCephsHealthState as healthHandler };
export { getStorageSystemHealthState as healthHandler };

export const healthResource = {
ceph: {
kind: referenceForModel(CephClusterModel),
namespaced: false,
isList: true,
},
export const healthResource: FirehoseResource = {
kind: referenceForModel(CephClusterModel),
namespaced: false,
isList: true,
prop: 'ceph',
};

type StoragePopoverProps = WatchK8sResults<WatchCephResources>;
19 changes: 18 additions & 1 deletion packages/shared/src/selectors/k8s.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk';
import {
K8sResourceCommon,
K8sResourceCondition,
K8sResourceKind,
} from '@openshift-console/dynamic-plugin-sdk';
import * as _ from 'lodash-es';

type GetStringProperty<T = K8sResourceCommon> = (resource: T) => string;
Expand Down Expand Up @@ -51,3 +55,16 @@ export const getOwnerReferences = <
value,
'metadata.ownerReferences'
) as K8sResourceCommon['metadata']['ownerReferences'];

type KnownResourceConditions = 'Available' | 'Degraded' | 'Progressing';

export const getResourceCondition = <
A extends K8sResourceKind = K8sResourceKind
>(
resource: A,
condition: KnownResourceConditions
): K8sResourceCondition => {
return resource?.status?.conditions?.find(
(current: K8sResourceCondition) => current.type === condition
);
};
5 changes: 3 additions & 2 deletions plugins/odf/console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,11 @@
}
},
{
"type": "console.dashboards/overview/health/resource",
"type": "console.dashboards/overview/health/prometheus",
"properties": {
"title": "Storage",
"resources": { "$codeRef": "healthResource.healthResource" },
"queries": ["NooBaa_health_status"],
"additionalResource": { "$codeRef": "healthResource.healthResource" },
"healthHandler": { "$codeRef": "healthResource.healthHandler" },
"popupComponent": { "$codeRef": "healthResource.StoragePopover" },
"popupTitle": "Storage"
Expand Down

0 comments on commit 7b4fc83

Please sign in to comment.