diff --git a/locales/en/plugin__odf-console.json b/locales/en/plugin__odf-console.json index 70253b511..da0a6c4a2 100644 --- a/locales/en/plugin__odf-console.json +++ b/locales/en/plugin__odf-console.json @@ -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", @@ -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", diff --git a/packages/ocs/dashboards/persistent-internal/details-card.tsx b/packages/ocs/dashboards/persistent-internal/details-card.tsx index e257287ad..8bbb355e1 100644 --- a/packages/ocs/dashboards/persistent-internal/details-card.tsx +++ b/packages/ocs/dashboards/persistent-internal/details-card.tsx @@ -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, @@ -34,6 +40,12 @@ const DetailsCard: React.FC = () => { StorageClusterModel, odfNamespace ); + + const [cephData, cephLoaded, cephLoadError] = useSafeK8sList( + CephClusterModel, + odfNamespace + ); + const [csv, csvLoaded, csvError] = useFetchCsv({ specName: ODF_OPERATOR, namespace: odfNamespace, @@ -104,6 +116,14 @@ const DetailsCard: React.FC = () => { > {inTransitEncryptionStatus} + + + diff --git a/packages/ocs/modals/osd-migration/osd-migration-details.tsx b/packages/ocs/modals/osd-migration/osd-migration-details.tsx new file mode 100644 index 000000000..7d4556288 --- /dev/null +++ b/packages/ocs/modals/osd-migration/osd-migration-details.tsx @@ -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 = ({ + cephData, + ocsData, +}) => { + const { t } = useCustomTranslation(); + const osdMigrationStatus: string = getOSDMigrationStatus(cephData); + const launcher = useModal(); + + return ( + <> + + + + ) + } + /> + + + {osdMigrationStatus === OSDMigrationStatus.PENDING && ( + + )} + + + + ); +}; + +type OSDMigrationDetailsProps = { + cephData: CephClusterKind; + ocsData: StorageClusterKind; +}; diff --git a/packages/ocs/modals/osd-migration/osd-migration-modal.tsx b/packages/ocs/modals/osd-migration/osd-migration-modal.tsx new file mode 100644 index 000000000..6cff41aa1 --- /dev/null +++ b/packages/ocs/modals/osd-migration/osd-migration-modal.tsx @@ -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 = ({ + isOpen, + extraProps, + closeModal, +}) => { + const { t } = useCustomTranslation(); + const ocsData = extraProps?.ocsData; + const [errorMessage, setErrorMessage] = React.useState(''); + + 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 ( + + {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 */} + + {!!errorMessage && ( + + {errorMessage} + + )} + + + + + + + ); +}; + +type OSDMigrationModalProps = CommonModalProps<{ + ocsData: StorageClusterKind; +}>; + +export default OSDMigrationModal; diff --git a/packages/ocs/utils/index.ts b/packages/ocs/utils/index.ts index 19a379cda..d92e7cc61 100644 --- a/packages/ocs/utils/index.ts +++ b/packages/ocs/utils/index.ts @@ -3,3 +3,4 @@ export * from './noobaa-health'; export * from './common'; export * from './metrics'; export * from './block-pool'; +export * from './osd-migration';