Skip to content

Commit

Permalink
Merge pull request #1416 from TimothyAsirJeyasing/support-key-rotatio…
Browse files Browse the repository at this point in the history
…n-for-pv-encryption

adding option to flatten pvc clone during drpolicy creation
  • Loading branch information
openshift-merge-bot[bot] authored Jul 1, 2024
2 parents f6b7f36 + bcbd497 commit 7bb0cdb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
4 changes: 3 additions & 1 deletion locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"Reveal password": "Reveal password",
"Pool name": "Pool name",
"Volume mode": "Volume mode",
"Advanced settings": "Advanced settings",
"Enable disaster recovery support for restored and cloned PersistentVolumeClaims (For Data Foundation only)": "Enable disaster recovery support for restored and cloned PersistentVolumeClaims (For Data Foundation only)",
"Before choosing this option, read the section<1>Creating Disaster Recovery Policy on Hub cluster chapter of Regional-DR solution guide</1>to understand the impact and limitations of this feature.": "Before choosing this option, read the section<1>Creating Disaster Recovery Policy on Hub cluster chapter of Regional-DR solution guide</1>to understand the impact and limitations of this feature.",
"Create DRPolicy": "Create DRPolicy",
"Get a quick recovery in a remote or secondary cluster with a disaster recovery (DR) policy": "Get a quick recovery in a remote or secondary cluster with a disaster recovery (DR) policy",
"Policy name": "Policy name",
Expand Down Expand Up @@ -997,7 +1000,6 @@
"Create a secret with the token for every namespace using encrypted PVCs.": "Create a secret with the token for every namespace using encrypted PVCs.",
"Authentication method": "Authentication method",
"authentication-method": "authentication-method",
"Advanced settings": "Advanced settings",
"Service account keys are needed for Google Cloud Storage authentication. The keys can be found in the service accounts page in the GCP console.": "Service account keys are needed for Google Cloud Storage authentication. The keys can be found in the service accounts page in the GCP console.",
"Learn more": "Learn more",
"Where can I find Google Cloud credentials?": "Where can I find Google Cloud credentials?",
Expand Down
66 changes: 66 additions & 0 deletions packages/mco/components/create-dr-policy/create-dr-policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
k8sCreate,
useK8sWatchResource,
} from '@openshift-console/dynamic-plugin-sdk';
import { Trans } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom-v5-compat';
import {
Form,
Expand All @@ -28,11 +29,14 @@ import {
FormHelperText,
HelperText,
HelperTextItem,
ExpandableSection,
Checkbox,
} from '@patternfly/react-core';
import {
MAX_ALLOWED_CLUSTERS,
REPLICATION_TYPE,
ODFMCO_OPERATOR,
RBD_IMAGE_FLATTEN_LABEL,
} from '../../constants';
import { DRPolicyModel, MirrorPeerModel } from '../../models';
import { DRPolicyKind, MirrorPeerKind } from '../../types';
Expand All @@ -41,6 +45,7 @@ import {
drPolicyInitialState,
DRPolicyActionType,
ManagedClusterInfoType,
DRPolicyAction,
} from './reducer';
import { SelectClusterList } from './select-cluster-list';
import { DRReplicationType } from './select-replication-type';
Expand Down Expand Up @@ -78,13 +83,17 @@ const createDRPolicy = (
policyName: string,
replicationType: REPLICATION_TYPE,
syncIntervalTime: string,
enableRBDImageFlatten: boolean,
peerNames: string[]
) => {
const drPolicyPayload: DRPolicyKind = {
apiVersion: getAPIVersionForModel(DRPolicyModel),
kind: DRPolicyModel.kind,
metadata: { name: policyName },
spec: {
replicationClassSelector: enableRBDImageFlatten
? { matchLabels: RBD_IMAGE_FLATTEN_LABEL }
: {},
schedulingInterval:
replicationType === REPLICATION_TYPE.ASYNC ? syncIntervalTime : '0m',
drClusters: peerNames,
Expand Down Expand Up @@ -119,6 +128,51 @@ const createMirrorPeer = (
const getDRPolicyListPageLink = (url: string) =>
url.replace(`/${referenceForModel(DRPolicyModel)}/~new`, '');

const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({
enableRBDImageFlatten,
dispatch,
}) => {
const { t } = useCustomTranslation();

const handleRBDImageFlattenOnChange = (checked: boolean) => {
dispatch({
type: DRPolicyActionType.SET_RBD_IMAGE_FLATTEN,
payload: checked,
});
};

return (
<ExpandableSection toggleText={t('Advanced settings')}>
<Checkbox
label={t(
'Enable disaster recovery support for restored and cloned PersistentVolumeClaims (For Data Foundation only)'
)}
isChecked={enableRBDImageFlatten}
onChange={(_event, checked: boolean) =>
handleRBDImageFlattenOnChange(checked)
}
id="flat-image-checkbox"
name="flat-image-checkbox"
/>
<Alert
className="pf-v5-u-mt-md odf-alert mco-create-data-policy__alert"
title={
<Trans>
Before choosing this option, read the section
<i className="pf-v5-u-mx-xs">
Creating Disaster Recovery Policy on Hub cluster chapter of
Regional-DR solution guide
</i>
to understand the impact and limitations of this feature.
</Trans>
}
variant={AlertVariant.warning}
isInline
/>
</ExpandableSection>
);
};

const CreateDRPolicy: React.FC<{}> = () => {
const { t } = useCustomTranslation();
const { pathname: url } = useLocation();
Expand Down Expand Up @@ -153,6 +207,7 @@ const CreateDRPolicy: React.FC<{}> = () => {
state.policyName,
state.replicationType,
state.syncIntervalTime,
state.enableRBDImageFlatten,
peerNames
)
);
Expand Down Expand Up @@ -279,6 +334,12 @@ const CreateDRPolicy: React.FC<{}> = () => {
drPolicies={drPolicies}
dispatch={dispatch}
/>
{state.replicationType === REPLICATION_TYPE.ASYNC && (
<AdvancedSettings
enableRBDImageFlatten={state.enableRBDImageFlatten}
dispatch={dispatch}
/>
)}
{errorMessage && (
<FormGroup fieldId="error-message">
<Alert
Expand Down Expand Up @@ -317,4 +378,9 @@ const CreateDRPolicy: React.FC<{}> = () => {
);
};

type AdvancedSettingsProps = {
enableRBDImageFlatten: boolean;
dispatch: React.Dispatch<DRPolicyAction>;
};

export default CreateDRPolicy;
12 changes: 11 additions & 1 deletion packages/mco/components/create-dr-policy/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type DRPolicyState = {
syncIntervalTime: string;
// Selected managed cluster for DRPolicy paring.
selectedClusters: ManagedClusterInfoType[];
enableRBDImageFlatten: boolean;
};

export enum DRPolicyActionType {
Expand All @@ -52,13 +53,15 @@ export enum DRPolicyActionType {
SET_SYNC_INTERVAL_TIME = 'SET_SYNC_INTERVAL_TIME',
SET_SELECTED_CLUSTERS = 'SET_SELECTED_CLUSTERS',
UPDATE_SELECTED_CLUSTERS = 'UPDATE_SELECTED_CLUSTERS',
SET_RBD_IMAGE_FLATTEN = 'SET_RBD_IMAGE_FLATTEN',
}

export const drPolicyInitialState: DRPolicyState = {
policyName: '',
replicationType: null,
syncIntervalTime: '5m',
selectedClusters: [],
enableRBDImageFlatten: false,
};

export type DRPolicyAction =
Expand All @@ -68,7 +71,8 @@ export type DRPolicyAction =
| {
type: DRPolicyActionType.SET_SELECTED_CLUSTERS;
payload: ManagedClusterInfoType[];
};
}
| { type: DRPolicyActionType.SET_RBD_IMAGE_FLATTEN; payload: boolean };

export const drPolicyReducer = (
state: DRPolicyState,
Expand Down Expand Up @@ -99,6 +103,12 @@ export const drPolicyReducer = (
selectedClusters: action.payload,
};
}
case DRPolicyActionType.SET_RBD_IMAGE_FLATTEN: {
return {
...state,
enableRBDImageFlatten: action.payload,
};
}
default:
return state;
}
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 @@ -23,6 +23,10 @@ export const Actions = {
DELETE_DR_POLICY: 'Delete DRPolicy',
};

// This label enables the flatten image feature
export const RBD_IMAGE_FLATTEN_LABEL = {
'replication.storage.openshift.io/flatten-mode': 'force',
};
// DR actions
export enum DRActionType {
FAILOVER = 'Failover',
Expand Down

0 comments on commit 7bb0cdb

Please sign in to comment.