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

Adds fallback layer for multi cluster code in External mode #1212

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
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under common.ts let's create an enum for each ceph provisioner type and reuse the same here, in this way we can replace the cephStorageProvisioners list under common also can be replaced with enums.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to backport this to 4.15. I will create a seperate PR on top of this for 4.16

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here declare the fsProvisionerPostFix like: '.' + CEPH_FILESYSTEM_PROVISIONER

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking at #1215

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack


/**
* 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);
Copy link
Collaborator

@SanjalKatiyar SanjalKatiyar Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way it won't even poll when we already have a value for storageClusterName...

Suggested change
useK8sWatchResource<StorageClassResourceKind[]>(scResource);
useK8sWatchResource<StorageClassResourceKind[]>(getValidWatchK8sResourceObj(scResource, !storageClusterName));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this resource is already called in the same page for inventory card. so we can live with this.

Copy link
Collaborator

@SanjalKatiyar SanjalKatiyar Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense then !! (I did not check the other active components)

if (storageClusterName) {
return storageClusterName;
}

const provisioners = storageClasses.map((sc) => sc.provisioner);
const fileSystemProvisioner = provisioners.find((item) =>
item.includes(fsProvisionerPostFix)
Comment on lines +28 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we replace this with a util function like isCephFSProvisioner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do that but I don't think we would have a very specific use case. We could probably go with isOCSProvisioner with more args. Adding it to #1215

);
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
Loading