Skip to content

Commit

Permalink
Bug 1932277: Create new pool with arbiter - wrong replica
Browse files Browse the repository at this point in the history
Signed-off-by: Gowtham Shanmugasundaram <gshanmug@redhat.com>
  • Loading branch information
GowthamShanmugam committed Feb 24, 2021
1 parent 0466794 commit b609189
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
Expand Up @@ -30,6 +30,7 @@ import { createDeviceSet } from '../../ocs-install/ocs-request-data';
import { cephCapacityResource } from '../../../constants/resources';
import { DeviceSet } from '../../../types';
import './_add-capacity-modal.scss';
import { checkArbiterCluster, checkFlexibleScaling } from '../../../utils/common';

const getProvisionedCapacity = (value: number) => (value % 1 ? (value * 3).toFixed(2) : value * 3);

Expand All @@ -54,8 +55,8 @@ export const AddCapacityModal = (props: AddCapacityModalProps) => {
const isNoProvionerSC: boolean = storageClass?.provisioner === NO_PROVISIONER;
const selectedSCName: string = getName(storageClass);
const deviceSetIndex: number = getCurrentDeviceSetIndex(deviceSets, selectedSCName);
const hasFlexibleScaling = ocsConfig?.spec?.flexibleScaling;
const isArbiterEnabled: boolean = ocsConfig?.spec?.arbiter?.enable;
const hasFlexibleScaling = checkFlexibleScaling(ocsConfig);
const isArbiterEnabled: boolean = checkArbiterCluster(ocsConfig);
const replica = isArbiterEnabled ? OCS_DEVICE_SET_ARBITER_REPLICA : OCS_DEVICE_SET_REPLICA;
const name = getName(ocsConfig);

Expand Down
Expand Up @@ -28,17 +28,19 @@ import {
withHandlePromise,
} from '@console/internal/components/utils/promise-component';
import { k8sCreate } from '@console/internal/module/k8s/resource';
import { referenceForModel, apiVersionForModel } from '@console/internal/module/k8s';
import { referenceForModel, apiVersionForModel, ListKind } from '@console/internal/module/k8s';
import {
useK8sWatchResource,
WatchK8sResource,
} from '@console/internal/components/utils/k8s-watch-hook';
import { useK8sGet } from '@console/internal/components/utils/k8s-get-hook';

import { CephClusterKind, StoragePoolKind } from '../../../types';
import { CephBlockPoolModel } from '../../../models';
import { CephClusterKind, StoragePoolKind, StorageClusterKind } from '../../../types';
import { CephBlockPoolModel, OCSServiceModel } from '../../../models';
import { CEPH_STORAGE_NAMESPACE, OCS_DEVICE_REPLICA } from '../../../constants/index';
import { PROGRESS_STATUS } from '../../../utils/storage-pool';
import { SECOND } from '../../../../integration-tests/utils/consts';
import { checkArbiterCluster } from '../../../utils/common';
import {
POOL_STATE,
POOL_PROGRESS,
Expand Down Expand Up @@ -84,6 +86,7 @@ export const StoragePoolModal = withHandlePromise((props: StoragePoolModalProps)
/* TODO: use reducer */
const [isSubmit, setIsSubmit] = React.useState(false);
const [timer, setTimer] = React.useState<NodeJS.Timer>(null);
const [isArbiterCluster, setArbiterCluster] = React.useState(false);

/* Not to be exposed for 4.6
const [isPerfObjOpen, setPerfObjOpen] = React.useState(false);
Expand Down Expand Up @@ -121,20 +124,33 @@ export const StoragePoolModal = withHandlePromise((props: StoragePoolModalProps)
}
}, [isSubmit, newPool, newPoolLoadError, newPoolLoaded, timer]);

const replicaDropdownItems = _.keys(OCS_DEVICE_REPLICA).map((replica) => {
return (
<DropdownItem
key={`replica-${OCS_DEVICE_REPLICA[replica]}`}
component="button"
id={replica}
data-test-id={replica}
onClick={(e) => setReplicaSize(e.currentTarget.id)}
>
{t('ceph-storage-plugin~{{replica}} Replication', { replica: OCS_DEVICE_REPLICA[replica] })}
</DropdownItem>
);
});
const [storageCluster, storageClusterLoaded, storageClusterLoadError] = useK8sGet<
ListKind<StorageClusterKind>
>(OCSServiceModel, null, CEPH_STORAGE_NAMESPACE);

React.useEffect(() => {
setArbiterCluster(checkArbiterCluster(storageCluster?.items[0]));
if (isArbiterCluster) {
setReplicaSize('4');
}
}, [storageCluster, storageClusterLoaded, storageClusterLoadError, isArbiterCluster]);

const replicaList: string[] = _.keys(OCS_DEVICE_REPLICA).filter(
(replica: string) =>
(isArbiterCluster && replica === '4') || (!isArbiterCluster && replica !== '4'),
);

const replicaDropdownItems = replicaList.map((replica) => (
<DropdownItem
key={`replica-${OCS_DEVICE_REPLICA[replica]}`}
component="button"
id={replica}
data-test-id={replica}
onClick={(e) => setReplicaSize(e.currentTarget.id)}
>
{t('ceph-storage-plugin~{{replica}} Replication', { replica: OCS_DEVICE_REPLICA[replica] })}
</DropdownItem>
));
/* Not to be exposed for 4.6
const availableDeviceClasses = cephClusterObj[0]?.status?.storage?.deviceClasses.map((device) => {
return (
Expand Down Expand Up @@ -286,6 +302,7 @@ export const StoragePoolModal = withHandlePromise((props: StoragePoolModalProps)
data-test="replica-dropdown"
onToggle={() => setReplicaOpen(!isReplicaOpen)}
toggleIndicator={CaretDownIcon}
isDisabled={isArbiterCluster}
>
{replicaSize
? t('ceph-storage-plugin~{{replica}} Replication', {
Expand Down
Expand Up @@ -40,6 +40,7 @@ export enum OCS_PROVISIONER {
export const OCS_DEVICE_REPLICA = Object.freeze({
'2': '2-way',
'3': '3-way',
'4': '4-way',
});
export const RGW_PROVISIONER = 'openshift-storage.ceph.rook.io/bucket';
export const NOOBAA_PROVISIONER = 'openshift-storage.noobaa.io/obc';
Expand Down
7 changes: 7 additions & 0 deletions frontend/packages/ceph-storage-plugin/src/utils/common.ts
@@ -0,0 +1,7 @@
import { StorageClusterKind } from '../types';

export const checkArbiterCluster = (storageCluster: StorageClusterKind): boolean =>
storageCluster?.spec?.arbiter?.enable;

export const checkFlexibleScaling = (storageCluster: StorageClusterKind): boolean =>
storageCluster?.spec?.flexibleScaling;

0 comments on commit b609189

Please sign in to comment.