Skip to content

Commit

Permalink
Merge pull request #1216 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1212-to-release-4.15-compatibility

[release-4.15-compatibility] Bug 2259961: Adds fallback layer for multi cluster code in External mode
  • Loading branch information
openshift-merge-bot[bot] authored Feb 7, 2024
2 parents eb9cceb + df47f94 commit f1b3f95
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 f1b3f95

Please sign in to comment.