From b139abeecc25d8dae61f4d75d20ac7b00ab5aabb Mon Sep 17 00:00:00 2001 From: chriskari Date: Thu, 12 Sep 2024 11:52:58 +0200 Subject: [PATCH] feat: added additional statistical cards to namespace overview --- .../Namespaces/AllNamespacesDetails.js | 20 ++- src/resources/Namespaces/NamespaceDetails.js | 4 +- .../NamespaceWorkloads/NamespaceWorkloads.js | 114 ++++++++++++++++++ 3 files changed, 131 insertions(+), 7 deletions(-) diff --git a/src/resources/Namespaces/AllNamespacesDetails.js b/src/resources/Namespaces/AllNamespacesDetails.js index e05fcd1ae0..6ef4a59938 100644 --- a/src/resources/Namespaces/AllNamespacesDetails.js +++ b/src/resources/Namespaces/AllNamespacesDetails.js @@ -3,6 +3,7 @@ import { DynamicPageComponent } from 'shared/components/DynamicPageComponent/Dyn import { NamespaceWorkloads } from './NamespaceWorkloads/NamespaceWorkloads'; import { ResourcesUsage } from './ResourcesUsage'; import { spacing } from '@ui5/webcomponents-react-base'; +import { Title } from '@ui5/webcomponents-react'; export function AllNamespacesDetails() { const { t } = useTranslation(); @@ -12,10 +13,21 @@ export function AllNamespacesDetails() { - - - + <> + + {t('common.headers.monitoring-and-health')} + +
+ + +
+ } /> diff --git a/src/resources/Namespaces/NamespaceDetails.js b/src/resources/Namespaces/NamespaceDetails.js index 97453565c5..75f9e990b3 100644 --- a/src/resources/Namespaces/NamespaceDetails.js +++ b/src/resources/Namespaces/NamespaceDetails.js @@ -17,7 +17,7 @@ import { AllNamespacesDetails } from './AllNamespacesDetails'; import { useSetRecoilState } from 'recoil'; import { ResourceDescription } from 'resources/Namespaces'; -export function NamespaceDetails(props) { +export default function NamespaceDetails(props) { const { t } = useTranslation(); const setShowAdd = useSetRecoilState(showYamlUploadDialogState); @@ -101,5 +101,3 @@ export function NamespaceDetails(props) { ); } - -export default NamespaceDetails; diff --git a/src/resources/Namespaces/NamespaceWorkloads/NamespaceWorkloads.js b/src/resources/Namespaces/NamespaceWorkloads/NamespaceWorkloads.js index 39587523cc..79c7a42922 100644 --- a/src/resources/Namespaces/NamespaceWorkloads/NamespaceWorkloads.js +++ b/src/resources/Namespaces/NamespaceWorkloads/NamespaceWorkloads.js @@ -4,11 +4,13 @@ import PropTypes from 'prop-types'; import { useGetList } from 'shared/hooks/BackendAPI/useGet'; import { + getHealthyDaemonsets, getHealthyReplicasCount, getStatusesPodCount, PodStatusCounterKey, } from './NamespaceWorkloadsHelpers'; import { CountingCard } from 'shared/components/CountingCard/CountingCard'; +import { useEffect, useState } from 'react'; NamespaceWorkloads.propTypes = { namespace: PropTypes.string }; @@ -31,6 +33,24 @@ export function NamespaceWorkloads({ namespace }) { }, ); + const { data: daemonsetsData } = useGetList()( + namespace + ? `/apis/apps/v1/namespaces/${namespace}/daemonsets` + : `/apis/apps/v1/daemonsets`, + { + pollingInterval: 3200, + }, + ); + + const { data: statefulsetsData } = useGetList()( + namespace + ? `/apis/apps/v1/namespaces/${namespace}/statefulsets` + : `/apis/apps/v1/statefulsets`, + { + pollingInterval: 3200, + }, + ); + const statusPodsData = getStatusesPodCount(podsData); const healthyPods = statusPodsData.has(PodStatusCounterKey.Healthy) ? statusPodsData.get(PodStatusCounterKey.Healthy) @@ -43,6 +63,29 @@ export function NamespaceWorkloads({ namespace }) { : 0; const healthyDeployments = getHealthyReplicasCount(deploymentsData); + const healthyDaemonsets = getHealthyDaemonsets(daemonsetsData); + const healthyStatefulsets = getHealthyReplicasCount(statefulsetsData); + + const { data: servicesData } = useGetList()( + namespace ? `/api/v1/namespaces/${namespace}/services` : `/api/v1/services`, + { + pollingInterval: 3200, + }, + ); + + const [loadbalancerNumber, setLoadbalancerNumber] = useState(0); + + useEffect(() => { + if (servicesData) { + let loadbalancers = 0; + for (const sv of servicesData) { + if (sv?.spec?.type === 'LoadBalancer') { + loadbalancers++; + } + } + setLoadbalancerNumber(loadbalancers); + } + }, [servicesData]); return ( <> @@ -96,6 +139,77 @@ export function NamespaceWorkloads({ namespace }) { /> )} + {daemonsetsData && ( +
+ +
+ )} + {statefulsetsData && ( +
+ +
+ )} + {servicesData && ( +
+ +
+ )} )}