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

Provide option to optimise cluster for Regional-DR #1095

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
5 changes: 5 additions & 0 deletions locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@
"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",
"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.",
"Cluster ready for Regional-DR setup.": "Cluster ready for Regional-DR setup.",
"Setting up disaster recovery": "Setting up disaster recovery",
Expand All @@ -478,6 +479,10 @@
"Go To PVC List": "Go To PVC List",
"Save": "Save",
"BlockPool Update Form": "BlockPool Update Form",
"Optimise cluster": "Optimise cluster",
"Optimise cluster for Regional-DR?": "Optimise cluster for Regional-DR?",
"Configure the cluster for a Regional-DR setup by migrating OSDs. Migration may take some time depending on several factors. To learn more about OSDs migration best practices and its consequences refer to the documentation.": "Configure the cluster for a Regional-DR setup by migrating OSDs. Migration may take some time depending on several factors. To learn more about OSDs migration best practices and its consequences refer to the documentation.",
"Optimise": "Optimise",
"Filesystem name": "Filesystem name",
"Enter filesystem name": "Enter filesystem name",
"CephFS filesystem name into which the volume shall be created": "CephFS filesystem name into which the volume shall be created",
Expand Down
22 changes: 21 additions & 1 deletion packages/ocs/dashboards/persistent-internal/details-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import * as React from 'react';
import { useSafeK8sList } from '@odf/core/hooks';
import { useODFNamespaceSelector } from '@odf/core/redux';
import { getOperatorVersion } from '@odf/core/utils';
import { OSDMigrationDetails } from '@odf/ocs/modals/osd-migration/osd-migration-details';
import { ODF_OPERATOR } from '@odf/shared/constants';
import { useK8sGet } from '@odf/shared/hooks/k8s-get-hook';
import { useFetchCsv } from '@odf/shared/hooks/use-fetch-csv';
import {
CephClusterModel,
ClusterServiceVersionModel,
InfrastructureModel,
} from '@odf/shared/models';
import { getName } from '@odf/shared/selectors';
import { K8sResourceKind, StorageClusterKind } from '@odf/shared/types';
import {
CephClusterKind,
K8sResourceKind,
StorageClusterKind,
} from '@odf/shared/types';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import {
getInfrastructurePlatform,
Expand All @@ -34,6 +40,12 @@ const DetailsCard: React.FC = () => {
StorageClusterModel,
odfNamespace
);

const [cephData, cephLoaded, cephLoadError] = useSafeK8sList<CephClusterKind>(
CephClusterModel,
odfNamespace
);

const [csv, csvLoaded, csvError] = useFetchCsv({
specName: ODF_OPERATOR,
namespace: odfNamespace,
Expand Down Expand Up @@ -104,6 +116,14 @@ const DetailsCard: React.FC = () => {
>
{inTransitEncryptionStatus}
</DetailItem>
<DetailItem
key="osd_migration"
title={t('Disaster recovery optimisation')}
isLoading={!cephLoaded}
error={cephLoadError as any}
>
<OSDMigrationDetails cephData={cephData?.[0]} ocsData={cluster} />
</DetailItem>
</DetailsBody>
</CardBody>
</Card>
Expand Down
58 changes: 58 additions & 0 deletions packages/ocs/modals/osd-migration/osd-migration-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import { OSDMigrationStatus } from '@odf/core/constants';
import { getOSDMigrationStatus } from '@odf/ocs/utils';
import { CephClusterKind, StorageClusterKind } from '@odf/shared/types';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import {
RedExclamationCircleIcon,
StatusIconAndText,
useModal,
} from '@openshift-console/dynamic-plugin-sdk';
import { Button, Flex, FlexItem } from '@patternfly/react-core';
import OSDMigrationModal from './osd-migration-modal';

export const OSDMigrationDetails: React.FC<OSDMigrationDetailsProps> = ({
cephData,
ocsData,
}) => {
const { t } = useCustomTranslation();
const osdMigrationStatus: string = getOSDMigrationStatus(cephData);
const launcher = useModal();

return (
<>
<Flex>
<FlexItem>
<StatusIconAndText
title={osdMigrationStatus}
icon={
osdMigrationStatus === OSDMigrationStatus.FAILED && (
<RedExclamationCircleIcon />
)
}
/>
</FlexItem>
<FlexItem>
{osdMigrationStatus === OSDMigrationStatus.PENDING && (
<Button
variant="link"
onClick={() =>
launcher(OSDMigrationModal, {
isOpen: true,
extraProps: { ocsData },
})
}
>
{t('Optimise cluster')}
</Button>
)}
</FlexItem>
</Flex>
</>
);
};

type OSDMigrationDetailsProps = {
cephData: CephClusterKind;
ocsData: StorageClusterKind;
};
81 changes: 81 additions & 0 deletions packages/ocs/modals/osd-migration/osd-migration-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as React from 'react';
import { DISASTER_RECOVERY_TARGET_ANNOTATION } from '@odf/core/constants';
import { CommonModalProps, ModalBody, ModalFooter } from '@odf/shared/modals';
import { OCSStorageClusterModel } from '@odf/shared/models';
import { getName, getNamespace } from '@odf/shared/selectors';
import { StorageClusterKind } from '@odf/shared/types';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { k8sPatch } from '@openshift-console/dynamic-plugin-sdk';
import { Modal, ModalVariant, Button, Alert } from '@patternfly/react-core';

export const OSDMigrationModal: React.FC<OSDMigrationModalProps> = ({
isOpen,
extraProps,
closeModal,
}) => {
const { t } = useCustomTranslation();
const ocsData = extraProps?.ocsData;
const [errorMessage, setErrorMessage] = React.useState<string>('');

const handleOptimize = () => {
const patch = [
{
op: 'add',
path: `metadata/annotations/${DISASTER_RECOVERY_TARGET_ANNOTATION}`,
value: 'true',
},
];

k8sPatch({
model: OCSStorageClusterModel,
resource: {
metadata: {
name: getName(ocsData),
namespace: getNamespace(ocsData),
},
},
data: patch,
})
.then(() => {
closeModal();
})
.catch((err) => {
setErrorMessage(err.message);
});
};

return (
<Modal
variant={ModalVariant.small}
title={t('Optimise cluster for Regional-DR?')}
isOpen={isOpen}
onClose={closeModal}
>
{t(
'Configure the cluster for a Regional-DR setup by migrating OSDs. Migration may take some time depending on several factors. To learn more about OSDs migration best practices and its consequences refer to the documentation.'
)}
{/* TODO: Show doc link once ViewDocumentation moved to shared */}
<ModalBody>
{!!errorMessage && (
<Alert isInline variant="danger" title={t('An error occurred')}>
{errorMessage}
</Alert>
)}
</ModalBody>
<ModalFooter>
<Button key="close" variant="secondary" onClick={closeModal}>
{t('Close')}
</Button>
<Button key="optimize" variant="primary" onClick={handleOptimize}>
{t('Optimise')}
</Button>
</ModalFooter>
</Modal>
);
};

type OSDMigrationModalProps = CommonModalProps<{
ocsData: StorageClusterKind;
}>;

export default OSDMigrationModal;
1 change: 1 addition & 0 deletions packages/ocs/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './noobaa-health';
export * from './common';
export * from './metrics';
export * from './block-pool';
export * from './osd-migration';