Skip to content

Commit

Permalink
Provide option to enable DR support
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Asir Jeyasingh <[email protected]>
  • Loading branch information
TimothyAsirJeyasing committed Nov 7, 2023
1 parent d768d0b commit bcf9d6c
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 2 deletions.
3 changes: 3 additions & 0 deletions locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@
"Only showing PVCs that are being mounted on an active pod": "Only showing PVCs that are being mounted on an active pod",
"This card shows the requested capacity for different Kubernetes resources. The figures shown represent the usable storage, meaning that data replication is not taken into consideration.": "This card shows the requested capacity for different Kubernetes resources. The figures shown represent the usable storage, meaning that data replication is not taken into consideration.",
"Internal": "Internal",
"Disaster recovery optimisation": "Disaster recovery optimisation",
"Configure cluster for Regional-DR?": "Configure cluster for Regional-DR?",
"<0>Optimise the cluster for a Regional-DR setup by migrating OSDs. Migration may take sometime depending on several factors. To learn more about OSDs migration best practices and its consequences refer to the documentation</0>": "<0>Optimise the cluster for a Regional-DR setup by migrating OSDs. Migration may take sometime depending on several factors. To learn more about OSDs migration best practices and its consequences refer to the documentation</0>",
"Raw capacity is the absolute total disk space available to the array subsystem.": "Raw capacity is the absolute total disk space available to the array subsystem.",
"Troubleshoot": "Troubleshoot",
"Active health checks": "Active health checks",
Expand Down
9 changes: 9 additions & 0 deletions packages/ocs/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ export enum CLUSTER_STATUS {
}

export const CEPH_INTERNAL_CR_NAME = 'ocs-storagecluster-cephcluster';

export const DISASTER_RECOVERY_TARGET_ANNOTATION =
'ocs.openshift.io/clusterIsDisasterRecoveryTarget';

export enum DRSetupStatus {
InProgress = 'In Progress',
Pending = 'Pending',
Completed = 'Completed',
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const DetailsCard: React.FC = () => {
: t('Disabled');

const ocsName = getName(resourcesObj['ocs'].data?.[0]);
//const disasterRecoveryStatus = getDRsetupStatus();

const [csv, csvLoaded, csvError] = useFetchCsv({
specName: !isODF ? OCS_OPERATOR : ODF_OPERATOR,
Expand Down
140 changes: 138 additions & 2 deletions packages/ocs/dashboards/persistent-internal/details-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,113 @@ import { useK8sGet } from '@odf/shared/hooks/k8s-get-hook';
import { useFetchCsv } from '@odf/shared/hooks/use-fetch-csv';
import { useK8sList } from '@odf/shared/hooks/useK8sList';
import {
CephClusterModel,
ClusterServiceVersionModel,
InfrastructureModel,
} from '@odf/shared/models';
import { getName } from '@odf/shared/selectors';
import { K8sResourceKind, StorageClusterKind } from '@odf/shared/types';
import { getAnnotations, getName } from '@odf/shared/selectors';
import {
CephClusterKind,
K8sResourceKind,
StorageClusterKind,
} from '@odf/shared/types';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import {
getInfrastructurePlatform,
resourcePathFromModel,
} from '@odf/shared/utils';
import { k8sUpdate } from '@openshift-console/dynamic-plugin-sdk';
import { DetailsBody } from '@openshift-console/dynamic-plugin-sdk-internal';
import { OverviewDetailItem as DetailItem } from '@openshift-console/plugin-shared';
import { Trans } from 'react-i18next';
import { Link } from 'react-router-dom';
import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core';
import { Modal, ModalVariant, Button, Alert } from '@patternfly/react-core';
import { CEPH_NS } from '../../constants';
import {
DISASTER_RECOVERY_TARGET_ANNOTATION,
DRSetupStatus,
} from '../../constants';
import { StorageClusterModel } from '../../models';
import { getNetworkEncryption } from '../../utils';

const DetailsCard: React.FC = () => {
const { t } = useCustomTranslation();
const [data, loaded, loadError] = useK8sList<CephClusterKind>(
CephClusterModel,
CEPH_NS
);

const [isOpen, setOpen] = React.useState(false);
const [updateError, setUpdateError] = React.useState('');

const openModal = () => {
setOpen(true);
};

const closeModal = () => {
setOpen(false);
};

const handleOptimize = () => {
const updatedResource = { ...data[0] };

updatedResource.metadata.annotations = {
...getAnnotations(updatedResource, {}),
[DISASTER_RECOVERY_TARGET_ANNOTATION]: 'true',
};

const updateData = {
model: CephClusterModel,
data: updatedResource,
};

k8sUpdate(updateData)
.then(() => {
closeModal();
})
.catch((err) => {
setUpdateError(err.message);
});
};

const getType = () => {
if (data && data.length > 0) {
const bluestoreCount =
data[0]?.status?.storage?.osd?.storeType?.['bluestore'];
const bluestoreRdrCount =
data[0]?.status?.storage?.osd?.storeType?.['bluestore-rdr'];

const isDisasterRecoveryTarget =
data[0]?.metadata?.annotations?.[
DISASTER_RECOVERY_TARGET_ANNOTATION
] === 'true';

if (bluestoreCount > 0) {
if (bluestoreRdrCount > 0) {
return DRSetupStatus.InProgress;
} else if (isDisasterRecoveryTarget) {
return DRSetupStatus.InProgress;
} else {
return DRSetupStatus.Pending;
}
} else if (bluestoreRdrCount > 0) {
return 'Completed';
}

return '';
}
};

const dRSetupStatus = getType();

const [infrastructure, infrastructureLoaded, infrastructureError] =
useK8sGet<K8sResourceKind>(InfrastructureModel, 'cluster');
const [ocsData, ocsLoaded, ocsError] = useK8sList<StorageClusterKind>(
StorageClusterModel,
CEPH_NS
);

const [csv, csvLoaded, csvError] = useFetchCsv({
specName: ODF_OPERATOR,
namespace: CEPH_STORAGE_NAMESPACE,
Expand Down Expand Up @@ -100,6 +181,61 @@ const DetailsCard: React.FC = () => {
>
{inTransitEncryptionStatus}
</DetailItem>
<DetailItem
key="dr_setup_state"
title={t('Disaster recovery optimisation')}
>
{loaded && !loadError ? (
<div>
<div
style={{ display: 'flex', justifyContent: 'space-between' }}
>
<p>{dRSetupStatus}</p>
{dRSetupStatus === DRSetupStatus.Pending && (
<a onClick={openModal}>Optimize</a>
)}
</div>
<Modal
variant={ModalVariant.medium}
title={t('Configure cluster for Regional-DR?')}
isOpen={isOpen}
onClose={closeModal}
actions={[
<Button
key="close"
variant="secondary"
onClick={closeModal}
>
Close
</Button>,
<Button
key="optimize"
variant="primary"
onClick={handleOptimize}
>
Optimize
</Button>,
]}
>
<Trans t={t}>
<p>
Optimise the cluster for a Regional-DR setup by migrating
OSDs. Migration may take sometime depending on several
factors. To learn more about OSDs migration best practices
and its consequences refer to the documentation
</p>
</Trans>
</Modal>
</div>
) : (
''
)}
{updateError && (
<Alert isInline variant="danger" title={t('An error occurred')}>
{updateError}
</Alert>
)}
</DetailItem>
</DetailsBody>
</CardBody>
</Card>
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/types/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ type CephDeviceClass = {
export type CephClusterKind = K8sResourceCommon & {
status?: {
storage: {
osd: {
storeType: {
bluestore: number;
'bluestore-rdr': number;
};
};
deviceClasses: CephDeviceClass[];
};
ceph?: {
Expand Down

0 comments on commit bcf9d6c

Please sign in to comment.