Skip to content

Commit

Permalink
Merge pull request #932 from GowthamShanmugam/2209288
Browse files Browse the repository at this point in the history
After hub recovery, cant initiate failover
  • Loading branch information
openshift-merge-robot authored Aug 8, 2023
2 parents 931c8db + c53734a commit 2ff703f
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../../../types';
import {
findDRType,
findDeploymentClusters,
getProtectedPVCsFromDRPC,
getRemoteNamespaceFromAppSet,
} from '../../../utils';
Expand Down Expand Up @@ -109,8 +110,11 @@ export const DRDashboard: React.FC = () => {
drPolicy,
placementDecision,
} = argoApplicationSetResource?.placements?.[0] || {};
placementDecision?.status?.decisions?.forEach((decision) => {
const decisionCluster = decision?.clusterName;
const deploymentClusters = findDeploymentClusters(
placementDecision,
drPlacementControl
);
deploymentClusters.forEach((decisionCluster) => {
if (drClusterAppsMap.hasOwnProperty(decisionCluster)) {
drClusterAppsMap[decisionCluster].totalAppSetsCount =
drClusterAppsMap[decisionCluster].totalAppSetsCount + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { ArgoApplicationSetKind } from '../../../types';
import {
findCluster,
findDeploymentClusterName,
findDeploymentClusters,
checkDRActionReadiness,
getManagedClusterAvailableCondition,
findDRType,
Expand Down Expand Up @@ -97,11 +97,11 @@ export const ArogoApplicationSetModal = (
placementDecision,
placement,
} = resourcePlacements?.[0] || {};
let deploymentClusterName = findDeploymentClusterName(
const deploymentClusters = findDeploymentClusters(
placementDecision,
drPlacementControl,
drClusters
drPlacementControl
);
const deploymentClusterName = deploymentClusters?.[0] || '';
const targetCluster = findCluster(managedClusters, deploymentClusterName);
const primaryCluster = findCluster(
managedClusters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ const ApplyDRPolicyModal: React.FC<CommonModalProps<ApplyModalExtraProps>> = (
plDecision,
],
}),
{}
{} as PlacementDecisionMap
);

if (
Expand Down
4 changes: 4 additions & 0 deletions packages/mco/constants/disaster-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const DRPC_NAME_ANNOTATION =
export const DRPC_NAMESPACE_ANNOTATION =
'drplacementcontrol.ramendr.openshift.io/drpc-namespace';

// DRPC annotations
export const LAST_APP_DEPLOYMENT_CLUSTER_ANNOTATION =
'drplacementcontrol.ramendr.openshift.io/last-app-deployment-cluster';

// Maximum cluster per DRPolicy
export const MAX_ALLOWED_CLUSTERS = 2;

Expand Down
2 changes: 1 addition & 1 deletion packages/mco/types/acm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type ACMPlacementKind = K8sResourceCommon & {
};

export type ACMPlacementDecisionKind = K8sResourceCommon & {
status: {
status?: {
decisions: {
// ClusterDecision represents a decision from a placement
clusterName: string;
Expand Down
33 changes: 31 additions & 2 deletions packages/mco/utils/acm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { getLabel, getName, getNamespace } from '@odf/shared/selectors';
import { PLACEMENT_REF_LABEL } from '../constants';
import {
getAnnotations,
getLabel,
getName,
getNamespace,
} from '@odf/shared/selectors';
import {
LAST_APP_DEPLOYMENT_CLUSTER_ANNOTATION,
PLACEMENT_REF_LABEL,
} from '../constants';
import {
ArgoApplicationSetKind,
ACMManagedClusterKind,
ACMPlacementDecisionKind,
ACMPlacementKind,
ACMPlacementRuleKind,
DRPlacementControlKind,
} from '../types';

// Finding placement from application generators
Expand Down Expand Up @@ -65,3 +74,23 @@ export const getClustersFromDecisions = (
export const getRemoteNamespaceFromAppSet = (
application: ArgoApplicationSetKind
): string => application?.spec?.template?.spec?.destination?.namespace;

export const getLastAppDeploymentClusterName = (
drPlacementControl: DRPlacementControlKind
) =>
getAnnotations(drPlacementControl)?.[
LAST_APP_DEPLOYMENT_CLUSTER_ANNOTATION
] || '';

export const findDeploymentClusters = (
placementDecision: ACMPlacementDecisionKind,
drPlacementControl: DRPlacementControlKind
): string[] => {
if ((placementDecision ?? {}).status?.decisions?.length > 0) {
return getClustersFromDecisions(placementDecision);
} else {
const lastDeploymentClusterName =
getLastAppDeploymentClusterName(drPlacementControl);
return !!lastDeploymentClusterName ? [lastDeploymentClusterName] : [];
}
};
34 changes: 7 additions & 27 deletions packages/mco/utils/disaster-recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ import {
ACMPlacementKind,
MirrorPeerKind,
} from '../types';
import { findPlacementDecisionUsingPlacement } from './acm';
import {
findPlacementDecisionUsingPlacement,
getLastAppDeploymentClusterName,
} from './acm';

export type PlacementMap = {
[placementUniqueId: string]: string;
Expand Down Expand Up @@ -221,7 +224,9 @@ export const getAppDRInfo = (
{
drPlacementControl: drPlacementControl,
subscriptions: subscriptionMap?.[uniqueId],
clusterName: placementMap?.[uniqueId] || '',
clusterName:
placementMap?.[uniqueId] ||
getLastAppDeploymentClusterName(drPlacementControl),
},
]
: acc;
Expand Down Expand Up @@ -521,31 +526,6 @@ export const filterPVCDataUsingAppsets = (
export const filterDRAlerts = (alert: Alert) =>
alert?.annotations?.alert_type === 'DisasterRecovery';

export const findDeploymentClusterName = (
plsDecision: ACMPlacementDecisionKind,
drpc: DRPlacementControlKind,
drClusters: DRClusterKind[]
): string => {
let deploymentClusterName =
plsDecision?.status?.decisions?.[0]?.clusterName || '';
// During failover/relocating ramen removing cluser name from placement decision
if (!deploymentClusterName) {
const currStatus: DRPC_STATUS = drpc?.status?.phase as DRPC_STATUS;
if (currStatus === DRPC_STATUS.Relocating) {
// While relocating, preferredCluster spec is the target cluster
// Find deployment cluster from drclusters using target cluster
const cluster = findCluster(drClusters, drpc?.spec?.preferredCluster);
deploymentClusterName = getName(cluster);
} else if (currStatus === DRPC_STATUS.FailingOver) {
// While failover, failoverCluster spec is the target cluster
// Find deployment cluster from drclusters using target cluster
const cluster = findCluster(drClusters, drpc?.spec?.failoverCluster);
deploymentClusterName = getName(cluster);
}
}
return deploymentClusterName;
};

export const isDRPolicyValidated = (drPolicy: DRPolicyKind) =>
drPolicy?.status?.conditions?.some(
(condition) =>
Expand Down

0 comments on commit 2ff703f

Please sign in to comment.