Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring (support ODF in any Namespace) #1099

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"history": "^4.9.0",
"i18next": "^20.2.1",
"i18next-conv": "^10.1.0",
"immer": "^10.0.3",
"js-base64": "^2.1.9",
"js-yaml": "^3.13.1",
"lodash-es": "^4.17.21",
Expand Down Expand Up @@ -108,6 +109,7 @@
"ts-loader": "^9.4.1",
"ts-node": "5.0.1",
"tsm": "^2.3.0",
"typesafe-actions": "^4.2.1",
"typescript": "^4.8",
"victory-core": "^35.4.4",
"webpack": "5.74.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { useODFNamespaceSelector } from '@odf/core/redux';
import { PVC_PROVISIONER_ANNOTATION } from '@odf/ocs/constants';
import {
eventsResource,
Expand Down Expand Up @@ -48,6 +49,8 @@ const getClientOperatorSubscription = (
) as SubscriptionKind;

const RecentEvent: React.FC = () => {
const { odfNamespace } = useODFNamespaceSelector();

const [pvcs, pvcLoaded, pvcLoadError] =
useK8sWatchResource<PersistentVolumeClaimKind[]>(pvcResource);
const [events, eventsLoaded, eventsLoadError] =
Expand All @@ -61,8 +64,8 @@ const RecentEvent: React.FC = () => {
const memoizedPVCNames = useDeepCompareMemoize(validPVC, true);

const clientEventsFilter = React.useCallback(
() => isPersistentStorageEvent(memoizedPVCNames),
[memoizedPVCNames]
() => isPersistentStorageEvent(memoizedPVCNames, odfNamespace),
[memoizedPVCNames, odfNamespace]
);

const eventObject = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ibm/system-connection-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ export const createFlashSystemPayload: CreatePayload<FlashSystemState> = ({
systemName,
state,
model,
namespace,
storageClassName,
}) => {
const namespace = 'openshift-storage';
const defaultFilesystem = 'ext4';
const defaultVolumeMode = 'thick';
const defaultVolumePrefix = 'odf';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const CreateDRPolicy: React.FC<ReRouteResourceProps> = ({
clusterName: cluster?.name,
storageClusterRef: {
name: cluster.storageClusterName,
// ToDo (epic 4422): Need to update this as per ConfigMap/ClusterClaim (whichever us decided) JSON output
namespace: CEPH_STORAGE_NAMESPACE,
},
})),
Expand Down
2 changes: 2 additions & 0 deletions packages/mco/components/mco-dashboard/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const LAST_SYNC_TIME_QUERY = 'ramen_sync_duration_seconds';
export const getLastSyncPerClusterQuery = () =>
`${LAST_SYNC_TIME_QUERY}{${DRPC_OBJECT_TYPE}, ${RAMEN_HUB_OPERATOR_METRICS_SERVICE}}`;

// ToDo (epic 4422): Need to update as per updates in the metrics
export const CAPACITY_QUERIES = {
[StorageDashboard.TOTAL_CAPACITY_FILE_BLOCK]: `(label_replace(odf_system_map{target_namespace="openshift-storage"} , "managedBy", "$1", "target_name", "(.*)")) * on (namespace, managedBy, cluster) group_right(storage_system, target_kind) ${TOTAL_CAPACITY_FILE_BLOCK_METRIC}`,
[StorageDashboard.USED_CAPACITY_FILE_BLOCK]: `(label_replace(odf_system_map{target_namespace="openshift-storage"} , "managedBy", "$1", "target_name", "(.*)")) * on (namespace, managedBy, cluster) group_right(storage_system, target_kind) ${USED_CAPACITY_FILE_BLOCK_METRIC}`,
Expand All @@ -43,6 +44,7 @@ export const getRBDSnapshotUtilizationQuery = (
return queries[queryName];
};

// ToDo (epic 4422): Need to update as per updates in the metrics
export const STATUS_QUERIES = {
[StorageDashboard.SYSTEM_HEALTH]: `(label_replace(odf_system_map{target_namespace="openshift-storage"} , "managedBy", "$1", "target_name", "(.*)")) * on (namespace, managedBy, cluster) group_right(storage_system, target_kind) ${SYSTEM_HEALTH_METRIC}`,
[StorageDashboard.HEALTH]: SYSTEM_HEALTH_METRIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ const appResources2: ArgoApplicationSetResourceKind = {
};

const onClose = jest.fn();

jest.mock('@odf/mco/hooks/disaster-recovery', () => ({
__esModule: true,
useDisasterRecoveryResourceWatch: jest.fn(() => {
Expand All @@ -283,6 +284,7 @@ jest.mock('@odf/mco/hooks/disaster-recovery', () => ({
}
}),
}));

jest.mock('@odf/mco/hooks/argo-application-set', () => ({
__esModule: true,
useArgoApplicationSetResourceWatch: jest.fn(() => {
Expand All @@ -293,6 +295,7 @@ jest.mock('@odf/mco/hooks/argo-application-set', () => ({
}
}),
}));

jest.mock('../utils/k8s-utils', () => ({
unAssignPromises: jest.fn(() => [Promise.resolve({ data: {} })]),
}));
Expand Down
31 changes: 17 additions & 14 deletions packages/ocs/block-pool/BlockPoolDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as React from 'react';
import { useSafeK8sWatchResource } from '@odf/core/hooks';
import { useODFNamespaceSelector } from '@odf/core/redux';
import DetailsPage from '@odf/shared/details-page/DetailsPage';
import { LoadingBox } from '@odf/shared/generic/status-box';
import { Kebab } from '@odf/shared/kebab/kebab';
import { ModalKeys } from '@odf/shared/modals/types';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { referenceForModel } from '@odf/shared/utils';
import { EventStreamWrapped, YAMLEditorWrapped } from '@odf/shared/utils/Tabs';
import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk';
import { RouteComponentProps, useLocation } from 'react-router-dom';
import { CEPH_NS } from '../constants';
import { BlockPoolDashboard } from '../dashboards/block-pool/block-pool-dashboard';
import { CephBlockPoolModel, CephClusterModel } from '../models';
import { StoragePoolKind } from '../types';
Expand All @@ -33,12 +32,16 @@ export const BlockPoolDetailsPage: React.FC<BlockPoolDetailsPageProps> = ({
const location = useLocation();
const kind = referenceForModel(CephBlockPoolModel);

const [resource, loaded] = useK8sWatchResource<StoragePoolKind>({
kind,
name: poolName,
namespace: CEPH_NS,
isList: false,
});
const { odfNamespace, isODFNsLoaded, odfNsLoadError } =
useODFNamespaceSelector();

const [resource, loaded, loadError] =
useSafeK8sWatchResource<StoragePoolKind>((ns: string) => ({
kind,
name: poolName,
namespace: ns,
isList: false,
}));

const breadcrumbs = [
{
Expand All @@ -62,7 +65,7 @@ export const BlockPoolDetailsPage: React.FC<BlockPoolDetailsPageProps> = ({
extraProps={{
resource,
resourceModel: CephBlockPoolModel,
namespace: CEPH_NS,
namespace: odfNamespace,
}}
customKebabItems={[
{
Expand All @@ -82,12 +85,12 @@ export const BlockPoolDetailsPage: React.FC<BlockPoolDetailsPageProps> = ({
]}
/>
);
}, [resource, t]);
}, [resource, odfNamespace, t]);

return !loaded ? (
<LoadingBox />
) : (
return (
<DetailsPage
loaded={loaded && isODFNsLoaded}
loadError={loadError || odfNsLoadError}
breadcrumbs={breadcrumbs}
actions={actions}
resourceModel={CephBlockPoolModel}
Expand Down
76 changes: 48 additions & 28 deletions packages/ocs/block-pool/BlockPoolListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as React from 'react';
import { useSafeK8sWatchResources } from '@odf/core/hooks';
import { useODFNamespaceSelector } from '@odf/core/redux';
import { healthStateMapping } from '@odf/shared/dashboards/status-card/states';
import {
useCustomPrometheusPoll,
Expand All @@ -15,7 +17,11 @@ import {
CephClusterKind,
} from '@odf/shared/types';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { humanizeBinaryBytes, referenceForModel } from '@odf/shared/utils';
import {
humanizeBinaryBytes,
referenceForModel,
getValidPrometheusPollObj,
} from '@odf/shared/utils';
import {
ListPageBody,
ListPageCreateLink,
Expand All @@ -26,7 +32,7 @@ import {
TableColumn,
TableData,
useActiveColumns,
useK8sWatchResources,
WatchK8sResults,
useListPageFilter,
VirtualizedTable,
} from '@openshift-console/dynamic-plugin-sdk';
Expand All @@ -35,7 +41,6 @@ import classNames from 'classnames';
import { Link, useLocation } from 'react-router-dom';
import { Tooltip } from '@patternfly/react-core';
import { sortable, wrappable } from '@patternfly/react-table';
import { CEPH_NS } from '../constants';
import { CephBlockPoolModel, CephClusterModel } from '../models';
import { getPoolQuery, StorageDashboardQuery } from '../queries';
import { StoragePoolKind } from '../types';
Expand Down Expand Up @@ -370,11 +375,11 @@ type BlockPoolListPageProps = {
hideColumnManagement?: boolean;
};

const resources = {
const resources = (ns: string) => ({
ceph: {
kind: referenceForModel(CephClusterModel),
namespaced: true,
namespace: CEPH_NS,
namespace: ns,
isList: true,
},
sc: {
Expand All @@ -386,7 +391,7 @@ const resources = {
kind: referenceForModel(CephBlockPoolModel),
isList: true,
},
};
});

type WatchType = {
sc: StorageClassResourceKind[];
Expand All @@ -397,10 +402,15 @@ type WatchType = {
export const BlockPoolListPage: React.FC<BlockPoolListPageProps> = ({}) => {
const { t } = useCustomTranslation();

const { odfNamespace, isODFNsLoaded, odfNsLoadError, isNsSafe } =
useODFNamespaceSelector();

const location = useLocation();
const listPagePath: string = location.pathname;

const response = useK8sWatchResources<WatchType>(resources);
const response = useSafeK8sWatchResources(
resources
) as WatchK8sResults<WatchType>;

const cephClusters = response.ceph.data;
const cephLoaded = response.ceph.loaded;
Expand All @@ -423,27 +433,37 @@ export const BlockPoolListPage: React.FC<BlockPoolListPageProps> = ({}) => {

// Metrics
const [poolRawCapacityMetrics, rawCapLoadError, rawCapLoading] =
useCustomPrometheusPoll({
endpoint: 'api/v1/query' as any,
query: getPoolQuery(
memoizedPoolNames,
StorageDashboardQuery.POOL_RAW_CAPACITY_USED
),
namespace: CEPH_NS,
basePath: usePrometheusBasePath(),
});
useCustomPrometheusPoll(
getValidPrometheusPollObj(
{
endpoint: 'api/v1/query' as any,
query: getPoolQuery(
memoizedPoolNames,
StorageDashboardQuery.POOL_RAW_CAPACITY_USED
),
namespace: odfNamespace,
basePath: usePrometheusBasePath(),
},
isNsSafe
)
);

// compression queries
const [compressionSavings, compressionLoadError, compressionLoading] =
useCustomPrometheusPoll({
endpoint: 'api/v1/query' as any,
query: getPoolQuery(
poolNames,
StorageDashboardQuery.POOL_COMPRESSION_SAVINGS
),
namespace: CEPH_NS,
basePath: usePrometheusBasePath(),
});
useCustomPrometheusPoll(
getValidPrometheusPollObj(
{
endpoint: 'api/v1/query' as any,
query: getPoolQuery(
poolNames,
StorageDashboardQuery.POOL_COMPRESSION_SAVINGS
),
namespace: odfNamespace,
basePath: usePrometheusBasePath(),
},
isNsSafe
)
);

const customData = React.useMemo(() => {
const poolRawCapacity: PoolMetrics = getPerPoolMetrics(
Expand Down Expand Up @@ -498,15 +518,15 @@ export const BlockPoolListPage: React.FC<BlockPoolListPageProps> = ({}) => {
<ListPageBody>
<ListPageFilter
data={data}
loaded={loaded}
loaded={loaded && isODFNsLoaded}
onFilterChange={onFilterChange}
hideColumnManagement={true}
/>
<BlockPoolList
data={filteredData}
unfilteredData={data}
loaded={loaded}
loadError={error}
loaded={loaded && isODFNsLoaded}
loadError={error || odfNsLoadError}
rowData={{ ...customData }}
/>
</ListPageBody>
Expand Down
Loading