-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide option to optimise cluster for Regional-DR
Signed-off-by: Timothy Asir Jeyasingh <[email protected]>
- Loading branch information
1 parent
9b55fef
commit 74e1979
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/ocs/modals/osd-migration/osd-migration-details.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters