-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1216 from openshift-cherrypick-robot/cherry-pick-…
…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
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/ocs/dashboards/persistent-external/fallback-hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters