Skip to content

Commit

Permalink
Merge pull request #1692 from alfonsomthd/hide-nfs-pool
Browse files Browse the repository at this point in the history
Hide NFS builtin pool
  • Loading branch information
alfonsomthd authored Nov 20, 2024
2 parents b97f1ee + 1ac83af commit 1b07337
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 60 deletions.
2 changes: 2 additions & 0 deletions cypress/constants/storage-pool-const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export enum POOL_TYPE {

export const COMPRESSION_ON = 'aggressive';
export const ROOK_MODEL = 'cephblockpools.ceph.rook.io';
export const CEPH_BUILTIN_MGR_POOL = 'builtin-mgr';
export const CEPH_BUILTIN_NFS_POOL = 'ocs-storagecluster-cephnfs-builtin-pool';
export const CEPH_DEFAULT_BLOCK_POOL_NAME = 'ocs-storagecluster-cephblockpool';
export const CEPH_DEFAULT_FS_POOL_PREFIX = 'ocs-storagecluster-cephfilesystem';
export const CEPH_DEFAULT_FS_POOL_NAME = `${CEPH_DEFAULT_FS_POOL_PREFIX}-data0`;
4 changes: 4 additions & 0 deletions cypress/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Cypress.Commands.add('install', () => {
cy.contains('Create StorageSystem', { timeout: 15 * SECOND }).should(
'be.visible'
);

// Uncomment next line only if the cluster has enough resources.
// cy.get('label[for="enable-nfs"]').click();

cy.get('button').contains('Next').click();
// @TODO: Do we still want to uncheck the already unchecked 'Taint nodes' checkbox?
// If yes, we should scroll down (needed after adding the performance profile selection)
Expand Down
20 changes: 14 additions & 6 deletions cypress/tests/storage-pool-in-storageclass-form.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
CEPH_BUILTIN_MGR_POOL,
CEPH_BUILTIN_NFS_POOL,
CEPH_DEFAULT_FS_POOL_PREFIX,
POOL_TYPE,
} from '../constants/storage-pool-const';
Expand All @@ -9,14 +11,23 @@ import {
createStoragePoolInSCForm,
fillPoolModalForm,
checkStoragePoolIsSelectableInSCForm,
showAvailablePoolsInSCForm,
} from '../views/storage-pool';

describe('Test storage pool creation when creating a new StorageClass', () => {
it(`Creates a new ${POOL_TYPE.BLOCK} pool`, () => {
const poolName = 'sc-block-name';

beforeEach(() => {
cy.clickNavLink(['Storage', 'StorageClasses']);
cy.byTestID('item-create').click();
});

it(`does not show hidden pools`, () => {
showAvailablePoolsInSCForm(POOL_TYPE.BLOCK);
cy.byTestID(CEPH_BUILTIN_MGR_POOL).should('not.exist');
cy.byTestID(CEPH_BUILTIN_NFS_POOL).should('not.exist');
});

it(`Creates a new ${POOL_TYPE.BLOCK} pool`, () => {
const poolName = 'sc-block-name';

cy.log(`Create a new ${POOL_TYPE.BLOCK} pool`);
createStoragePoolInSCForm(POOL_TYPE.BLOCK, poolName);
Expand All @@ -37,9 +48,6 @@ describe('Test storage pool creation when creating a new StorageClass', () => {
const poolName = 'sc-fs-name';
const poolFullName = `${CEPH_DEFAULT_FS_POOL_PREFIX}-${poolName}`;

cy.clickNavLink(['Storage', 'StorageClasses']);
cy.byTestID('item-create').click();

cy.log(`Create a new ${POOL_TYPE.FILESYSTEM} pool`);
createStoragePoolInSCForm(POOL_TYPE.FILESYSTEM, poolName);
checkStoragePoolIsSelectableInSCForm(poolFullName);
Expand Down
24 changes: 16 additions & 8 deletions cypress/views/storage-pool.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
CEPH_DEFAULT_BLOCK_POOL_NAME,
CEPH_DEFAULT_FS_POOL_NAME,
POOL_PROGRESS,
POOL_TYPE,
} from '../constants/storage-pool-const';
import { STORAGE_SYSTEM_NAME } from '../consts';
import { SECOND, STORAGE_SYSTEM_NAME } from '../consts';
import { NS } from '../utils/consts';
import { ODFCommon } from '../views/odf-common';
import { modal } from './modals';
Expand Down Expand Up @@ -38,8 +39,13 @@ export const navigateToStoragePoolList = () => {
cy.byTestID('horizontal-link-Storage pools').click();
};

const prepareStorageClassForm = (poolType: POOL_TYPE) => {
export const showAvailablePoolsInSCForm = (poolType: POOL_TYPE) => {
const provisioner = poolType === POOL_TYPE.BLOCK ? 'rbd' : 'cephfs';
const defaultPool =
poolType === POOL_TYPE.BLOCK
? CEPH_DEFAULT_BLOCK_POOL_NAME
: CEPH_DEFAULT_FS_POOL_NAME;

cy.log('Selecting provisioner');
cy.byTestID('storage-class-provisioner-dropdown').click();
cy.byLegacyTestID('dropdown-text-filter').type(
Expand All @@ -48,17 +54,19 @@ const prepareStorageClassForm = (poolType: POOL_TYPE) => {
cy.byTestID('dropdown-menu-item-link')
.contains(`openshift-storage.${provisioner}.csi.ceph.com`)
.click();

cy.log('Click on: Create new storage pool');
cy.byTestID('pool-dropdown-toggle', { timeout: 1000 })
cy.log('Show Storage pool list.');
cy.byTestID('pool-dropdown-toggle', { timeout: 5 * SECOND })
.should('be.visible')
.click();
cy.byTestID('create-new-pool-button').should('be.visible').click();
cy.byTestID('create-new-pool-button').should('be.visible');
cy.byTestID(defaultPool).should('be.visible');
};

export const fillPoolModalForm = (poolType: POOL_TYPE, poolName: string) => {
prepareStorageClassForm(poolType);
cy.log('Make sure the storage pool creation form is open');
showAvailablePoolsInSCForm(poolType);
cy.log('Click on: Create new storage pool');
cy.byTestID('create-new-pool-button').click();
cy.log('Make sure the storage pool creation form modal is opened.');
modal.shouldBeOpened();
modal.modalTitleShouldContain('Create Storage Pool');
fillStoragePoolForm(poolType, poolName);
Expand Down
1 change: 0 additions & 1 deletion packages/ocs/storage-class/sc-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@

.ocs-storage-class__pool--create {
color: var(--pf-v5-global--primary-color--100);
display: block;
}
31 changes: 15 additions & 16 deletions packages/ocs/storage-class/sc-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
useODFSystemFlagsSelector,
} from '@odf/core/redux';
import {
cephBlockPoolResource,
getCephBlockPoolResource,
cephClusterResource,
} from '@odf/core/resources';
import {
Expand Down Expand Up @@ -77,7 +77,6 @@ import {
Form,
Radio,
ActionGroup,
Icon,
} from '@patternfly/react-core';
import { AddCircleOIcon, CaretDownIcon } from '@patternfly/react-icons';
import {
Expand Down Expand Up @@ -172,10 +171,10 @@ const getPoolDropdownItems = (
})
}
>
<Icon size="md" className="ocs-storage-class__pool--create">
<span className="ocs-storage-class__pool--create">
<AddCircleOIcon className="pf-v5-u-mr-sm" />
{t('Create new storage pool')}
</Icon>
</span>
</DropdownItem>,
<DropdownSeparator key="separator" />,
]
Expand Down Expand Up @@ -439,17 +438,25 @@ export const BlockPoolResourceComponent: React.FC<ProvisionerProps> = ({

const launchModal = useModal();

const [poolsData, poolDataLoaded, poolDataLoadError] = useK8sWatchResource<
StoragePoolKind[]
>(cephBlockPoolResource);

const [cephClusters, cephClustersLoaded, cephClustersLoadError] =
useK8sWatchResource<CephClusterKind[]>(cephClusterResource);

const [isOpen, setOpen] = React.useState(false);
const [poolName, setPoolName] = React.useState('');
const [systemNamespace, setSystemNamespace] = React.useState<string>();

const cephCluster = getResourceInNs(cephClusters, systemNamespace);

const { systemFlags, areFlagsLoaded, flagsLoadError, areFlagsSafe } =
useODFSystemFlagsSelector();
const isExternal = systemFlags[systemNamespace]?.isExternalMode;

const poolNs = getNamespace(cephCluster);
const clusterName = systemFlags[poolNs]?.ocsClusterName;
const defaultPoolName = `${clusterName}-cephblockpool`;
const [poolsData, poolDataLoaded, poolDataLoadError] = useK8sWatchResource<
StoragePoolKind[]
>(getCephBlockPoolResource(clusterName));
const filteredPools = poolsData?.filter(
(pool) => getNamespace(pool) === systemNamespace
);
Expand All @@ -458,15 +465,7 @@ export const BlockPoolResourceComponent: React.FC<ProvisionerProps> = ({
const poolData = getStoragePoolsFromBlockPools(filteredPools) || [];
const existingNames = getExistingBlockPoolNames(poolData);

const cephCluster = getResourceInNs(cephClusters, systemNamespace);

const { systemFlags, areFlagsLoaded, flagsLoadError, areFlagsSafe } =
useODFSystemFlagsSelector();
const isExternal = systemFlags[systemNamespace]?.isExternalMode;

// Get the default deviceClass required by the 'create' modal.
const poolNs = getNamespace(cephCluster);
const defaultPoolName = `${systemFlags[poolNs]?.ocsClusterName}-cephblockpool`;
const defaultPool = filteredPools.find(
(pool: StoragePoolKind) => pool.metadata.name === defaultPoolName
);
Expand Down
55 changes: 30 additions & 25 deletions packages/ocs/storage-pool/StoragePoolListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useODFSystemFlagsSelector } from '@odf/core/redux';
import { cephBlockPoolResource } from '@odf/core/resources';
import { getCephBlockPoolResource } from '@odf/core/resources';
import { healthStateMapping } from '@odf/shared/dashboards/status-card/states';
import {
useCustomPrometheusPoll,
Expand Down Expand Up @@ -33,6 +33,7 @@ import {
useListPageFilter,
VirtualizedTable,
useK8sWatchResources,
WatchK8sResources,
} from '@openshift-console/dynamic-plugin-sdk';
import Status from '@openshift-console/dynamic-plugin-sdk/lib/app/components/status/Status';
import classNames from 'classnames';
Expand Down Expand Up @@ -420,20 +421,7 @@ type StoragePoolListPageProps = {
storageClasses: StorageClassResourceKind[];
loaded: boolean;
loadError: any;
managedByOCS: string;
};

const resources = {
sc: {
kind: StorageClassModel.kind,
namespaced: false,
isList: true,
},
blockPools: cephBlockPoolResource,
filesystem: {
kind: referenceForModel(CephFileSystemModel),
isList: false,
},
clusterName: string;
};

type WatchType = {
Expand All @@ -442,18 +430,35 @@ type WatchType = {
filesystem: CephFilesystemKind;
};

const getResources = (
clusterName: string,
clusterNamespace: string
): WatchK8sResources<WatchType> => {
return {
sc: {
kind: StorageClassModel.kind,
namespaced: false,
isList: true,
},
blockPools: getCephBlockPoolResource(clusterName),
filesystem: {
kind: referenceForModel(CephFileSystemModel),
isList: false,
name: `${clusterName}-cephfilesystem`,
namespace: clusterNamespace,
},
};
};

// To divide the number of hooks, add _StoragePoolListPage on top of StoragePoolListPage.
const _StoragePoolListPage: React.FC = () => {
const { namespace: clusterNs } = useParams<ODFSystemParams>();
const { systemFlags, areFlagsLoaded, flagsLoadError } =
useODFSystemFlagsSelector();
const managedByOCS = systemFlags[clusterNs]?.ocsClusterName;

resources.filesystem['name'] = `${managedByOCS}-cephfilesystem`;
resources.filesystem['namespace'] = clusterNs;
const clusterName = systemFlags[clusterNs]?.ocsClusterName;

const response = useK8sWatchResources(
resources
getResources(clusterName, clusterNs)
) as WatchK8sResults<WatchType>;

const storageClasses = response.sc.data;
Expand Down Expand Up @@ -489,7 +494,7 @@ const _StoragePoolListPage: React.FC = () => {
storageClasses={memoizedSC}
loaded={loaded}
loadError={error}
managedByOCS={managedByOCS}
clusterName={clusterName}
/>
);
};
Expand All @@ -499,7 +504,7 @@ const StoragePoolListPage: React.FC<StoragePoolListPageProps> = ({
storageClasses,
loaded,
loadError,
managedByOCS,
clusterName,
}) => {
const { t } = useCustomTranslation();

Expand All @@ -516,7 +521,7 @@ const StoragePoolListPage: React.FC<StoragePoolListPageProps> = ({
query: getPoolQuery(
poolNames,
StorageDashboardQuery.POOL_RAW_CAPACITY_USED,
managedByOCS
clusterName
),
basePath: usePrometheusBasePath(),
},
Expand All @@ -532,7 +537,7 @@ const StoragePoolListPage: React.FC<StoragePoolListPageProps> = ({
query: getPoolQuery(
poolNames,
StorageDashboardQuery.POOL_COMPRESSION_SAVINGS,
managedByOCS
clusterName
),
basePath: usePrometheusBasePath(),
},
Expand All @@ -551,7 +556,7 @@ const StoragePoolListPage: React.FC<StoragePoolListPageProps> = ({
query: getPoolQuery(
poolNames,
StorageDashboardQuery.POOL_MIRRORING_IMAGE_HEALTH,
managedByOCS
clusterName
),
basePath: usePrometheusBasePath(),
},
Expand Down
13 changes: 9 additions & 4 deletions packages/odf/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ export const subscriptionResource: WatchK8sResource = {
* Retrieve all the CRs except those not meant to be
* exposed to the users. See:
* https://bugzilla.redhat.com/show_bug.cgi?id=2297295
* https://issues.redhat.com/browse/DFBUGS-871
*/
export const cephBlockPoolResource: WatchK8sResource = {
kind: referenceForModel(CephBlockPoolModel),
isList: true,
fieldSelector: 'metadata.name!=builtin-mgr',
export const getCephBlockPoolResource = (
clusterName: string
): WatchK8sResource => {
return {
kind: referenceForModel(CephBlockPoolModel),
isList: true,
fieldSelector: `metadata.name!=builtin-mgr,metadata.name!=${clusterName}-cephnfs-builtin-pool`,
};
};

export const nodeResource: WatchK8sResource = {
Expand Down

0 comments on commit 1b07337

Please sign in to comment.