-
Notifications
You must be signed in to change notification settings - Fork 735
CONSOLE-5409: Add Playwright e2e test for operator lifecycle metadata UI #16701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
perdasilva
wants to merge
1
commit into
openshift:main
Choose a base branch
from
perdasilva:operator-lifecycle-metadata-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| export type LifecycleData = { | ||
| package: string; | ||
| schema: string; | ||
| versions?: { | ||
| name: string; | ||
| platformCompatibility?: { name: string; versions: string[] }[]; | ||
| phases?: { name: string; startDate: string; endDate: string }[]; | ||
| }[]; | ||
| }; | ||
|
|
||
| const LIFECYCLE_SCHEMA = 'io.openshift.operators.lifecycles.v1alpha1'; | ||
|
|
||
| const toDateStr = (d: Date): string => d.toISOString().slice(0, 10); | ||
|
|
||
| const activePhases = (): { name: string; startDate: string; endDate: string }[] => { | ||
| const now = new Date(); | ||
| const maintenanceStart = new Date(now.getFullYear() - 1, 0, 1); | ||
| const maintenanceEnd = new Date(now.getFullYear() + 1, 5, 30); | ||
| const extendedStart = new Date(maintenanceEnd); | ||
| extendedStart.setDate(extendedStart.getDate() + 1); | ||
| const extendedEnd = new Date(now.getFullYear() + 3, 11, 31); | ||
| return [ | ||
| { name: 'Maintenance support', startDate: toDateStr(maintenanceStart), endDate: toDateStr(maintenanceEnd) }, | ||
| { name: 'Extended life cycle support', startDate: toDateStr(extendedStart), endDate: toDateStr(extendedEnd) }, | ||
| ]; | ||
| }; | ||
|
|
||
| const expiredPhases = (): { name: string; startDate: string; endDate: string }[] => { | ||
| const now = new Date(); | ||
| const maintenanceStart = new Date(now.getFullYear() - 3, 0, 1); | ||
| const maintenanceEnd = new Date(now.getFullYear() - 2, 5, 30); | ||
| const extendedStart = new Date(maintenanceEnd); | ||
| extendedStart.setDate(extendedStart.getDate() + 1); | ||
| const extendedEnd = new Date(now.getFullYear() - 1, 11, 31); | ||
| return [ | ||
| { name: 'Maintenance support', startDate: toDateStr(maintenanceStart), endDate: toDateStr(maintenanceEnd) }, | ||
| { name: 'Extended life cycle support', startDate: toDateStr(extendedStart), endDate: toDateStr(extendedEnd) }, | ||
| ]; | ||
| }; | ||
|
|
||
| export const makeLifecycleActiveAndCompatible = ( | ||
| packageName: string, | ||
| version: string, | ||
| clusterVersion: string, | ||
| ): LifecycleData => ({ | ||
| package: packageName, | ||
| schema: LIFECYCLE_SCHEMA, | ||
| versions: [ | ||
| { | ||
| name: version, | ||
| platformCompatibility: [{ name: 'openshift', versions: [clusterVersion] }], | ||
| phases: activePhases(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export const makeLifecycleSelfSupport = ( | ||
| packageName: string, | ||
| version: string, | ||
| clusterVersion: string, | ||
| ): LifecycleData => ({ | ||
| package: packageName, | ||
| schema: LIFECYCLE_SCHEMA, | ||
| versions: [ | ||
| { | ||
| name: version, | ||
| platformCompatibility: [{ name: 'openshift', versions: [clusterVersion] }], | ||
| phases: expiredPhases(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export const makeLifecycleIncompatible = ( | ||
| packageName: string, | ||
| version: string, | ||
| ): LifecycleData => ({ | ||
| package: packageName, | ||
| schema: LIFECYCLE_SCHEMA, | ||
| versions: [ | ||
| { | ||
| name: version, | ||
| platformCompatibility: [{ name: 'openshift', versions: ['4.99'] }], | ||
| phases: activePhases(), | ||
| }, | ||
| ], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { Locator } from '@playwright/test'; | ||
|
|
||
| import BasePage from './base-page'; | ||
|
|
||
| export class InstalledOperatorsPage extends BasePage { | ||
| async navigateTo(namespace?: string): Promise<void> { | ||
| const path = namespace | ||
| ? `/k8s/ns/${namespace}/operators.coreos.com~v1alpha1~ClusterServiceVersion` | ||
| : `/k8s/all-namespaces/operators.coreos.com~v1alpha1~ClusterServiceVersion`; | ||
| await this.goTo(path); | ||
| } | ||
|
|
||
| getOperatorRow(displayName: string): Locator { | ||
| return this.page | ||
| .locator('tr') | ||
| .filter({ has: this.page.getByTestId(`operator-row-${displayName}`) }); | ||
| } | ||
|
|
||
| getCompatibleIndicator(displayName: string): Locator { | ||
| return this.getOperatorRow(displayName).getByTestId('cluster-compatibility-compatible'); | ||
| } | ||
|
|
||
| getIncompatibleIndicator(displayName: string): Locator { | ||
| return this.getOperatorRow(displayName).getByTestId('cluster-compatibility-incompatible'); | ||
| } | ||
|
|
||
| getSupportPhaseBadge(displayName: string): Locator { | ||
| return this.getOperatorRow(displayName).getByTestId('support-phase-badge'); | ||
| } | ||
|
|
||
| getSelfSupportBadge(displayName: string): Locator { | ||
| return this.getOperatorRow(displayName).getByTestId('support-phase-self-support'); | ||
| } | ||
| } |
217 changes: 217 additions & 0 deletions
217
frontend/e2e/tests/olm/operator-lifecycle-metadata.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| import { test, expect } from '../../fixtures'; | ||
| import type { LifecycleData } from '../../mocks/operator-lifecycle'; | ||
| import { | ||
| makeLifecycleActiveAndCompatible, | ||
| makeLifecycleSelfSupport, | ||
| makeLifecycleIncompatible, | ||
| } from '../../mocks/operator-lifecycle'; | ||
| import { InstalledOperatorsPage } from '../../pages/installed-operators-page'; | ||
|
|
||
| const OLM_GROUP = 'operators.coreos.com'; | ||
| const OLM_VERSION = 'v1alpha1'; | ||
| const OPERATOR_NAMESPACE = 'openshift-operators'; | ||
| const PACKAGE_NAME = 'web-terminal'; | ||
| const CSV_NAME_PREFIX = `${PACKAGE_NAME}.v`; | ||
| const CATALOG_SOURCE = 'redhat-operators'; | ||
| const CATALOG_NAMESPACE = 'openshift-marketplace'; | ||
| const LIFECYCLE_URL_PATTERN = '**/api/olm/lifecycle/**'; | ||
|
|
||
| const INSTALL_TIMEOUT = 300_000; | ||
| const POLL_INTERVAL = 10_000; | ||
|
|
||
| type CSVResource = { | ||
| metadata?: { name?: string }; | ||
| spec?: { version?: string; displayName?: string }; | ||
| status?: { phase?: string }; | ||
| }; | ||
|
|
||
| const webTerminalSubscription = { | ||
| apiVersion: `${OLM_GROUP}/${OLM_VERSION}`, | ||
| kind: 'Subscription', | ||
| metadata: { | ||
| name: PACKAGE_NAME, | ||
| namespace: OPERATOR_NAMESPACE, | ||
| }, | ||
| spec: { | ||
| channel: 'fast', | ||
| name: PACKAGE_NAME, | ||
| source: CATALOG_SOURCE, | ||
| sourceNamespace: CATALOG_NAMESPACE, | ||
| installPlanApproval: 'Automatic', | ||
| }, | ||
| }; | ||
|
|
||
| test.describe('Operator lifecycle metadata', { tag: ['@admin'] }, () => { | ||
| let operatorVersion: string; | ||
| let operatorDisplayName: string; | ||
|
|
||
| test.beforeAll(async ({ k8sClient }) => { | ||
| test.setTimeout(INSTALL_TIMEOUT + 60_000); | ||
|
|
||
| try { | ||
| await k8sClient.createCustomResource( | ||
| OLM_GROUP, | ||
| OLM_VERSION, | ||
| OPERATOR_NAMESPACE, | ||
| 'subscriptions', | ||
| webTerminalSubscription, | ||
| ); | ||
| } catch (err) { | ||
| const msg = err instanceof Error ? err.message : String(err); | ||
| if (!msg.includes('409') && !msg.includes('already exists')) { | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| const deadline = Date.now() + INSTALL_TIMEOUT; | ||
| let csv: CSVResource | undefined; | ||
| while (Date.now() < deadline) { | ||
| try { | ||
| const sub = (await k8sClient.getCustomResource( | ||
| OLM_GROUP, | ||
| OLM_VERSION, | ||
| OPERATOR_NAMESPACE, | ||
| 'subscriptions', | ||
| PACKAGE_NAME, | ||
| )) as { status?: { installedCSV?: string } }; | ||
|
|
||
| const csvName = sub?.status?.installedCSV; | ||
| if (csvName) { | ||
| const csvResource = (await k8sClient.getCustomResource( | ||
| OLM_GROUP, | ||
| OLM_VERSION, | ||
| OPERATOR_NAMESPACE, | ||
| 'clusterserviceversions', | ||
| csvName, | ||
| )) as CSVResource; | ||
|
|
||
| if (csvResource?.status?.phase === 'Succeeded') { | ||
| csv = csvResource; | ||
| break; | ||
| } | ||
| } | ||
| } catch { | ||
| // subscription or CSV not ready yet | ||
| } | ||
| await new Promise((r) => setTimeout(r, POLL_INTERVAL)); | ||
| } | ||
|
TheRealJon marked this conversation as resolved.
|
||
|
|
||
| if (!csv) { | ||
| throw new Error( | ||
| `Timed out waiting for ${PACKAGE_NAME} CSV to reach Succeeded phase`, | ||
| ); | ||
| } | ||
|
|
||
| operatorVersion = csv.spec?.version ?? ''; | ||
| operatorDisplayName = csv.spec?.displayName ?? PACKAGE_NAME; | ||
| }); | ||
|
|
||
| test.afterAll(async ({ k8sClient }) => { | ||
|
TheRealJon marked this conversation as resolved.
|
||
| const csvs = (await k8sClient.listCustomResources( | ||
| OLM_GROUP, | ||
| OLM_VERSION, | ||
| OPERATOR_NAMESPACE, | ||
| 'clusterserviceversions', | ||
| )) as CSVResource[]; | ||
|
|
||
| await Promise.allSettled([ | ||
| k8sClient.deleteCustomResource( | ||
| OLM_GROUP, | ||
| OLM_VERSION, | ||
| OPERATOR_NAMESPACE, | ||
| 'subscriptions', | ||
| PACKAGE_NAME, | ||
| ), | ||
| ...csvs | ||
| .filter((c) => c.metadata?.name?.startsWith(CSV_NAME_PREFIX)) | ||
| .map((c) => | ||
| k8sClient.deleteCustomResource( | ||
| OLM_GROUP, | ||
| OLM_VERSION, | ||
| OPERATOR_NAMESPACE, | ||
| 'clusterserviceversions', | ||
| c.metadata!.name!, | ||
| ), | ||
| ), | ||
| ]); | ||
| }); | ||
|
|
||
| test('displays lifecycle metadata columns for installed operator', async ({ page }) => { | ||
| let activeLifecycleData: LifecycleData | null = null; | ||
|
|
||
| await page.route(LIFECYCLE_URL_PATTERN, async (route) => { | ||
| if (activeLifecycleData) { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify(activeLifecycleData), | ||
| }); | ||
| } else { | ||
| await route.abort(); | ||
| } | ||
| }); | ||
|
|
||
| const installedOperators = new InstalledOperatorsPage(page); | ||
| await installedOperators.navigateTo(OPERATOR_NAMESPACE); | ||
|
|
||
| const serverFlags = await page.evaluate(() => window.SERVER_FLAGS); | ||
| test.skip( | ||
| !serverFlags.olmLifecycleMetadata, | ||
| 'Lifecycle metadata columns require the OLMLifecycleAndCompatibility feature gate', | ||
| ); | ||
| const releaseVersion = serverFlags.releaseVersion ?? ''; | ||
| const versionMatch = releaseVersion.match(/^(\d+\.\d+)/); | ||
| const clusterMinorVersion = versionMatch ? versionMatch[1] : '4.18'; | ||
|
|
||
| await test.step('Active support phase and compatible cluster', async () => { | ||
| activeLifecycleData = makeLifecycleActiveAndCompatible( | ||
| PACKAGE_NAME, | ||
| operatorVersion, | ||
| clusterMinorVersion, | ||
| ); | ||
|
|
||
| await page.reload(); | ||
| await expect( | ||
| installedOperators.getOperatorRow(operatorDisplayName), | ||
| ).toBeVisible({ timeout: 30_000 }); | ||
|
|
||
| await expect( | ||
| installedOperators.getCompatibleIndicator(operatorDisplayName), | ||
| ).toContainText('Compatible', { timeout: 30_000 }); | ||
|
|
||
| await expect( | ||
| installedOperators.getSupportPhaseBadge(operatorDisplayName), | ||
| ).toContainText('Maintenance support'); | ||
| }); | ||
|
|
||
| await test.step('Unsupported when all phases expired', async () => { | ||
| activeLifecycleData = makeLifecycleSelfSupport( | ||
| PACKAGE_NAME, | ||
| operatorVersion, | ||
| clusterMinorVersion, | ||
| ); | ||
|
|
||
| await page.reload(); | ||
| await expect( | ||
| installedOperators.getOperatorRow(operatorDisplayName), | ||
| ).toBeVisible({ timeout: 30_000 }); | ||
|
|
||
| await expect( | ||
| installedOperators.getSelfSupportBadge(operatorDisplayName), | ||
| ).toContainText('Unsupported', { timeout: 30_000 }); | ||
| }); | ||
|
|
||
| await test.step('Incompatible when cluster version not in compatibility list', async () => { | ||
| activeLifecycleData = makeLifecycleIncompatible(PACKAGE_NAME, operatorVersion); | ||
|
|
||
| await page.reload(); | ||
| await expect( | ||
| installedOperators.getOperatorRow(operatorDisplayName), | ||
| ).toBeVisible({ timeout: 30_000 }); | ||
|
|
||
| await expect( | ||
| installedOperators.getIncompatibleIndicator(operatorDisplayName), | ||
| ).toContainText('Incompatible', { timeout: 30_000 }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,47 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Prow / CI entrypoint for Playwright E2E tech-preview tests against a live OpenShift cluster. | ||
| # Runs the operator lifecycle metadata test suite, which requires the OLMLifecycleAndCompatibility | ||
| # feature gate to be enabled on the cluster. | ||
| # | ||
| # Run from the openshift/console repository root. | ||
| # | ||
| # Environment (typical Prow / installer): | ||
| # ARTIFACT_DIR, INSTALLER_DIR, KUBEADMIN_PASSWORD_FILE same as test-prow-e2e.sh | ||
| # | ||
|
|
||
| set -exuo pipefail | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| cd "${REPO_ROOT}" | ||
|
|
||
| ARTIFACT_DIR=${ARTIFACT_DIR:-/tmp/artifacts} | ||
| INSTALLER_DIR=${INSTALLER_DIR:=${ARTIFACT_DIR}/installer} | ||
|
|
||
| # Validate ARTIFACT_DIR is set and is an absolute path | ||
| if [ -z "$ARTIFACT_DIR" ]; then | ||
| echo "Error: ARTIFACT_DIR is not set" >&2 | ||
| exit 1 | ||
| fi | ||
| case "$ARTIFACT_DIR" in | ||
| /) echo "Error: ARTIFACT_DIR must not be '/'" >&2; exit 1 ;; | ||
| /*) ;; # absolute path, OK | ||
| *) echo "Error: ARTIFACT_DIR must be an absolute path, got: $ARTIFACT_DIR" >&2; exit 1 ;; | ||
| esac | ||
|
|
||
| export ARTIFACT_DIR INSTALLER_DIR | ||
| mkdir -p "${ARTIFACT_DIR}" | ||
|
|
||
| # don't log kubeadmin-password | ||
| set +x | ||
| export BRIDGE_KUBEADMIN_PASSWORD="$(cat "${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/auth/kubeadmin-password}")" | ||
| set -x | ||
| export BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}')" | ||
|
|
||
| ./contrib/create-user.sh | ||
|
|
||
| pushd frontend | ||
|
|
||
| ./integration-tests/test-playwright-e2e.sh -- --project=olm e2e/tests/olm/operator-lifecycle-metadata.spec.ts "$@" | ||
|
|
||
| popd |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.