Skip to content

Commit 842cb49

Browse files
refactor: split operator-commands.ts into focused modules with conditional COO setup
Split the monolithic operator-commands.ts (932 lines) into focused modules: - auth-commands.ts: expanded with operatorAuthUtils (RBAC, OAuth, session keys) - coo-install-commands.ts: COO install/uninstall/namespace lifecycle - image-patch-commands.ts: CSV image patching utilities - dashboards-commands.ts: Perses dashboards, troubleshooting panel, UIPlugin CR operator-commands.ts is now a slim orchestrator (~280 lines) that composes the above modules into Cypress commands. Added COOSetupOptions interface so callers can skip unnecessary setup steps: - dashboards (Perses dashboards, perses pod, health-analyzer ServiceMonitor) - troubleshootingPanel (korrel8r pod) - healthAnalyzer (CHA image patch) All incident tests now use { dashboards: false, troubleshootingPanel: false, healthAnalyzer: false } to skip Perses/korrel8r/CHA setup they don't need. The Monitoring UIPlugin CR creation is extracted into its own function and always runs, since it's required by all COO features including incidents. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8a5e42a commit 842cb49

15 files changed

Lines changed: 881 additions & 830 deletions

web/cypress/e2e/incidents/00.coo_incidents_e2e.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('BVT: Incidents - e2e', { tags: ['@smoke', '@slow', '@incidents'] }, ()
2525
let currentAlertName: string;
2626

2727
before(() => {
28-
cy.beforeBlockCOO(MCP, MP);
28+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
2929

3030
cy.cleanupIncidentPrometheusRules();
3131

web/cypress/e2e/incidents/01.incidents.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ALERT_DESC = 'This is an alert meant to ensure that the entire alerting pi
3333
const ALERT_SUMMARY = 'An alert that should always be firing to certify that Alertmanager is working properly.'
3434
describe('BVT: Incidents - UI', { tags: ['@smoke', '@incidents'] }, () => {
3535
before(() => {
36-
cy.beforeBlockCOO(MCP, MP);
36+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
3737
});
3838

3939

web/cypress/e2e/incidents/02.incidents-mocking-example.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MP = {
2929
describe('Incidents - Mocking Examples', { tags: ['@demo', '@incidents'] }, () => {
3030

3131
before(() => {
32-
cy.beforeBlockCOO(MCP, MP);
32+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
3333
});
3434

3535
beforeEach(() => {

web/cypress/e2e/incidents/regression/01.reg_filtering.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const MP = {
2828
describe('Regression: Incidents Filtering', { tags: ['@incidents'] }, () => {
2929

3030
before(() => {
31-
cy.beforeBlockCOO(MCP, MP);
31+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
3232
});
3333

3434
beforeEach(() => {

web/cypress/e2e/incidents/regression/02.reg_ui_charts_comprehensive.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const MP = {
8787
describe('Regression: Charts UI - Comprehensive', { tags: ['@incidents'] }, () => {
8888

8989
before(() => {
90-
cy.beforeBlockCOO(MCP, MP);
90+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
9191

9292
});
9393

web/cypress/e2e/incidents/regression/03-04.reg_e2e_firing_alerts.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Regression: Time-Based Alert Resolution (E2E with Firing Alerts)', { t
3737
let currentAlertName: string;
3838

3939
before(() => {
40-
cy.beforeBlockCOO(MCP, MP);
40+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
4141

4242
cy.log('Create or reuse firing alert for testing');
4343
cy.createKubePodCrashLoopingAlert('TimeBasedResolution2').then((alertName) => {

web/cypress/e2e/incidents/regression/03.reg_api_calls.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MP = {
2929
describe('Regression: Silences Not Applied Correctly', { tags: ['@incidents'] }, () => {
3030

3131
before(() => {
32-
cy.beforeBlockCOO(MCP, MP);
32+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
3333
});
3434

3535
beforeEach(() => {

web/cypress/e2e/incidents/regression/04.reg_redux_effects.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const MP = {
3333
describe('Regression: Redux State Management', { tags: ['@incidents', '@incidents-redux'] }, () => {
3434

3535
before(() => {
36-
cy.beforeBlockCOO(MCP, MP);
36+
cy.beforeBlockCOO(MCP, MP, { dashboards: false, troubleshootingPanel: false });
3737
});
3838

3939
beforeEach(() => {

web/cypress/support/commands/auth-commands.ts

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { nav } from '../../views/nav';
22
import { guidedTour } from '../../views/tour';
33

4-
5-
64
export { };
75
declare global {
86
namespace Cypress {
@@ -22,6 +20,138 @@ declare global {
2220
}
2321
}
2422

23+
// ── Auth orchestration (RBAC + OAuth discovery + login) ────────────
24+
// Moved from operator-commands.ts so all auth concerns live in one file.
25+
26+
export const operatorAuthUtils = {
27+
performLoginAndAuth(useSession: boolean): void {
28+
if (`${Cypress.env('LOGIN_USERNAME')}` === 'kubeadmin') {
29+
cy.adminCLI(
30+
`oc adm policy add-cluster-role-to-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
31+
);
32+
} else {
33+
cy.adminCLI(`oc project openshift-monitoring`);
34+
cy.adminCLI(
35+
`oc adm policy add-role-to-user monitoring-edit ${Cypress.env('LOGIN_USERNAME')} -n openshift-monitoring`,
36+
);
37+
cy.adminCLI(
38+
`oc adm policy add-role-to-user monitoring-alertmanager-edit --role-namespace openshift-monitoring ${Cypress.env('LOGIN_USERNAME')}`,
39+
);
40+
cy.adminCLI(
41+
`oc adm policy add-role-to-user view ${Cypress.env('LOGIN_USERNAME')} -n openshift-monitoring`,
42+
);
43+
cy.adminCLI(`oc project default`);
44+
cy.adminCLI(
45+
`oc adm policy add-role-to-user monitoring-edit ${Cypress.env('LOGIN_USERNAME')} -n default`,
46+
);
47+
cy.adminCLI(
48+
`oc adm policy add-role-to-user monitoring-alertmanager-edit --role-namespace default ${Cypress.env('LOGIN_USERNAME')}`,
49+
);
50+
cy.adminCLI(
51+
`oc adm policy add-role-to-user view ${Cypress.env('LOGIN_USERNAME')} -n default`,
52+
);
53+
}
54+
cy.exec(
55+
`oc get oauthclient openshift-browser-client -o go-template --template="{{index .redirectURIs 0}}" --kubeconfig ${Cypress.env('KUBECONFIG_PATH')}`,
56+
).then((result) => {
57+
if (result.stderr === '') {
58+
const oauth = result.stdout;
59+
const oauthurl = new URL(oauth);
60+
const oauthorigin = oauthurl.origin;
61+
cy.log(oauthorigin);
62+
cy.wrap(oauthorigin as string).as('oauthorigin');
63+
} else {
64+
throw new Error(`Execution of oc get oauthclient failed
65+
Exit code: ${result.code}
66+
Stdout:\n${result.stdout}
67+
Stderr:\n${result.stderr}`);
68+
}
69+
});
70+
cy.get('@oauthorigin').then((oauthorigin) => {
71+
if (useSession) {
72+
cy.login(
73+
Cypress.env('LOGIN_IDP'),
74+
Cypress.env('LOGIN_USERNAME'),
75+
Cypress.env('LOGIN_PASSWORD'),
76+
oauthorigin as unknown as string,
77+
);
78+
} else {
79+
cy.loginNoSession(
80+
Cypress.env('LOGIN_IDP'),
81+
Cypress.env('LOGIN_USERNAME'),
82+
Cypress.env('LOGIN_PASSWORD'),
83+
oauthorigin as unknown as string,
84+
);
85+
}
86+
});
87+
},
88+
89+
loginAndAuth(): void {
90+
cy.log('Before block');
91+
operatorAuthUtils.performLoginAndAuth(true);
92+
},
93+
94+
loginAndAuthNoSession(): void {
95+
cy.log('Before block (no session)');
96+
operatorAuthUtils.performLoginAndAuth(false);
97+
},
98+
99+
generateCOOSessionKey(
100+
MCP: { namespace: string; operatorName: string; packageName: string },
101+
MP: { namespace: string; operatorName: string },
102+
): string[] {
103+
const baseKey = [
104+
Cypress.env('LOGIN_IDP'),
105+
Cypress.env('LOGIN_USERNAME'),
106+
MCP.namespace,
107+
MCP.operatorName,
108+
MCP.packageName,
109+
MP.namespace,
110+
MP.operatorName,
111+
];
112+
const envVars = [
113+
Cypress.env('SKIP_ALL_INSTALL'),
114+
Cypress.env('SKIP_COO_INSTALL'),
115+
Cypress.env('COO_UI_INSTALL'),
116+
Cypress.env('KONFLUX_COO_BUNDLE_IMAGE'),
117+
Cypress.env('CUSTOM_COO_BUNDLE_IMAGE'),
118+
Cypress.env('FBC_STAGE_COO_IMAGE'),
119+
Cypress.env('MP_IMAGE'),
120+
Cypress.env('MCP_CONSOLE_IMAGE'),
121+
Cypress.env('CHA_IMAGE'),
122+
];
123+
return [...baseKey, ...envVars.filter(Boolean)];
124+
},
125+
126+
generateMPSessionKey(MP: { namespace: string; operatorName: string }): string[] {
127+
const baseKey = [
128+
Cypress.env('LOGIN_IDP'),
129+
Cypress.env('LOGIN_USERNAME'),
130+
MP.namespace,
131+
MP.operatorName,
132+
];
133+
const envVars = [
134+
Cypress.env('SKIP_ALL_INSTALL'),
135+
Cypress.env('MP_IMAGE'),
136+
];
137+
return [...baseKey, ...envVars.filter(Boolean)];
138+
},
139+
140+
generateKBVSessionKey(KBV: { namespace: string; packageName: string }): string[] {
141+
const baseKey = [
142+
Cypress.env('LOGIN_IDP'),
143+
Cypress.env('LOGIN_USERNAME'),
144+
KBV.namespace,
145+
KBV.packageName,
146+
];
147+
const envVars = [
148+
Cypress.env('SKIP_KBV_INSTALL'),
149+
Cypress.env('KBV_UI_INSTALL'),
150+
];
151+
return [...baseKey, ...envVars.filter(Boolean)];
152+
},
153+
};
154+
25155

26156
// Core login function (used by both session and non-session versions)
27157
function performLogin(

0 commit comments

Comments
 (0)