Skip to content

Commit

Permalink
Show provisioner based storage classes
Browse files Browse the repository at this point in the history
- OCS install flow will use first provisioner based storage class
- OCS add capacity lists only provisioner based storage class

Signed-off-by: cloudbehl <cloudbehl@gmail.com>
  • Loading branch information
cloudbehl committed Nov 21, 2019
1 parent 82b4695 commit 11fb898
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import * as _ from 'lodash';
import { Firehose } from '@console/internal/components/utils';
import { InfrastructureModel } from '@console/internal/models';
import { K8sResourceKind, StorageClassResourceKind, k8sGet } from '@console/internal/module/k8s';
import { StorageClassDropdownInner } from '@console/internal/components/utils/storage-class-dropdown';
import { K8sResourceKind } from '@console/internal/module/k8s';

const cephStorageProvisioners = ['ceph.rook.io/block', 'cephfs.csi.ceph.com', 'rbd.csi.ceph.com'];
import { getInfrastructurePlatform } from '@console/shared';
import { infraProvisionerMap } from '../../constants/ocs-install';

export const OCSStorageClassDropdown: React.FC<OCSStorageClassDropdownProps> = (props) => (
<Firehose resources={[{ kind: 'StorageClass', prop: 'StorageClass', isList: true }]}>
Expand All @@ -14,18 +15,30 @@ export const OCSStorageClassDropdown: React.FC<OCSStorageClassDropdownProps> = (

const StorageClassDropdown = (props: any) => {
const scConfig = _.cloneDeep(props);
const [infrastructure, setInfrastructure] = React.useState<K8sResourceKind>();
const [infrastructureError, setInfrastructureError] = React.useState();
/* 'S' of Storage should be Capital as its defined key in resourses object */
const scLoaded = _.get(scConfig.resources.StorageClass, 'loaded');
const scData = _.get(scConfig.resources.StorageClass, 'data', []) as K8sResourceKind[];
const scData = _.get(scConfig.resources.StorageClass, 'data', []) as StorageClassResourceKind[];

React.useEffect(() => {
const fetchInfrastructure = async () => {
try {
const infra = await k8sGet(InfrastructureModel, 'cluster');
setInfrastructure(infra);
} catch (error) {
setInfrastructureError(error);
}
};
fetchInfrastructure();
}, []);

const filteredSCData = scData.filter((sc: K8sResourceKind) => {
return cephStorageProvisioners.every(
(provisioner: string) => !_.get(sc, 'provisioner').includes(provisioner),
);
});
const infrastructurePlatform = getInfrastructurePlatform(infrastructure);

if (scLoaded) {
scConfig.resources.StorageClass.data = filteredSCData;
if (scLoaded && !infrastructureError && !!infrastructurePlatform) {
// find infra supported provisioner
const provisioner: string = infraProvisionerMap[_.toLower(infrastructurePlatform)];
scConfig.resources.StorageClass.data = _.filter(scData, (sc) => sc.provisioner === provisioner);
}

return <StorageClassDropdownInner {...scConfig} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,16 @@ const CustomNodeTable: React.FC<CustomNodeTableProps> = ({
.then((storageClasses: StorageClassResourceKind[]) => {
// find all storageclass with the given provisioner
const scList = _.filter(storageClasses, (sc) => sc.provisioner === provisioner);
// take the default storageclass
// take the provisioner based storageclass
_.forEach(scList, (sc) => {
if (isDefaultClass(sc)) {
storageClass = sc.metadata.name;
}
});
// take the first storageclass if default not set
if (!storageClass && storageClass.length > 0) {
storageClass = getName(_.get(scList, '0'));
}
makeOCSRequest();
})
.catch((err) => {
Expand Down

0 comments on commit 11fb898

Please sign in to comment.