Skip to content

Commit

Permalink
Merge pull request #1212 from bipuladh/fix-multi-client
Browse files Browse the repository at this point in the history
Adds fallback layer for multi cluster code in External mode
  • Loading branch information
openshift-merge-bot[bot] authored Feb 7, 2024
2 parents 8b0c003 + 1d21c8a commit a11fb5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
TitleWithHelp,
} from '../persistent-internal/capacity-breakdown-card/capacity-breakdown-card';
import '../persistent-internal/capacity-breakdown-card/capacity-breakdown-card.scss';
import useClientFallback from './fallback-hook';

export const BreakdownCard: React.FC = () => {
const { t } = useCustomTranslation();
Expand All @@ -51,7 +52,8 @@ export const BreakdownCard: React.FC = () => {
const { systemFlags } = useODFSystemFlagsSelector();

// name of created StorageClasses are prefix by StorageCluster name
const storageClassNamePrefix = systemFlags[clusterNs]?.ocsClusterName;
const storageClassName = systemFlags?.[clusterNs]?.ocsClusterName;
const storageClassNamePrefix = useClientFallback(storageClassName);

const { queries, model, metric } = getBreakdownMetricsQuery(
metricType,
Expand Down
37 changes: 37 additions & 0 deletions packages/ocs/dashboards/persistent-external/fallback-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { StorageClassModel } from '@odf/shared/models';
import { StorageClassResourceKind } from '@odf/shared/types';
import { referenceForModel } from '@odf/shared/utils';
import {
WatchK8sResource,
useK8sWatchResource,
} from '@openshift-console/dynamic-plugin-sdk';

const scResource: WatchK8sResource = {
isList: true,
kind: referenceForModel(StorageClassModel),
};

const fsProvisionerPostFix = '.cephfs.csi.ceph.com';

/**
* This hooks is for ODF Client Mode use case only.
* ODF client mode doesn't deploy ODF StorageCluster hence falling back to StorageClases.
*/
const useClientFallback = (storageClusterName) => {
const [storageClasses, storageClassesLoaded, storageClassLoadError] =
useK8sWatchResource<StorageClassResourceKind[]>(scResource);
if (storageClusterName) {
return storageClusterName;
}

const provisioners = storageClasses.map((sc) => sc.provisioner);
const fileSystemProvisioner = provisioners.find((item) =>
item.includes(fsProvisionerPostFix)
);
const clusterName = fileSystemProvisioner?.split(fsProvisionerPostFix)?.[0];
return storageClassesLoaded && !storageClassLoadError
? clusterName
: 'ocs-storagecluster';
};

export default useClientFallback;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
INDEPENDENT_UTILIZATION_QUERIES,
} from '../../queries';
import { ODFSystemParams } from '../../types';
import useClientFallback from './fallback-hook';

export const UtilizationContent: React.FC = () => {
const { t } = useCustomTranslation();
Expand All @@ -29,7 +30,8 @@ export const UtilizationContent: React.FC = () => {
const { systemFlags } = useODFSystemFlagsSelector();

// name of created StorageClasses are prefix by StorageCluster name
const storageClassNamePrefix = systemFlags[clusterNs]?.ocsClusterName;
const storageClassName = systemFlags?.[clusterNs]?.ocsClusterName;
const storageClassNamePrefix = useClientFallback(storageClassName);

return (
<UtilizationBody>
Expand Down

0 comments on commit a11fb5a

Please sign in to comment.