diff --git a/frontend/e2e/fixtures/operator-migration-fixture.ts b/frontend/e2e/fixtures/operator-migration-fixture.ts index 805a1cd68a6..32f6bba8bd7 100644 --- a/frontend/e2e/fixtures/operator-migration-fixture.ts +++ b/frontend/e2e/fixtures/operator-migration-fixture.ts @@ -28,10 +28,20 @@ interface Resource { deletionTimestamp?: string; finalizers?: string[]; annotations?: Record; + labels?: Record; + ownerReferences?: { + apiVersion: string; + kind: string; + name: string; + uid: string; + controller?: boolean; + }[]; }; spec?: { namespace?: string; lifecycleState?: string; + group?: string; + revision?: number; source?: { catalog?: { packageName?: string } }; }; status?: { @@ -59,6 +69,22 @@ export class OperatorMigrationFixture { private readonly jobs = new Set(); private readonly rollbackHolds = new Set<() => Promise>(); + /** Detects the revision manager API used by this cluster. */ + private async hasDeploymentAPI(): Promise { + try { + await this.client.getClusterCustomResource( + 'apiextensions.k8s.io', + 'v1', + 'customresourcedefinitions', + 'clusterobjectdeployments.olm.operatorframework.io', + ); + return true; + } catch (error) { + if (isNotFound(error)) return false; + throw error; + } + } + /** Creates isolated catalog identifiers and shares cleanup and authentication configuration. */ constructor( private readonly client: KubernetesClient, @@ -154,6 +180,14 @@ export class OperatorMigrationFixture { 'v1', 'clusterextensions', ); + if (await this.hasDeploymentAPI()) { + this.cleanup.trackClusterCustomResource( + subscriptionName, + TARGET_GROUP, + 'v1', + 'clusterobjectdeployments', + ); + } this.cleanup.trackClusterCustomResource( `${subscriptionName}-1`, TARGET_GROUP, @@ -600,25 +634,90 @@ export class OperatorMigrationFixture { const references = await this.client.coreV1Api.listSecretForAllNamespaces({ labelSelector, }); - return { revisions: revisions.items.length, references: references.items.length }; + let deployments = 0; + if (await this.hasDeploymentAPI()) { + const result = (await this.client.customObjectsApi.listClusterCustomObject({ + group: TARGET_GROUP, + version: 'v1', + plural: 'clusterobjectdeployments', + labelSelector, + })) as { items: Resource[] }; + deployments = result.items.length; + } + return { + revisions: revisions.items.length, + references: references.items.length, + deployments, + }; }, { timeout: 60_000, message: 'Recovery must remove all migration revisions and reference Secrets', }, ) - .toEqual({ revisions: 0, references: 0 }); + .toEqual({ revisions: 0, references: 0, deployments: 0 }); } /** Verifies retained migration resources and reconciliation after revision handover. */ async expectPreservedMigration(operator: MigrationOperator): Promise { await expect(async () => { - const objectSet = (await this.client.getClusterCustomResource( - TARGET_GROUP, - 'v1', - 'clusterobjectsets', - `${operator.subscriptionName}-1`, - )) as Resource; + let objectSet: Resource; + if (await this.hasDeploymentAPI()) { + const deployment = (await this.client.getClusterCustomResource( + TARGET_GROUP, + 'v1', + 'clusterobjectdeployments', + operator.subscriptionName, + )) as Resource; + expect(deployment.metadata.labels?.['apps.kubernetes.io/managed-by']).toBe( + 'operator-controller', + ); + const revisions = (await this.client.customObjectsApi.listClusterCustomObject({ + group: TARGET_GROUP, + version: 'v1', + plural: 'clusterobjectsets', + })) as { items: Resource[] }; + // Archived handover revisions can be pruned by revisionHistoryLimit. + // Validate the current active revision controlled by this deployment. + const active = revisions.items + .filter( + (revision) => + !revision.metadata.deletionTimestamp && + revision.spec?.group === deployment.metadata.name && + revision.spec?.lifecycleState === 'Active' && + revision.metadata.ownerReferences?.some( + (owner) => + owner.apiVersion === `${TARGET_GROUP}/v1` && + owner.kind === 'ClusterObjectDeployment' && + owner.name === deployment.metadata.name && + owner.uid === deployment.metadata.uid && + owner.controller, + ), + ) + .sort((first, second) => (second.spec.revision ?? 0) - (first.spec.revision ?? 0)); + expect(active.length).toBeGreaterThan(0); + [objectSet] = active; + expect(objectSet.metadata.labels?.['apps.kubernetes.io/managed-by']).toBe( + 'object-controller', + ); + expect(objectSet.metadata.ownerReferences).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + kind: 'ClusterObjectDeployment', + name: deployment.metadata.name, + uid: deployment.metadata.uid, + controller: true, + }), + ]), + ); + } else { + objectSet = (await this.client.getClusterCustomResource( + TARGET_GROUP, + 'v1', + 'clusterobjectsets', + `${operator.subscriptionName}-1`, + )) as Resource; + } const ready = objectSet.status?.conditions?.find(({ type }) => type === 'Ready'); const succeeded = objectSet.status?.conditions?.find(({ type }) => type === 'Succeeded'); const available = objectSet.status?.conditions?.find(({ type }) => type === 'Available'); diff --git a/frontend/e2e/pages/details-page.ts b/frontend/e2e/pages/details-page.ts index e8943a41bbb..0e0a0b31b35 100644 --- a/frontend/e2e/pages/details-page.ts +++ b/frontend/e2e/pages/details-page.ts @@ -6,6 +6,10 @@ export class DetailsPage extends BasePage { private readonly pageHeading = this.page.getByTestId('page-heading'); private readonly resourceTitle = this.page.getByTestId('resource-title'); private readonly skeletonLoader = this.page.getByTestId('skeleton-detail-view'); + private readonly toastDismissButton = this.page + .getByTestId('toast-notifications') + .getByRole('button', { name: /^(Close|Minimize) / }) + .first(); readonly nodeTerminalError: Locator = this.page.getByTestId('node-terminal-error'); readonly xtermViewport: Locator = this.page.locator('.xterm-viewport'); @@ -37,7 +41,13 @@ export class DetailsPage extends BasePage { await this.goTo(url); } + /** Dismisses overlapping notifications before opening and selecting a details-page action. */ async clickPageAction(actionName: string): Promise { + // Persistent notifications can cover the details actions. Dismiss them + // before clicking so a forced click cannot hit a notification instead. + while (await this.toastDismissButton.isVisible()) { + await this.toastDismissButton.click(); + } await this.robustClick(this.page.getByTestId('actions-menu-button')); await this.robustClick(this.page.getByTestId(actionName)); } diff --git a/frontend/e2e/tests/olm/operator-migration.spec.ts b/frontend/e2e/tests/olm/operator-migration.spec.ts index 1ea5cf0e162..cca15eb0be0 100644 --- a/frontend/e2e/tests/olm/operator-migration.spec.ts +++ b/frontend/e2e/tests/olm/operator-migration.spec.ts @@ -69,10 +69,6 @@ const prepareInstalledTargetFailure = async ( }; test.describe('Operator migration', { tag: ['@techpreview'], lock: OLM_CLUSTER_STATE_LOCK }, () => { - test.skip( - true, - 'operator-controller#3126 made type required on revision objects; the pinned library-olm emits the old format and migrations roll back (library-olm#93 pending)', - ); test.setTimeout(900_000); test('migrates one operator after a read-only plan review and keeps its operand running', async ({ @@ -657,10 +653,6 @@ test.describe( 'Operator migration interruptions', { tag: ['@techpreview'], lock: OLM_CLUSTER_STATE_LOCK }, () => { - test.skip( - true, - 'operator-controller#3126 made type required on revision objects; the pinned library-olm emits the old format and migrations roll back (library-olm#93 pending)', - ); // Logout must not revoke the saved session shared by other workers. test.use({ storageState: { cookies: [], origins: [] } }); test.setTimeout(900_000); @@ -706,6 +698,9 @@ test.describe( await migrationPage.startMigration(); await migration.expectHeldMigration(first); await expect(migrationPage.getProgress()).toContainText('0 of 2 Operators processed'); + await expect(migrationPage.getStatus(second.packageName)).toContainText( + 'Migration in progress', + ); let returnedPage = migrationPage; let replacementBrowser: Browser | undefined; try { @@ -738,6 +733,10 @@ test.describe( } await expect(returnedPage.getProgress()).toBeVisible({ timeout: 90_000 }); await expect(returnedPage.getProgress()).toContainText('0 of 2 Operators processed'); + await returnedPage.navigateToOperators(); + await expect(returnedPage.getStatus(second.packageName)).toContainText( + 'Migration in progress', + ); await release(); for (const operator of [first, second]) { await expect(returnedPage.getResult(operator.subscriptionName)).toContainText( @@ -811,10 +810,6 @@ test.describe( 'Operator rollback interruptions', { tag: ['@techpreview'], lock: OLM_CLUSTER_STATE_LOCK }, () => { - test.skip( - true, - 'operator-controller#3126 made type required on revision objects; the pinned library-olm emits the old format and migrations roll back (library-olm#93 pending)', - ); // Logout must not revoke the saved session shared by other workers. test.use({ storageState: { cookies: [], origins: [] } }); test.setTimeout(900_000); diff --git a/frontend/packages/console-app/src/providers/toast/InternalToastProvider.tsx b/frontend/packages/console-app/src/providers/toast/InternalToastProvider.tsx index 15de89a0c5f..94eace8f1e7 100644 --- a/frontend/packages/console-app/src/providers/toast/InternalToastProvider.tsx +++ b/frontend/packages/console-app/src/providers/toast/InternalToastProvider.tsx @@ -243,6 +243,7 @@ export const InternalToastProvider: FC = ({ {children} {!isNotificationDrawerExpanded && toasts.length > 0 ? ( { const t = (key: string, values?: Record) => @@ -13,6 +13,7 @@ jest.mock('react-i18next', () => { }); jest.mock('../../status/csv-status', () => ({ subscriptionForCSV: jest.fn() })); +jest.mock('../operator-migration-notifications', () => ({ useMigrationNotifications: jest.fn() })); jest.mock('../../utils/operator-migration-api', () => ({ getOperatorMigrationScans: jest.fn(), OPERATOR_MIGRATION_SCAN_INVALIDATED_EVENT: 'test-migration-scans', @@ -29,7 +30,7 @@ const renderCell = () => { const [cell] = getOperatorMigrationEligibilityCell([ { obj: subscription, rowData: { subscriptions: [] }, activeColumnIDs: new Set(), index: 0 }, ]); - render(<>{isDataViewTdObject(cell) ? cell.cell : cell}); + render(<>{cell && typeof cell === 'object' && 'cell' in cell ? cell.cell : cell}); }; const mockScan = (scan: Partial) => { @@ -45,7 +46,33 @@ const mockScan = (scan: Partial) => { }; describe('OperatorMigrationEligibilityCell', () => { - beforeEach(() => jest.clearAllMocks()); + beforeEach(() => { + jest.clearAllMocks(); + (useMigrationNotifications as jest.Mock).mockReturnValue({ migratingOperators: new Set() }); + }); + + it('shows an active migration instead of stale eligibility', async () => { + mockScan({ status: 'Eligible', eligible: true }); + (useMigrationNotifications as jest.Mock).mockReturnValue({ + migratingOperators: new Set(['netobserv-operator/netobserv-operator']), + }); + renderCell(); + + expect(await screen.findByText('Migration in progress')).toBeVisible(); + expect(screen.queryByRole('button')).not.toBeInTheDocument(); + expect(screen.queryByText('Eligible')).not.toBeInTheDocument(); + }); + + it('does not use a migration for the same subscription name in another namespace', async () => { + mockScan({ status: 'Eligible', eligible: true }); + (useMigrationNotifications as jest.Mock).mockReturnValue({ + migratingOperators: new Set(['another-namespace/netobserv-operator']), + }); + renderCell(); + + expect(await screen.findByRole('button', { name: 'Migration status: Eligible' })).toBeVisible(); + expect(screen.queryByText('Migration in progress')).not.toBeInTheDocument(); + }); it.each([ { diff --git a/frontend/packages/operator-lifecycle-manager/src/components/__tests__/operator-migration-notifications.spec.tsx b/frontend/packages/operator-lifecycle-manager/src/components/__tests__/operator-migration-notifications.spec.tsx index 6ee681ec94d..27e77b0e9e5 100644 --- a/frontend/packages/operator-lifecycle-manager/src/components/__tests__/operator-migration-notifications.spec.tsx +++ b/frontend/packages/operator-lifecycle-manager/src/components/__tests__/operator-migration-notifications.spec.tsx @@ -1,15 +1,19 @@ -import { act, render, screen } from '@testing-library/react'; +import type { PropsWithChildren, ReactNode } from 'react'; +import { act, render, screen, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { useTranslation } from 'react-i18next'; import { InternalToastProvider } from '@console/app/src/providers/toast/InternalToastProvider'; import { OverlayProvider } from '@console/dynamic-plugin-sdk/src/app/modal-support/OverlayProvider'; import { HttpError } from '@console/dynamic-plugin-sdk/src/utils/error/http-error'; +import type { SubscriptionKind } from '../../types'; import type { OperatorMigrationJob } from '../../utils/operator-migration-api'; import { getOperatorMigrationJob, getOperatorMigrationJobs, + getOperatorMigrationScans, startOperatorMigrationRollback, } from '../../utils/operator-migration-api'; +import { getOperatorMigrationEligibilityCell } from '../operator-migration-eligibility'; import { OperatorMigrationNotificationsProvider, useOperatorMigrationNotifications, @@ -17,9 +21,12 @@ import { } from '../operator-migration-notifications'; jest.mock('react-i18next', () => ({ useTranslation: jest.fn() })); +jest.mock('../../status/csv-status', () => ({ subscriptionForCSV: jest.fn() })); jest.mock('../../utils/operator-migration-api', () => ({ getOperatorMigrationJob: jest.fn(), getOperatorMigrationJobs: jest.fn(), + getOperatorMigrationScans: jest.fn(), + OPERATOR_MIGRATION_SCAN_INVALIDATED_EVENT: 'test-migration-scans', invalidateOperatorMigrationScans: jest.fn(), startOperatorMigrationRollback: jest.fn(), })); @@ -47,24 +54,62 @@ const StartMigration = () => { ); }; -const Notifications = () => { +const Notifications = ({ children }: PropsWithChildren) => { const value = useOperatorMigrationNotifications(); return ( Console content + {children} ); }; -const renderNotifications = () => +const renderNotifications = (children?: ReactNode) => render( - + {children} , ); +const subscriptions: SubscriptionKind[] = [ + { name: 'demo', namespace: 'operators' }, + { name: 'second', namespace: 'operators' }, + { name: 'demo', namespace: 'another-namespace' }, +].map((metadata) => ({ + apiVersion: 'operators.coreos.com/v1alpha1', + kind: 'Subscription', + metadata, + spec: { name: metadata.name, source: 'fixture-catalog' }, +})); + +const MigrationStatusTable = () => { + const cells = getOperatorMigrationEligibilityCell( + subscriptions.map((obj, index) => ({ + obj, + rowData: { subscriptions }, + activeColumnIDs: new Set(), + index, + })), + ); + return ( + + + {cells.map((cell, index) => { + const { name, namespace } = subscriptions[index].metadata; + return ( + + + + + ); + })} + +
{`${namespace}/${name}`}{cell && typeof cell === 'object' && 'cell' in cell ? cell.cell : cell}
+ ); +}; + const translate = (key: string, values?: Record): string => key.replace(/{{(\w+)}}/g, (_, name: string) => String(values?.[name] ?? '')); @@ -75,9 +120,97 @@ describe('OperatorMigrationNotifications', () => { (useTranslation as jest.Mock).mockReturnValue({ t: translate }); (getOperatorMigrationJobs as jest.Mock).mockResolvedValue([running]); (getOperatorMigrationJob as jest.Mock).mockResolvedValue(running); + (getOperatorMigrationScans as jest.Mock).mockResolvedValue( + subscriptions.map(({ metadata }) => ({ + subscriptionName: metadata.name, + subscriptionNamespace: metadata.namespace, + status: 'Eligible', + eligible: true, + reason: '', + })), + ); }); afterEach(() => jest.useRealTimers()); + it('restores in-progress migration cells only for the matching subscription and namespace', async () => { + renderNotifications(); + + expect( + await within(screen.getByRole('row', { name: /^operators\/demo / })).findByText( + 'Migration in progress', + ), + ).toBeVisible(); + expect( + await within(screen.getByRole('row', { name: /^another-namespace\/demo / })).findByRole( + 'button', + { name: 'Migration status: Eligible' }, + ), + ).toBeVisible(); + expect( + within(screen.getByRole('row', { name: /^operators\/second / })).getByRole('button', { + name: 'Migration status: Eligible', + }), + ).toBeVisible(); + }); + + it('updates the migration cell as soon as a newly submitted job is monitored', async () => { + (getOperatorMigrationJobs as jest.Mock).mockResolvedValue([]); + renderNotifications(); + const row = within(screen.getByRole('row', { name: /^operators\/demo / })); + expect(await row.findByRole('button', { name: 'Migration status: Eligible' })).toBeVisible(); + const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }); + + await user.click(screen.getByRole('button', { name: 'Start migration' })); + + expect(await row.findByText('Migration in progress')).toBeVisible(); + expect(row.queryByRole('button')).not.toBeInTheDocument(); + }); + + it.each(['Succeeded', 'Failed', 'Skipped'])( + 'clears a %s operator while keeping the remaining batch operator in progress', + async (status) => { + const batch: OperatorMigrationJob = { + ...running, + items: [ + running.items[0], + { ...running.items[0], subscriptionName: 'second', status: 'Queued' }, + ], + }; + (getOperatorMigrationJobs as jest.Mock).mockResolvedValue([batch]); + (getOperatorMigrationJob as jest.Mock).mockResolvedValue(batch); + renderNotifications(); + expect(await screen.findAllByText('Migration in progress')).toHaveLength(2); + (getOperatorMigrationJob as jest.Mock).mockResolvedValue({ + ...batch, + items: [ + { ...batch.items[0], status }, + { ...batch.items[1], status: 'Migrating' }, + ], + }); + + await act(async () => jest.advanceTimersByTimeAsync(2000)); + + expect( + within(screen.getByRole('row', { name: /^operators\/demo / })).getByRole('button', { + name: 'Migration status: Eligible', + }), + ).toBeVisible(); + expect( + within(screen.getByRole('row', { name: /^operators\/second / })).getByText( + 'Migration in progress', + ), + ).toBeVisible(); + (getOperatorMigrationJob as jest.Mock).mockResolvedValue({ + ...batch, + status: 'Failed', + }); + + await act(async () => jest.advanceTimersByTimeAsync(2000)); + + expect(screen.queryByText('Migration in progress')).not.toBeInTheDocument(); + }, + ); + it('restores an active migration when Console mounts with no browser state', async () => { const { unmount } = renderNotifications(); expect(await screen.findByText('Operator migration in progress')).toBeVisible(); diff --git a/frontend/packages/operator-lifecycle-manager/src/components/modals/__tests__/operator-migration-plan.spec.tsx b/frontend/packages/operator-lifecycle-manager/src/components/modals/__tests__/operator-migration-plan.spec.tsx new file mode 100644 index 00000000000..6c156872982 --- /dev/null +++ b/frontend/packages/operator-lifecycle-manager/src/components/modals/__tests__/operator-migration-plan.spec.tsx @@ -0,0 +1,50 @@ +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { DASH } from '@console/shared/src/constants/ui'; +import type { OperatorMigrationPlan } from '../../../utils/operator-migration-api'; +import { MigrationPlanDetails } from '../operator-migration-plan'; + +jest.mock('react-i18next'); + +describe('Migration plan manager', () => { + it.each([ + { scenario: 'deployment', clusterObjectDeploymentName: 'deployment', expected: 'deployment' }, + { scenario: 'legacy revision', clusterObjectSetName: 'legacy-1', expected: 'legacy-1' }, + { + scenario: 'both manager fields', + clusterObjectDeploymentName: 'deployment', + clusterObjectSetName: 'legacy-1', + expected: 'deployment', + }, + { scenario: 'absent manager fields', expected: DASH }, + { + scenario: 'empty manager fields', + clusterObjectDeploymentName: '', + clusterObjectSetName: '', + expected: DASH, + }, + ])( + 'shows the manager or a placeholder with $scenario', + async ({ scenario, expected, ...manager }) => { + const user = userEvent.setup(); + const plan: OperatorMigrationPlan = { + packageName: 'operator', + version: '1.0.0', + clusterExtensionName: 'extension', + clusterCatalog: 'catalog', + installNamespace: 'operators', + channel: 'stable', + resources: [], + actions: [], + ...manager, + }; + render(); + + await user.click(screen.getByRole('button', { name: 'Migration plan for Operator' })); + + expect( + screen.getAllByRole('definition').map((definition) => definition.textContent), + ).toContain(expected); + }, + ); +}); diff --git a/frontend/packages/operator-lifecycle-manager/src/components/modals/operator-migration-plan.tsx b/frontend/packages/operator-lifecycle-manager/src/components/modals/operator-migration-plan.tsx index 55f04165103..3689b5b0a4e 100644 --- a/frontend/packages/operator-lifecycle-manager/src/components/modals/operator-migration-plan.tsx +++ b/frontend/packages/operator-lifecycle-manager/src/components/modals/operator-migration-plan.tsx @@ -120,8 +120,14 @@ export const MigrationPlanDetails: FC<{ plan: OperatorMigrationPlan; displayName {plan.clusterExtensionName} - {t('ClusterObjectSet')} - {plan.clusterObjectSetName} + + {plan.clusterObjectDeploymentName + ? t('ClusterObjectDeployment') + : t('ClusterObjectSet')} + + + {plan.clusterObjectDeploymentName || plan.clusterObjectSetName || DASH} + diff --git a/frontend/packages/operator-lifecycle-manager/src/components/operator-migration-eligibility.tsx b/frontend/packages/operator-lifecycle-manager/src/components/operator-migration-eligibility.tsx index a29d3b709c5..42ea1a53fcd 100644 --- a/frontend/packages/operator-lifecycle-manager/src/components/operator-migration-eligibility.tsx +++ b/frontend/packages/operator-lifecycle-manager/src/components/operator-migration-eligibility.tsx @@ -1,11 +1,12 @@ import type { FC, ReactElement } from 'react'; import { useEffect, useState } from 'react'; import { Status, IconStatus } from '@patternfly/react-component-groups/dist/dynamic/Status'; -import { Button, Content, Popover } from '@patternfly/react-core'; +import { Button, Content, Panel, PanelMain, Popover } from '@patternfly/react-core'; import { RhUiCheckCircleFillIcon, RhUiErrorFillIcon, RhUiInformationFillIcon, + RhUiInProgressIcon, } from '@patternfly/react-icons'; import { useTranslation } from 'react-i18next'; import type { GetDataViewCell } from '@console/dynamic-plugin-sdk/src/extensions/dataview'; @@ -17,6 +18,7 @@ import { OPERATOR_MIGRATION_SCAN_INVALIDATED_EVENT, type OperatorMigrationScan, } from '../utils/operator-migration-api'; +import { useMigrationNotifications } from './operator-migration-notifications'; type InstalledOperator = ClusterServiceVersionKind | SubscriptionKind; @@ -75,11 +77,24 @@ const OperatorMigrationEligibilityCell: FC<{ subscriptionNamespace: string; }> = ({ subscriptionName, subscriptionNamespace }) => { const { t } = useTranslation('olm'); + const { migratingOperators } = useMigrationNotifications(); const { scan, loading, error } = useOperatorMigrationScan( subscriptionNamespace, subscriptionName, ); + if (migratingOperators.has(`${subscriptionNamespace}/${subscriptionName}`)) { + return ( + + } + label={t('Migration in progress')} + /> + + ); + } + if (loading) { return {t('Scanning...')}; } @@ -141,18 +156,25 @@ const OperatorMigrationEligibilityCell: FC<{ aria-label={t('Migration status for {{operator}}', { operator: subscriptionName })} headerContent={statusText} bodyContent={ - <> - {summary} - {failedChecks.length > 0 && ( - - {failedChecks.map(({ name, message }) => ( - - {name}: {message} - - ))} - - )} - + + + {summary} + {failedChecks.length > 0 && ( + + {failedChecks.map(({ name, message }) => ( + + {name}: {message} + + ))} + + )} + + } >