Skip to content

Commit

Permalink
Merge pull request #1137 from bipuladh/fix-mon-count
Browse files Browse the repository at this point in the history
Bug 2255340: Updates CephMonCountLow alert modal errors
  • Loading branch information
openshift-merge-bot[bot] authored Dec 21, 2023
2 parents 49b10b1 + 58fa260 commit 790a41d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@
"Configure monitor count": "Configure monitor count",
"To enhance system resilience, align Ceph monitors with the available node failure zones.": "To enhance system resilience, align Ceph monitors with the available node failure zones.",
"Failure domains: {{failureDomains}}": "Failure domains: {{failureDomains}}",
"Monitor count: 3": "Monitor count: 3",
"Monitor count: {{monitorCount}}": "Monitor count: {{monitorCount}}",
"Recommended monitor count: 5": "Recommended monitor count: 5",
"Update count": "Update count",
"and": "and",
Expand Down
33 changes: 29 additions & 4 deletions packages/odf/modals/configure-mons/configure-mons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import {
NodeKind,
NodeModel,
StorageClusterKind,
StorageClusterModel,
getName,
getNamespace,
Expand All @@ -12,6 +13,8 @@ import { LoadingInline } from '@odf/shared/generic/Loading';
import { ModalBody, ModalFooter, ModalHeader } from '@odf/shared/modals/Modal';
import { k8sPatch } from '@openshift-console/dynamic-plugin-sdk';
import { ModalComponent } from '@openshift-console/dynamic-plugin-sdk/lib/app/modal-support/ModalProvider';
import { useSelector } from 'react-redux';
import { compose } from 'redux';
import {
Alert,
Button,
Expand All @@ -24,7 +27,7 @@ import {
} from '@patternfly/react-core';
import { groupNodesByZones } from '../../components/topology/utils';
import { useSafeK8sGet } from '../../hooks';
import { useODFNamespaceSelector } from '../../redux';
import { getODFSystemFlags } from '../../redux';

const patch = [
{
Expand All @@ -34,21 +37,36 @@ const patch = [
},
];

const getStorageClusterName = (store: ReturnType<typeof getODFSystemFlags>) =>
Object.entries(store.systemFlags).find(([, flags]) => flags.isInternalMode);

const getMonitorCount = (cluster: StorageClusterKind) =>
cluster?.spec?.managedResources?.cephCluster?.monCount;

const LowMonAlertModal: ModalComponent = ({ closeModal }) => {
const { odfNamespace } = useODFNamespaceSelector();
const [namespace, clusterFlags] = useSelector(
compose(getStorageClusterName, getODFSystemFlags)
);
const { t } = useCustomTranslation();

const [errorMessage, setErrorMessage] = React.useState('');
const [inProgress, setProgress] = React.useState(false);

// ToDo (epic 4422) (bipuladh): Update it to use information from the alert.
const [storageCluster, storageClusterLoaded, storageCluserLoadError] =
useSafeK8sGet(StorageClusterModel, null, odfNamespace);
useSafeK8sGet<StorageClusterKind>(
StorageClusterModel,
clusterFlags.ocsClusterName,
namespace
);

const [nodes, nodesLoaded, nodesLoadError] = useK8sList<NodeKind>(NodeModel);
const failureDomains =
nodesLoaded && !nodesLoadError ? groupNodesByZones(nodes)?.length : [];
const Header = <ModalHeader>{t('Configure monitor count')}</ModalHeader>;

const monitorCount = getMonitorCount(storageCluster);

const onSubmit = () => {
setProgress(true);
k8sPatch({
Expand All @@ -63,6 +81,7 @@ const LowMonAlertModal: ModalComponent = ({ closeModal }) => {
})
.then(() => {
setProgress(false);
closeModal();
})
.catch((err) => {
setProgress(false);
Expand Down Expand Up @@ -102,7 +121,13 @@ const LowMonAlertModal: ModalComponent = ({ closeModal }) => {
)}
</FlexItem>
)}
<FlexItem>{t('Monitor count: 3')}</FlexItem>
<FlexItem>
{storageClusterLoaded ? (
t('Monitor count: {{monitorCount}}', { monitorCount })
) : (
<LoadingInline />
)}
</FlexItem>
</Flex>
</FlexItem>
<FlexItem>
Expand Down
2 changes: 1 addition & 1 deletion packages/odf/redux/selectors/odf-system-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ODFSystemFlagsPayload } from '../actions';

export const odfSystemFlagsReducerName = 'odfSystemFlags';

const getODFSystemFlags = (state): ODFSystemFlagsPayload =>
export const getODFSystemFlags = (state): ODFSystemFlagsPayload =>
state.plugins?.[reduxReducerScope]?.[odfSystemFlagsReducerName] || {};

export const useODFSystemFlagsSelector = (): ODFSystemFlagsPayload & {
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/types/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export type StorageClusterKind = K8sResourceCommon & {
nfs?: {
enable?: boolean;
};
managedResources?: {
cephCluster: {
monCount: 3 | 5;
};
};
manageNodes?: boolean;
storageDeviceSets?: DeviceSet[];
resourceProfile?: ResourceProfile;
Expand Down
6 changes: 6 additions & 0 deletions plugins/odf/console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@
"insertAfter": "odfdashboard",
"section": "storage",
"href": "/odf/storage-clients"
},
"flags": {
"required": ["PROVIDER_MODE"]
}
},
{
Expand All @@ -694,6 +697,9 @@
"component": {
"$codeRef": "storageConsumerListPage.ClientListPage"
}
},
"flags": {
"required": ["PROVIDER_MODE"]
}
}
]

0 comments on commit 790a41d

Please sign in to comment.