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

[release-4.15] Bug 2259961: Adds fallback layer for multi cluster code in External mode #1217

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
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