Skip to content

Commit

Permalink
Merge pull request #1676 from GowthamShanmugam/RHSTOR-6634
Browse files Browse the repository at this point in the history
UI check to avoid peering a same managed cluster with more than one cluster
  • Loading branch information
openshift-merge-bot[bot] authored Nov 15, 2024
2 parents cb13092 + 0b69437 commit 1059fea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"Replication policy": "Replication policy",
"Unsupported peering configuration.": "Unsupported peering configuration.",
"The clusters you're trying to peer aren't compatible. It could be due to mismatched types (one with a client, the other without) or both using the same Data Foundation provider. Select clusters that are either the same type or have separate providers to continue.": "The clusters you're trying to peer aren't compatible. It could be due to mismatched types (one with a client, the other without) or both using the same Data Foundation provider. Select clusters that are either the same type or have separate providers to continue.",
"Existing DRPolicy detected.": "Existing DRPolicy detected.",
"A DRPolicy is already configured for selected managed clusters. You cannot create another DRPolicy using the same pair of clusters.": "A DRPolicy is already configured for selected managed clusters. You cannot create another DRPolicy using the same pair of clusters.",
"Selected clusters cannot be used to create a DRPolicy.": "Selected clusters cannot be used to create a DRPolicy.",
"A mirror peer configuration already exists for one or more of the selected clusters, either from an existing or deleted DR policy. To create a new DR policy with these clusters, delete any existing mirror peer configurations associated with them and try again.": "A mirror peer configuration already exists for one or more of the selected clusters, either from an existing or deleted DR policy. To create a new DR policy with these clusters, delete any existing mirror peer configurations associated with them and try again.",
"Data foundation must be {{version}} or above.": "Data foundation must be {{version}} or above.",
"Must be connected to RHCS.": "Must be connected to RHCS.",
"The cluster has multiple storage instances.": "The cluster has multiple storage instances.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const CreateDRPolicy: React.FC<{}> = () => {
selectedClusters={state.selectedClusters}
requiredODFVersion={odfMCOVersion}
dispatch={dispatch}
mirrorPeers={mirrorPeers}
/>
</FormGroup>
{state.isClusterSelectionValid && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { pluralize } from '@odf/core/components/utils';
import { REPLICATION_TYPE } from '@odf/mco/constants';
import { getDRPolicyResourceObj } from '@odf/mco/hooks';
import { DRPolicyKind } from '@odf/mco/types';
import { DRPolicyKind, MirrorPeerKind } from '@odf/mco/types';
import { getReplicationType } from '@odf/mco/utils';
import { getName, StatusBox } from '@odf/shared';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
Expand Down Expand Up @@ -57,9 +57,26 @@ const checkClientToODFPeering = (clusters: ManagedClusterInfoType[]): boolean =>
!!clusters[0]?.odfInfo?.storageClusterInfo?.clientInfo !==
!!clusters[1]?.odfInfo?.storageClusterInfo?.clientInfo;

const verifyMirrorPeerExistence = (
clusters: ManagedClusterInfoType[],
mirrorPeers: MirrorPeerKind[]
): boolean => {
const peerNames: string[] = clusters.map(getName);
const mirrorPeer: MirrorPeerKind = mirrorPeers.find((mirrorPeer) =>
mirrorPeer.spec?.items?.some((item) => peerNames.includes(item.clusterName))
);
const existingPeerNames =
mirrorPeer?.spec?.items?.map((item) => item.clusterName) ?? [];
// When one of the chosen clusters is already paired with another cluster, return True.
return existingPeerNames.length > 0
? existingPeerNames.sort().join(',') !== peerNames.sort().join(',')
: false;
};

const validateClusterSelection = (
clusters: ManagedClusterInfoType[],
drPolicies: DRPolicyKind[]
drPolicies: DRPolicyKind[],
mirrorPeers: MirrorPeerKind[]
): ValidationType => {
const validation: ValidationType = clusters.reduce(
(acc, cluster) => {
Expand Down Expand Up @@ -92,9 +109,11 @@ const validateClusterSelection = (
);

validation.peeringValidation = {
syncPolicyFound: checkSyncPolicyExists(clusters.map(getName), drPolicies),
unSupportedPeering:
checkClientToClientPeering(clusters) || checkClientToODFPeering(clusters),
invalidPolicyCreation:
checkSyncPolicyExists(clusters.map(getName), drPolicies) ||
verifyMirrorPeerExistence(clusters, mirrorPeers),
};

return validation;
Expand All @@ -114,12 +133,13 @@ const getPeeringValidationMessage = (
'the same type or have separate providers to continue.'
),
};
} else if (peeringValidation.syncPolicyFound) {
} else if (peeringValidation.invalidPolicyCreation) {
return {
title: t('Existing DRPolicy detected.'),
title: t('Selected clusters cannot be used to create a DRPolicy.'),
description: t(
'A DRPolicy is already configured for selected managed clusters. ' +
'You cannot create another DRPolicy using the same pair of clusters.'
'A mirror peer configuration already exists for one or more of the selected clusters, ' +
'either from an existing or deleted DR policy. To create a new DR policy with these clusters, ' +
'delete any existing mirror peer configurations associated with them and try again.'
),
};
}
Expand Down Expand Up @@ -219,7 +239,7 @@ const PeeringValidationMessage: React.FC<PeeringValidationMessageProps> = ({
};

export const SelectedClusterValidation: React.FC<SelectedClusterValidationProps> =
({ selectedClusters, requiredODFVersion, dispatch }) => {
({ selectedClusters, requiredODFVersion, dispatch, mirrorPeers }) => {
const { t } = useCustomTranslation();

const [drPolicies, policyLoaded, policyLoadError] = useK8sWatchResource<
Expand All @@ -239,7 +259,8 @@ export const SelectedClusterValidation: React.FC<SelectedClusterValidationProps>

const validations: ValidationType = validateClusterSelection(
selectedClusters,
drPolicies
drPolicies,
mirrorPeers
);

const { peeringValidation, clusterValidation } = validations;
Expand Down Expand Up @@ -337,11 +358,12 @@ type SelectedClusterValidationProps = {
selectedClusters: ManagedClusterInfoType[];
requiredODFVersion: string;
dispatch: React.Dispatch<DRPolicyAction>;
mirrorPeers: MirrorPeerKind[];
};

type PeeringValidationType = {
unSupportedPeering: boolean;
syncPolicyFound: boolean;
invalidPolicyCreation: boolean;
};

type ClusterValidationType = {
Expand Down

0 comments on commit 1059fea

Please sign in to comment.