Skip to content

Commit

Permalink
Merge pull request #1716 from SanjalKatiyar/device_class_sc_encryption
Browse files Browse the repository at this point in the history
Add 'encryptionKMSID' for 'Attach Storage' form
  • Loading branch information
openshift-merge-bot[bot] authored Nov 27, 2024
2 parents c8ab830 + 1a441e1 commit 4521641
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ export const AttachStorageFormFooter = (
errorMessage,
storageClassDetails,
} = state;
const { name } = storageClassDetails;
const { name, enableStorageClassEncryption, encryptionKMSID } =
storageClassDetails;
const isDisabled =
checkRequiredValues(poolName, replicaSize, lsoStorageClassName, name) ||
checkRequiredValues(
poolName,
replicaSize,
lsoStorageClassName,
name,
enableStorageClassEncryption,
encryptionKMSID
) ||
inProgress ||
!!errorMessage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.storagepool-form {
margin-top: var(--pf-v5-global--spacer--md);
margin-left: calc(var(--pf-v5-global--spacer--lg) * -1);
}
.attachstorage-form {
margin-right: var(--pf-v5-global--spacer--xl);
Expand Down
16 changes: 16 additions & 0 deletions packages/odf/components/attach-storage-storagesystem/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type StorageClassDetails = {
name: string;
volumeBindingMode: VolumeBindingMode;
enableStorageClassEncryption: boolean;
encryptionKMSID: string;
};

type PoolDetails = {
Expand Down Expand Up @@ -49,6 +50,7 @@ export const initialAttachStorageState: AttachStorageFormState = {
name: '',
volumeBindingMode: VolumeBindingMode.WaitForFirstConsumer,
enableStorageClassEncryption: false,
encryptionKMSID: '',
},
};

Expand Down Expand Up @@ -97,6 +99,7 @@ export enum AttachStorageActionType {
SET_DEVICESET_ENCRYPTION = 'SET_DEVICESET_ENCRYPTION',
SET_STORAGECLASS_NAME = 'SET_STORAGECLASS_NAME',
SET_STORAGECLASS_ENCRYPTION = 'SET_STORAGECLASS_ENCRYPTION',
SET_ENCRYPTION_KMS_ID = 'SET_ENCRYPTION_KMS_ID',
SET_STORAGECLASS_RECLAIM_POLICY = 'SET_STORAGECLASS_RECLAIM_POLICY',
SET_STORAGECLASS_VOLUME_BINDING_MODE = 'SET_STORAGECLASS_VOLUME_BINDING_MODE',
}
Expand Down Expand Up @@ -127,6 +130,10 @@ export type AttachStorageAction =
type: AttachStorageActionType.SET_STORAGECLASS_ENCRYPTION;
payload: boolean;
}
| {
type: AttachStorageActionType.SET_ENCRYPTION_KMS_ID;
payload: string;
}
| {
type: AttachStorageActionType.SET_STORAGECLASS_RECLAIM_POLICY;
payload: ReclaimPolicy;
Expand Down Expand Up @@ -225,6 +232,15 @@ export const attachStorageReducer = (
},
};
}
case AttachStorageActionType.SET_ENCRYPTION_KMS_ID: {
return {
...state,
storageClassDetails: {
...state.storageClassDetails,
encryptionKMSID: action.payload,
},
};
}
case AttachStorageActionType.SET_STORAGECLASS_RECLAIM_POLICY: {
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { StorageClassEncryptionKMSID } from '@odf/ocs/storage-class/sc-form';
import { ReclaimPolicy, VolumeBindingMode } from '@odf/shared';
import {
Dropdown,
Expand Down Expand Up @@ -39,6 +40,16 @@ const StorageClassForm: React.FC<StorageClassFormProps> = ({
payload: !state.storageClassDetails.enableStorageClassEncryption,
});
}, [dispatch, state.storageClassDetails.enableStorageClassEncryption]);
const onEncryptionKMSIDChange = (
_id: string,
paramName: string,
_checkbox: boolean
) => {
dispatch({
type: AttachStorageActionType.SET_ENCRYPTION_KMS_ID,
payload: paramName,
});
};

const reclaimPolicyDropdownItems = React.useMemo(() => {
return Object.values(ReclaimPolicy).map((policy) => (
Expand Down Expand Up @@ -178,12 +189,19 @@ const StorageClassForm: React.FC<StorageClassFormProps> = ({
</FormGroup>
<FormGroup>
<Checkbox
id="enable-encryption-device-set"
id="enable-encryption-storage-class"
label={t('Enable encryption on StorageClass')}
className="pf-v5-u-pt-md"
isChecked={state.storageClassDetails.enableStorageClassEncryption}
onChange={onEncryptionChange}
/>
{!!state.storageClassDetails.enableStorageClassEncryption && (
<StorageClassEncryptionKMSID
onParamChange={onEncryptionKMSIDChange}
parameterKey=""
parameterValue={state.storageClassDetails.encryptionKMSID}
/>
)}
</FormGroup>
</div>
);
Expand Down
10 changes: 8 additions & 2 deletions packages/odf/components/attach-storage-storagesystem/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ export const checkRequiredValues = (
poolName: string,
replicaSize: string,
lsoStorageClassName: string,
storageClassName: string
storageClassName: string,
enableStorageClassEncryption: boolean,
encryptionKMSID: string
): boolean =>
!poolName || !replicaSize || !lsoStorageClassName || !storageClassName;
!poolName ||
!replicaSize ||
!lsoStorageClassName ||
!storageClassName ||
(enableStorageClassEncryption ? !encryptionKMSID : false);

0 comments on commit 4521641

Please sign in to comment.