-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #901 from bipuladh/ms-dashboard
Adds dashboard for ocs client operator
- Loading branch information
Showing
28 changed files
with
571 additions
and
65 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@odf/client", | ||
"description": "UI plugin for ODF client mode cluster", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@odf/ocs": "0.0.0", | ||
"@odf/shared": "0.0.0" | ||
}, | ||
"scripts": { | ||
"build": "NODE_ENV=production PLUGIN=client I8N_NS=plugin__odf-client yarn --cwd ../.. build:plugin", | ||
"dev": "PLUGIN=client I8N_NS=plugin__odf-client yarn --cwd ../.. server:plugin" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/client/src/components/dashboards/cards/activity-card.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.odf-client-activity-card__body { | ||
max-height: 48rem; | ||
} |
129 changes: 129 additions & 0 deletions
129
packages/client/src/components/dashboards/cards/activity-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import * as React from 'react'; | ||
import { PVC_PROVISIONER_ANNOTATION } from '@odf/ocs/constants'; | ||
import { | ||
eventsResource, | ||
pvcResource, | ||
} from '@odf/ocs/dashboards/persistent-internal/activity-card/activity-card'; | ||
import { isSubscriptionUpgradeActivity } from '@odf/ocs/dashboards/persistent-internal/activity-card/ocs-upgrade-activity'; | ||
import { isCephProvisioner, isPersistentStorageEvent } from '@odf/ocs/utils'; | ||
import { useDeepCompareMemoize } from '@odf/shared/hooks/deep-compare-memoize'; | ||
import { SubscriptionModel } from '@odf/shared/models'; | ||
import { getAnnotations, getName } from '@odf/shared/selectors'; | ||
import { | ||
K8sResourceKind, | ||
PersistentVolumeClaimKind, | ||
SubscriptionKind, | ||
} from '@odf/shared/types'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { referenceForModel } from '@odf/shared/utils'; | ||
import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { | ||
ActivityBody, | ||
ActivityItem, | ||
OngoingActivityBody, | ||
RecentEventsBody, | ||
} from '@openshift-console/dynamic-plugin-sdk-internal'; | ||
import { EventKind } from '@openshift-console/dynamic-plugin-sdk/lib/api/internal-types'; | ||
import * as _ from 'lodash-es'; | ||
import { Card, CardHeader, CardTitle } from '@patternfly/react-core'; | ||
import { CLIENT_OPERATOR } from '../../../constants'; | ||
import './activity-card.scss'; | ||
|
||
const ClientOperatorUpgradeActivity: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
|
||
return ( | ||
<ActivityItem> | ||
{t('Upgrading Data Foundation Client Operator')} | ||
</ActivityItem> | ||
); | ||
}; | ||
|
||
const getClientOperatorSubscription = ( | ||
subscriptions: K8sResourceKind[] | ||
): SubscriptionKind => | ||
_.find( | ||
subscriptions, | ||
(item) => item?.spec?.name === CLIENT_OPERATOR | ||
) as SubscriptionKind; | ||
|
||
const RecentEvent: React.FC = () => { | ||
const [pvcs, pvcLoaded, pvcLoadError] = | ||
useK8sWatchResource<PersistentVolumeClaimKind[]>(pvcResource); | ||
const [events, eventsLoaded, eventsLoadError] = | ||
useK8sWatchResource<EventKind[]>(eventsResource); | ||
|
||
const validPVC = pvcs | ||
.filter((obj) => | ||
isCephProvisioner(getAnnotations(obj)?.[PVC_PROVISIONER_ANNOTATION]) | ||
) | ||
.map(getName); | ||
const memoizedPVCNames = useDeepCompareMemoize(validPVC, true); | ||
|
||
const clientEventsFilter = React.useCallback( | ||
() => isPersistentStorageEvent(memoizedPVCNames), | ||
[memoizedPVCNames] | ||
); | ||
|
||
const eventObject = { | ||
data: events, | ||
loaded: eventsLoaded && pvcLoaded, | ||
kind: 'Event', | ||
loadError: pvcLoadError || eventsLoadError, | ||
}; | ||
|
||
return ( | ||
<RecentEventsBody events={eventObject} filter={clientEventsFilter()} /> | ||
); | ||
}; | ||
|
||
export const subscriptionResource = { | ||
isList: true, | ||
kind: referenceForModel(SubscriptionModel), | ||
namespaced: false, | ||
}; | ||
|
||
const OngoingActivity = () => { | ||
const [subscriptions, subLoaded] = | ||
useK8sWatchResource<K8sResourceKind[]>(subscriptionResource); | ||
|
||
const clientOperatorSubscription: SubscriptionKind = | ||
getClientOperatorSubscription(subscriptions); | ||
|
||
const resourceActivities = []; | ||
|
||
if (isSubscriptionUpgradeActivity(clientOperatorSubscription)) { | ||
resourceActivities.push({ | ||
resource: clientOperatorSubscription, | ||
timestamp: clientOperatorSubscription?.status?.lastUpdated, | ||
loader: () => Promise.resolve(ClientOperatorUpgradeActivity), | ||
}); | ||
} | ||
|
||
return ( | ||
<OngoingActivityBody | ||
loaded={subLoaded} | ||
resourceActivities={resourceActivities} | ||
/> | ||
); | ||
}; | ||
|
||
export const ActivityCard: React.FC = React.memo(() => { | ||
const { t } = useCustomTranslation(); | ||
|
||
return ( | ||
<Card className="co-overview-card--gradient"> | ||
<CardHeader> | ||
<CardTitle>{t('Activity')}</CardTitle> | ||
</CardHeader> | ||
<ActivityBody className="odf-client-activity-card__body"> | ||
<OngoingActivity /> | ||
<RecentEvent /> | ||
</ActivityBody> | ||
</Card> | ||
); | ||
}); | ||
|
||
ActivityCard.displayName = 'ActivityCard'; | ||
|
||
export default ActivityCard; |
52 changes: 52 additions & 0 deletions
52
packages/client/src/components/dashboards/cards/details-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react'; | ||
import { useFetchCsv } from '@odf/shared/hooks/use-fetch-csv'; | ||
import { K8sResourceKind } from '@odf/shared/types'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { DetailsBody } from '@openshift-console/dynamic-plugin-sdk-internal'; | ||
import { OverviewDetailItem as DetailItem } from '@openshift-console/plugin-shared'; | ||
import { Card, CardHeader, CardTitle, CardBody } from '@patternfly/react-core'; | ||
import { CLIENT_OPERATOR } from '../../../constants'; | ||
|
||
const getOperatorVersion = (operator: K8sResourceKind): string => | ||
operator?.spec?.version || ''; | ||
|
||
export const DetailsCard: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
|
||
const [csv, csvLoaded, csvError] = useFetchCsv({ | ||
specName: CLIENT_OPERATOR, | ||
}); | ||
|
||
const subscriptionVersion = getOperatorVersion(csv); | ||
|
||
const serviceName = t('Data Foundation'); | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>{t('Details')}</CardTitle> | ||
</CardHeader> | ||
<CardBody> | ||
<DetailsBody> | ||
<DetailItem key="service_name" title={t('Service name')}> | ||
{serviceName} | ||
</DetailItem> | ||
<DetailItem key="mode" title={t('Mode')}> | ||
{t('Client')} | ||
</DetailItem> | ||
<DetailItem | ||
key="version" | ||
title={t('Version')} | ||
isLoading={!csvLoaded} | ||
error={csvError?.message} | ||
data-test-id="cluster-subscription" | ||
> | ||
{subscriptionVersion} | ||
</DetailItem> | ||
</DetailsBody> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default DetailsCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './activity-card'; | ||
export * from './details-card'; | ||
export * from './inventory-card'; | ||
export * from './status-card'; |
77 changes: 77 additions & 0 deletions
77
packages/client/src/components/dashboards/cards/inventory-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as React from 'react'; | ||
import { getCephPVCs, getCephPVs, getCephSC } from '@odf/ocs/utils'; | ||
import { | ||
PersistentVolumeClaimModel, | ||
PersistentVolumeModel, | ||
StorageClassModel, | ||
} from '@odf/shared/models'; | ||
import { getName } from '@odf/shared/selectors'; | ||
import { | ||
getPVCStatusGroups, | ||
getPVStatusGroups, | ||
} from '@odf/shared/status/Inventory'; | ||
import { K8sResourceKind, StorageClassResourceKind } from '@odf/shared/types'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { useK8sWatchResources } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { ResourceInventoryItem } from '@openshift-console/dynamic-plugin-sdk-internal'; | ||
import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core'; | ||
|
||
const watchResources = { | ||
pvcs: { | ||
isList: true, | ||
kind: PersistentVolumeClaimModel.kind, | ||
}, | ||
pvs: { | ||
isList: true, | ||
kind: PersistentVolumeModel.kind, | ||
}, | ||
sc: { | ||
isList: true, | ||
kind: StorageClassModel.kind, | ||
}, | ||
}; | ||
export const InventoryCard: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
|
||
const resources = useK8sWatchResources(watchResources); | ||
|
||
const pvcsLoaded = resources?.pvcs?.loaded; | ||
const pvcsLoadError = resources?.pvcs?.loadError; | ||
const pvcsData = (resources?.pvcs?.data ?? []) as K8sResourceKind[]; | ||
|
||
const pvsLoaded = resources?.pvs?.loaded; | ||
const pvsLoadError = resources?.pvs?.loadError; | ||
const pvsData = (resources?.pvs?.data ?? []) as K8sResourceKind[]; | ||
|
||
const scData = (resources?.sc?.data ?? []) as StorageClassResourceKind[]; | ||
const filteredCephSC = getCephSC(scData); | ||
const filteredSCNames = filteredCephSC.map(getName); | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>{t('Inventory')}</CardTitle> | ||
</CardHeader> | ||
<CardBody> | ||
<ResourceInventoryItem | ||
dataTest="inventory-pvc" | ||
isLoading={!pvcsLoaded} | ||
error={!!pvcsLoadError} | ||
kind={PersistentVolumeClaimModel as any} | ||
resources={getCephPVCs(filteredSCNames, pvcsData, pvsData)} | ||
mapper={getPVCStatusGroups} | ||
showLink={false} | ||
/> | ||
<ResourceInventoryItem | ||
dataTest="inventory-pv" | ||
isLoading={!pvsLoaded} | ||
error={!!pvsLoadError} | ||
kind={PersistentVolumeModel as any} | ||
resources={getCephPVs(pvsData)} | ||
mapper={getPVStatusGroups} | ||
showLink={false} | ||
/> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; |
Oops, something went wrong.