Skip to content

Commit b807480

Browse files
Merge pull request #720 from DavidRajnoha/cypress-csv-patch-cluster-health-analyzer
OBSINTA-1062: custom cluster-health-analyzer builds
2 parents bfdd3e2 + c8d6f72 commit b807480

5 files changed

Lines changed: 124 additions & 12 deletions

File tree

web/cypress/README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Creates `export-env.sh` that you can source later: `source export-env.sh`
7575
|----------|-------------|----------|
7676
| `CYPRESS_MP_IMAGE` | Custom Monitoring Plugin image | Testing custom MP builds |
7777
| `CYPRESS_MCP_CONSOLE_IMAGE` | Custom Monitoring Console Plugin image | Testing custom MCP builds |
78+
| `CYPRESS_CHA_IMAGE` | Custom cluster-health-analyzer image | Testing custom CHA builds |
7879

7980
### Operator Installation Control
8081

@@ -160,7 +161,25 @@ export CYPRESS_MP_IMAGE=quay.io/myorg/monitoring-plugin:my-branch
160161
export CYPRESS_MCP_CONSOLE_IMAGE=quay.io/myorg/monitoring-console-plugin:my-branch
161162
```
162163

163-
### Example 4: Pre-Provisioned Cluster (Skip Installations)
164+
### Example 4: Testing Custom cluster-health-analyzer Build
165+
166+
For CI jobs testing PRs to cluster-health-analyzer:
167+
168+
```bash
169+
# Required variables
170+
export CYPRESS_BASE_URL=https://...
171+
export CYPRESS_LOGIN_IDP=flexy-htpasswd-provider
172+
export CYPRESS_LOGIN_USERS=username:password
173+
export CYPRESS_KUBECONFIG_PATH=~/Downloads/kubeconfig
174+
175+
# Custom cluster-health-analyzer image built from PR
176+
export CYPRESS_CHA_IMAGE=quay.io/myorg/cluster-health-analyzer:pr-123
177+
178+
# Use COO bundle (required for incidents feature testing)
179+
export CYPRESS_KONFLUX_COO_BUNDLE_IMAGE=quay.io/rhobs/observability-operator-bundle:latest
180+
```
181+
182+
### Example 5: Pre-Provisioned Cluster (Skip Installations)
164183

165184
```bash
166185
# Required variables
@@ -173,14 +192,14 @@ export CYPRESS_KUBECONFIG_PATH=~/Downloads/kubeconfig
173192
export CYPRESS_SKIP_ALL_INSTALL=true
174193
```
175194

176-
### Example 5: Configurable COO Namespace
195+
### Example 6: Configurable COO Namespace
177196

178197
Set the following var to specify the Cluster Observability Operator namespace. Defaults to `openshift-cluster-observability-operator` if not set. This is useful when testing with different namespace configurations (e.g., using `coo` instead of the default).
179198
```bash
180199
export CYPRESS_COO_NAMESPACE=openshift-cluster-observability-operator
181200
```
182201

183-
### Example 6: Debug Mode
202+
### Example 7: Debug Mode
184203

185204
```bash
186205
# Required variables + debug

web/cypress/configure-env.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ print_current_config() {
175175
print_var "CYPRESS_KONFLUX_COO_BUNDLE_IMAGE" "${CYPRESS_KONFLUX_COO_BUNDLE_IMAGE-}"
176176
print_var "CYPRESS_CUSTOM_COO_BUNDLE_IMAGE" "${CYPRESS_CUSTOM_COO_BUNDLE_IMAGE-}"
177177
print_var "CYPRESS_MCP_CONSOLE_IMAGE" "${CYPRESS_MCP_CONSOLE_IMAGE-}"
178+
print_var "CYPRESS_CHA_IMAGE" "${CYPRESS_CHA_IMAGE-}"
178179
print_var "CYPRESS_TIMEZONE" "${CYPRESS_TIMEZONE-}"
179180
print_var "CYPRESS_MOCK_NEW_METRICS" "${CYPRESS_MOCK_NEW_METRICS-}"
180181
print_var "CYPRESS_SESSION" "${CYPRESS_SESSION-}"
@@ -226,6 +227,7 @@ main() {
226227
local def_konflux_bundle=${CYPRESS_KONFLUX_COO_BUNDLE_IMAGE-}
227228
local def_custom_coo_bundle=${CYPRESS_CUSTOM_COO_BUNDLE_IMAGE-}
228229
local def_mcp_console_image=${CYPRESS_MCP_CONSOLE_IMAGE-}
230+
local def_cha_image=${CYPRESS_CHA_IMAGE-}
229231
local def_timezone=${CYPRESS_TIMEZONE-}
230232
local def_mock_new_metrics=${CYPRESS_MOCK_NEW_METRICS-}
231233
local def_session=${CYPRESS_SESSION-}
@@ -434,6 +436,9 @@ main() {
434436
local mcp_console_image
435437
mcp_console_image=$(ask "Monitoring Console Plugin UI image (CYPRESS_MCP_CONSOLE_IMAGE)" "$def_mcp_console_image")
436438

439+
local cha_image
440+
cha_image=$(ask "Cluster Health Analyzer image (CYPRESS_CHA_IMAGE)" "$def_cha_image")
441+
437442
local timezone
438443
timezone=$(ask "Cluster timezone (CYPRESS_TIMEZONE)" "${def_timezone:-UTC}")
439444

@@ -500,6 +505,9 @@ main() {
500505
if [[ -n "$mcp_console_image" ]]; then
501506
export_lines+=("export CYPRESS_MCP_CONSOLE_IMAGE='$(printf %s "$mcp_console_image" | escape_for_single_quotes)'" )
502507
fi
508+
if [[ -n "$cha_image" ]]; then
509+
export_lines+=("export CYPRESS_CHA_IMAGE='$(printf %s "$cha_image" | escape_for_single_quotes)'" )
510+
fi
503511
if [[ -n "$timezone" ]]; then
504512
export_lines+=("export CYPRESS_TIMEZONE='$(printf %s "$timezone" | escape_for_single_quotes)'" )
505513
fi
@@ -553,6 +561,7 @@ main() {
553561
[[ -n "$konflux_bundle" ]] && echo " CYPRESS_KONFLUX_COO_BUNDLE_IMAGE=$konflux_bundle"
554562
[[ -n "$custom_coo_bundle" ]] && echo " CYPRESS_CUSTOM_COO_BUNDLE_IMAGE=$custom_coo_bundle"
555563
[[ -n "$mcp_console_image" ]] && echo " CYPRESS_MCP_CONSOLE_IMAGE=$mcp_console_image"
564+
[[ -n "$cha_image" ]] && echo " CYPRESS_CHA_IMAGE=$cha_image"
556565
[[ -n "$timezone" ]] && echo " CYPRESS_TIMEZONE=$timezone"
557566
echo " CYPRESS_MOCK_NEW_METRICS=$mock_new_metrics"
558567
echo " CYPRESS_SESSION=$session"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Script to patch the cluster-health-analyzer image in COO CSV
4+
# Used by Cypress tests to test custom CHA builds
5+
6+
echo "--------------------------------"
7+
echo "CHA_IMAGE: ${CHA_IMAGE}"
8+
echo "--------------------------------"
9+
10+
# Generate a random filename
11+
RANDOM_FILE="/tmp/coo_cha_csv_$(date +%s%N).yaml"
12+
13+
COO_CSV_NAME=$(oc get csv --kubeconfig "${KUBECONFIG}" --namespace="${MCP_NAMESPACE}" | grep "cluster-observability-operator" | awk '{print $1}')
14+
15+
if [ -z "${COO_CSV_NAME}" ]; then
16+
echo "Error: Could not find cluster-observability-operator CSV in namespace ${MCP_NAMESPACE}"
17+
exit 1
18+
fi
19+
20+
echo "Found COO CSV: ${COO_CSV_NAME}"
21+
22+
oc get csv "${COO_CSV_NAME}" -n "${MCP_NAMESPACE}" -o yaml > "${RANDOM_FILE}" --kubeconfig "${KUBECONFIG}"
23+
24+
# Patch the CSV file env vars for cluster-health-analyzer
25+
# Handle both US and UK spellings (analyser/analyzer) for compatibility
26+
sed -i "s#value: .*cluster-health-analy[sz]er.*#value: ${CHA_IMAGE}#g" "${RANDOM_FILE}"
27+
28+
# Patch the CSV file related images
29+
sed -i "s#^\([[:space:]]*- image:\).*cluster-health-analy[sz]er.*#\1 ${CHA_IMAGE}#g" "${RANDOM_FILE}"
30+
31+
# Apply the patched CSV resource file
32+
oc replace -f "${RANDOM_FILE}" --kubeconfig "${KUBECONFIG}"
33+
34+
# Wait for the operator to reconcile the change
35+
sleep 25
36+
37+
# Wait for health-analyzer pod to be ready with the new image
38+
OUTPUT=$(oc wait --for=condition=ready pods -l app.kubernetes.io/instance=health-analyzer -n "${MCP_NAMESPACE}" --timeout=120s --kubeconfig "${KUBECONFIG}")
39+
echo "${OUTPUT}"
40+
41+
echo "--------------------------------"
42+
echo "Health-analyzer pod status:"
43+
echo "--------------------------------"
44+
oc get pods -l app.kubernetes.io/instance=health-analyzer -n "${MCP_NAMESPACE}" -o wide --kubeconfig "${KUBECONFIG}"
45+
echo "--------------------------------"
46+

web/cypress/fixtures/export.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export CYPRESS_FBC_STAGE_COO_IMAGE=<COO FBC image>
3636
# Set the following var to use custom Monitoring Console Plugin UI plugin image. The image will be patched in Cluster Observability Operator CSV.
3737
export CYPRESS_MCP_CONSOLE_IMAGE=<Monitoring Console Plugin image>
3838

39+
# Set the following var to use custom cluster-health-analyzer image. The image will be patched in Cluster Observability Operator CSV.
40+
export CYPRESS_CHA_IMAGE=<cluster-health-analyzer image>
41+
3942
# Set the following var to specify the cluster timezone for incident timeline calculations. Defaults to UTC if not specified.
4043
export CYPRESS_TIMEZONE=<timezone>
4144

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export const operatorAuthUtils = {
135135
Cypress.env('CUSTOM_COO_BUNDLE_IMAGE'),
136136
Cypress.env('FBC_STAGE_COO_IMAGE'),
137137
Cypress.env('MP_IMAGE'),
138-
Cypress.env('MCP_CONSOLE_IMAGE')
138+
Cypress.env('MCP_CONSOLE_IMAGE'),
139+
Cypress.env('CHA_IMAGE')
139140
];
140141

141142
return [...baseKey, ...envVars.filter(Boolean)];
@@ -309,15 +310,32 @@ const operatorUtils = {
309310
cy.get('[data-test="status-text"]', { timeout: installTimeoutMilliseconds }).eq(0).should('contain.text', 'Succeeded', { timeout: installTimeoutMilliseconds });
310311
},
311312

312-
setupMonitoringConsolePlugin(MCP: { namespace: string }): void {
313-
cy.log('Set Monitoring Console Plugin image in operator CSV');
314-
if (Cypress.env('MCP_CONSOLE_IMAGE')) {
315-
cy.log('MCP_CONSOLE_IMAGE is set. the image will be patched in COO operator CSV');
313+
/**
314+
* Generic function to patch a component image in the COO CSV
315+
* @param MCP - The MCP namespace configuration
316+
* @param config - Configuration for the image patch
317+
* @param config.envVar - The Cypress environment variable name (also used as the shell script env var)
318+
* @param config.scriptPath - Path to the shell script that performs the patch
319+
* @param config.componentName - Human-readable name for logging
320+
*/
321+
patchCOOCSVImage(
322+
MCP: { namespace: string },
323+
config: {
324+
envVar: string;
325+
scriptPath: string;
326+
componentName: string;
327+
}
328+
): void {
329+
const imageValue = Cypress.env(config.envVar);
330+
cy.log(`Set ${config.componentName} image in operator CSV`);
331+
332+
if (imageValue) {
333+
cy.log(`${config.envVar} is set. The image will be patched in COO operator CSV`);
316334
cy.exec(
317-
'./cypress/fixtures/coo/update-mcp-image.sh',
335+
config.scriptPath,
318336
{
319337
env: {
320-
MCP_CONSOLE_IMAGE: Cypress.env('MCP_CONSOLE_IMAGE'),
338+
[config.envVar]: imageValue,
321339
KUBECONFIG: Cypress.env('KUBECONFIG_PATH'),
322340
MCP_NAMESPACE: `${MCP.namespace}`
323341
},
@@ -326,14 +344,30 @@ const operatorUtils = {
326344
}
327345
).then((result) => {
328346
expect(result.code).to.eq(0);
329-
cy.log(`COO CSV updated successfully with Monitoring Console Plugin image: ${result.stdout}`);
347+
cy.log(`COO CSV updated successfully with ${config.componentName} image: ${result.stdout}`);
330348
cy.reload(true);
331349
});
332350
} else {
333-
cy.log('MCP_CONSOLE_IMAGE is NOT set. Skipping patching the image in COO operator CSV.');
351+
cy.log(`${config.envVar} is NOT set. Skipping patching the image in COO operator CSV.`);
334352
}
335353
},
336354

355+
setupMonitoringConsolePlugin(MCP: { namespace: string }): void {
356+
operatorUtils.patchCOOCSVImage(MCP, {
357+
envVar: 'MCP_CONSOLE_IMAGE',
358+
scriptPath: './cypress/fixtures/coo/update-mcp-image.sh',
359+
componentName: 'Monitoring Console Plugin'
360+
});
361+
},
362+
363+
setupClusterHealthAnalyzer(MCP: { namespace: string }): void {
364+
operatorUtils.patchCOOCSVImage(MCP, {
365+
envVar: 'CHA_IMAGE',
366+
scriptPath: './cypress/fixtures/coo/update-cha-image.sh',
367+
componentName: 'cluster-health-analyzer'
368+
});
369+
},
370+
337371
setupDashboardsAndPlugins(MCP: { namespace: string }): void {
338372

339373
cy.log('Create perses-dev namespace.');
@@ -797,6 +831,7 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
797831
operatorUtils.installCOO(MCP);
798832
operatorUtils.waitForCOOReady(MCP);
799833
operatorUtils.setupMonitoringConsolePlugin(MCP);
834+
operatorUtils.setupClusterHealthAnalyzer(MCP);
800835
operatorUtils.setupDashboardsAndPlugins(MCP);
801836
operatorUtils.setupTroubleshootingPanel(MCP);
802837
operatorUtils.setupMonitoringPluginImage(MP);

0 commit comments

Comments
 (0)