Skip to content

Commit 8ea8249

Browse files
committed
feat: Use CR status condition information
Ref #42
1 parent 525f7c5 commit 8ea8249

File tree

4 files changed

+94
-16
lines changed

4 files changed

+94
-16
lines changed

src/components/camel-app-details/CamelAppDetails.tsx

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import {
1111
TextListItem,
1212
} from '@patternfly/react-core';
1313
import { useTranslation } from 'react-i18next';
14-
import { K8sGroupVersionKind, ResourceLink } from '@openshift-console/dynamic-plugin-sdk';
14+
import {
15+
GreenCheckCircleIcon,
16+
K8sGroupVersionKind,
17+
K8sResourceConditionStatus,
18+
ResourceLink,
19+
YellowExclamationTriangleIcon,
20+
} from '@openshift-console/dynamic-plugin-sdk';
1521
import { camelAppGVK } from '../../const';
1622
import CamelAppStatusPod from './CamelAppStatusPod';
1723
import CamelAppHealth from '../camel-list-page/CamelAppHealth';
@@ -35,9 +41,31 @@ type CamelAppDetails = {
3541
metricsEndpoint: string;
3642
};
3743

44+
const monitoredCondition = (camelInt: CamelAppKind) => {
45+
const monitoredConditions = camelInt.status?.conditions?.filter(
46+
(contidition) => contidition.type == 'Monitored',
47+
);
48+
if (monitoredConditions.length > 0) {
49+
return monitoredConditions[0];
50+
}
51+
return;
52+
};
53+
const healthyCondition = (camelInt: CamelAppKind) => {
54+
const healthConditions = camelInt.status?.conditions?.filter(
55+
(contidition) => contidition.type == 'Healthy',
56+
);
57+
if (healthConditions.length > 0) {
58+
return healthConditions[0];
59+
}
60+
return;
61+
};
62+
3863
const CamelAppDetails: React.FC<CamelAppDetailsProps> = ({ obj: camelInt }) => {
3964
const { t } = useTranslation('plugin__camel-openshift-console-plugin');
4065

66+
const monitored = monitoredCondition(camelInt);
67+
const healthy = healthyCondition(camelInt);
68+
4169
return (
4270
<div className="co-m-pane__body">
4371
<h2>{t('Camel App Details')}</h2>
@@ -63,9 +91,25 @@ const CamelAppDetails: React.FC<CamelAppDetailsProps> = ({ obj: camelInt }) => {
6391
{camelInt.status?.image ? camelInt.status.image : 'unknown'}
6492
</DescriptionListDescription>
6593
</DescriptionListGroup>
94+
<DescriptionListGroup>
95+
<DescriptionListTerm>{t('Monitored')}:</DescriptionListTerm>
96+
<DescriptionListDescription>
97+
{monitored && monitored?.status == K8sResourceConditionStatus.True ? (
98+
<>
99+
<GreenCheckCircleIcon />
100+
&nbsp;&nbsp;True
101+
</>
102+
) : (
103+
<>
104+
<YellowExclamationTriangleIcon />
105+
&nbsp;&nbsp;False&nbsp;&nbsp;({monitored.message})
106+
</>
107+
)}
108+
</DescriptionListDescription>
109+
</DescriptionListGroup>
66110
<DescriptionListGroup>
67111
<DescriptionListTerm>
68-
<PopoverCamelHealth popoverBody={t('Health') + ' :'} />
112+
<PopoverCamelHealth popoverBody={t('Health') + ' :'} condition={healthy} />
69113
</DescriptionListTerm>
70114
<DescriptionListDescription>
71115
<CamelAppHealth

src/components/camel-app-details/CamelAppHealthPopover.tsx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import * as React from 'react';
22
import { Button, Popover, PopoverPosition, PopoverProps } from '@patternfly/react-core';
33
import { Trans, useTranslation } from 'react-i18next';
44
import CamelAppHealth from '../camel-list-page/CamelAppHealth';
5+
import {
6+
K8sResourceCondition,
7+
K8sResourceConditionStatus,
8+
} from '@openshift-console/dynamic-plugin-sdk';
59

610
type PopoverCamelHealthProps = {
711
popoverBody: React.ReactNode;
@@ -12,6 +16,7 @@ type PopoverCamelHealthProps = {
1216
isVisible?: boolean;
1317
shouldClose?: (hideFunction: any) => void;
1418
shouldOpen?: PopoverProps['shouldOpen'];
19+
condition?: K8sResourceCondition;
1520
};
1621

1722
export const PopoverCamelHealth: React.FC<PopoverCamelHealthProps> = ({
@@ -23,6 +28,7 @@ export const PopoverCamelHealth: React.FC<PopoverCamelHealthProps> = ({
2328
title,
2429
onHide,
2530
onShow,
31+
condition,
2632
}) => {
2733
const { t } = useTranslation('plugin__camel-openshift-console-plugin');
2834
return (
@@ -32,17 +38,26 @@ export const PopoverCamelHealth: React.FC<PopoverCamelHealthProps> = ({
3238
bodyContent={() => (
3339
<div>
3440
<div>
35-
<Trans t={t}>
36-
<h4>Service Level Indicator</h4>
37-
<CamelAppHealth health="Error" />: &gt; 10 % failed exchanges
38-
<br />
39-
<CamelAppHealth health="Warning" />: &gt; 5 % failed exchanges
40-
<br />
41-
<CamelAppHealth health="OK" />: healthy
42-
<br />
43-
<CamelAppHealth health="Unknown" />: no informations
44-
<br />
45-
</Trans>
41+
{condition &&
42+
condition?.status &&
43+
condition?.status == K8sResourceConditionStatus.False ? (
44+
<>
45+
<h4>Reason</h4>
46+
{condition.reason}
47+
</>
48+
) : (
49+
<Trans t={t}>
50+
<h4>Service Level Indicator</h4>
51+
<CamelAppHealth health="Error" />: &gt; 10 % failed exchanges
52+
<br />
53+
<CamelAppHealth health="Warning" />: &gt; 5 % failed exchanges
54+
<br />
55+
<CamelAppHealth health="OK" />: healthy
56+
<br />
57+
<CamelAppHealth health="Unknown" />: no informations
58+
<br />
59+
</Trans>
60+
)}
4661
</div>
4762
</div>
4863
)}

src/components/camel-app-details/CamelAppStatusPod.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
DescriptionListDescription,
1212
} from '@patternfly/react-core';
1313
import { podGVK } from '../../const';
14-
import { ResourceLink, ResourceStatus } from '@openshift-console/dynamic-plugin-sdk';
14+
import {
15+
ResourceLink,
16+
ResourceStatus,
17+
YellowExclamationTriangleIcon,
18+
} from '@openshift-console/dynamic-plugin-sdk';
1519
import { useTranslation } from 'react-i18next';
1620
import Status from '@openshift-console/dynamic-plugin-sdk/lib/app/components/status/Status';
1721
import { formatDuration } from '../../date-utils';
@@ -30,6 +34,7 @@ const hasRuntimeExchanges = (camelPod: CamelAppStatusPod) =>
3034
camelPod.runtime?.exchange ? true : false;
3135
const hasObserve = (camelPod: CamelAppStatusPod) =>
3236
camelPod.observe && Object.keys(camelPod.observe).length > 0;
37+
const hasStatusMessage = (camelPod: CamelAppStatusPod) => (camelPod.reason ? true : false);
3338

3439
const CamelAppStatusPod: React.FC<CamelAppStatusPodProps> = ({ obj: camelInt, pod: camelPod }) => {
3540
const { t } = useTranslation('plugin__camel-openshift-console-plugin');
@@ -68,6 +73,19 @@ const CamelAppStatusPod: React.FC<CamelAppStatusPodProps> = ({ obj: camelInt, po
6873
<DescriptionListTerm>{t('Uptime')}:</DescriptionListTerm>
6974
<DescriptionListDescription>{durationFull}</DescriptionListDescription>
7075
</DescriptionListGroup>
76+
77+
{hasStatusMessage(camelPod) ? (
78+
<DescriptionListGroup>
79+
<DescriptionListTerm>{t('Status message')}:</DescriptionListTerm>
80+
<DescriptionListDescription>
81+
<YellowExclamationTriangleIcon />
82+
&nbsp;&nbsp;{camelPod.reason}
83+
</DescriptionListDescription>
84+
</DescriptionListGroup>
85+
) : (
86+
<></>
87+
)}
88+
7189
{hasRuntime(camelPod) ? (
7290
<DescriptionListGroup>
7391
<DescriptionListTerm>{t('Runtime')}:</DescriptionListTerm>

src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { K8sResourceKind } from '@openshift-console/dynamic-plugin-sdk';
1+
import { K8sResourceCondition, K8sResourceKind } from '@openshift-console/dynamic-plugin-sdk';
22

33
// See how to enrich camelSpec
44
export type CamelAppKind = K8sResourceKind & {
55
status: {
66
pods: CamelAppStatusPod[];
77
phase: string;
88
sliExchangeSuccessRate: CamelAppSli;
9+
conditions: K8sResourceCondition[];
910
};
1011
};
1112

@@ -24,7 +25,7 @@ export type CamelAppStatusPod = {
2425
name: string;
2526
observe: CamelAppObservability;
2627
ready: boolean;
27-
reason: boolean;
28+
reason: string;
2829
runtime: CamelAppRuntime;
2930
status: string;
3031
/** Format: date-time - in nanoseconds */

0 commit comments

Comments
 (0)