Skip to content

Commit b9a5354

Browse files
committed
fix(e2e): adapt new KubeClient methods to modular kube-client structure
After rebasing onto main, the kube-client.ts monolith was split into kube-client/ directory modules. Add methods and constants that our PR introduced to the new modular structure: - BACKSTAGE_BACKEND_CONTAINER constant - patchAppConfig, jsonPatchDeployment, restartDeploymentWithRetry - removeContainerEnvVars, addContainerEnvVarsFromSecret - waitForBackstageCrd, createConfigMap, deleteNamespaceIfExists, createNamespace - getRhdhDeploymentName: use resolveInstallMethod() for INSTALL_METHOD env var Fix all oxlint violations to comply with strict + pedantic linting: - Replace || with ?? for nullish coalescing - Add explicit nullish/empty checks for strict-boolean-expressions - Fix setTimeout in Promise executors for strict-void-return - Move inline comments to separate lines - Add type annotations and safe type assertions - Swap negated conditions to positive form Assisted-by: OpenCode
1 parent 619ceb3 commit b9a5354

15 files changed

Lines changed: 430 additions & 289 deletions

File tree

e2e-tests/playwright/e2e/configuration-test/config-map.spec.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { test, expect } from "@support/coverage/test";
22

33
import { Common } from "../../utils/common";
4-
import { KubeClient, getRhdhDeploymentName } from "../../utils/kube-client";
5-
import { UIhelper } from "../../utils/ui-helper";
4+
import { KubeClient, getRhdhDeploymentName, isRecord } from "../../utils/kube-client";
65
import { ensureRuntimeDeployed } from "../../utils/runtime-deploy";
6+
import { UIhelper } from "../../utils/ui-helper";
77

88
test.describe("Change app-config at e2e test runtime", () => {
99
test.beforeAll(async () => {
10-
test.setTimeout(900000); // 15 minutes — includes deployment if needed
10+
// 15 minutes — includes deployment if needed
11+
test.setTimeout(900000);
1112
test.info().annotations.push(
1213
{
1314
type: "component",
@@ -28,22 +29,19 @@ test.describe("Change app-config at e2e test runtime", () => {
2829
test("Verify title change after ConfigMap modification", async ({ page }) => {
2930
test.setTimeout(300000);
3031

31-
const namespace = process.env.NAME_SPACE_RUNTIME || "showcase-runtime";
32+
const namespace = process.env.NAME_SPACE_RUNTIME ?? "showcase-runtime";
3233
const deploymentName = getRhdhDeploymentName();
3334

3435
const kubeUtils = new KubeClient();
3536
const dynamicTitle = generateDynamicTitle();
3637
try {
3738
console.log("Updating app-config ConfigMap with new title.");
38-
await kubeUtils.patchAppConfig(namespace, (appConfig) => {
39-
if (!appConfig.app) {
40-
throw new Error(
41-
"Invalid app-config structure: expected 'app' section not found.",
42-
);
39+
await kubeUtils.patchAppConfig(namespace, (appConfig: Record<string, unknown>) => {
40+
if (!isRecord(appConfig.app)) {
41+
throw new Error("Invalid app-config structure: expected 'app' section not found.");
4342
}
44-
const app = appConfig.app as Record<string, unknown>;
45-
console.log(`Current title: ${app.title}`);
46-
app.title = dynamicTitle;
43+
console.log(`Current title: ${String(appConfig.app.title)}`);
44+
appConfig.app.title = dynamicTitle;
4745
console.log(`New title: ${dynamicTitle}`);
4846
});
4947

e2e-tests/playwright/e2e/external-database/verify-tls-config-with-external-azure-db.spec.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ test.describe("Verify TLS configuration with Azure Database for PostgreSQL healt
4949
await ensureRuntimeDeployed();
5050

5151
// Validate certificates are available — skip gracefully if not set
52-
const azureCerts = readCertificateFile(
53-
process.env.AZURE_DB_CERTIFICATES_PATH,
54-
);
55-
if (!azureCerts || !azureUser || !azurePassword) {
52+
const azureCerts = readCertificateFile(process.env.AZURE_DB_CERTIFICATES_PATH);
53+
if (azureCerts === null || azureCerts === undefined || !azureUser || !azurePassword) {
5654
testInfo.skip(
5755
true,
5856
"Azure DB environment variables not configured (AZURE_DB_CERTIFICATES_PATH, AZURE_DB_USER, AZURE_DB_PASSWORD) — Azure DB tests are opt-in",
@@ -76,10 +74,7 @@ test.describe("Verify TLS configuration with Azure Database for PostgreSQL healt
7674
test.beforeAll(async ({}, testInfo) => {
7775
test.setTimeout(180000);
7876
if (!config.host) {
79-
testInfo.skip(
80-
true,
81-
`AZURE_DB_*_HOST not set for ${config.name} — skipping`,
82-
);
77+
testInfo.skip(true, `AZURE_DB_*_HOST not set for ${config.name} — skipping`);
8378
return;
8479
}
8580
test.info().annotations.push({
@@ -88,8 +83,8 @@ test.describe("Verify TLS configuration with Azure Database for PostgreSQL healt
8883
});
8984
await clearDatabase({
9085
host: config.host,
91-
user: azureUser!,
92-
password: azurePassword!,
86+
user: azureUser,
87+
password: azurePassword,
9388
certificatePath: process.env.AZURE_DB_CERTIFICATES_PATH,
9489
});
9590
});
@@ -103,8 +98,8 @@ test.describe("Verify TLS configuration with Azure Database for PostgreSQL healt
10398
test.setTimeout(600000);
10499
await configurePostgresCredentials(kubeClient, namespace, {
105100
host: config.host,
106-
user: azureUser!,
107-
password: azurePassword!,
101+
user: azureUser,
102+
password: azurePassword,
108103
});
109104
await kubeClient.restartDeployment(deploymentName, namespace);
110105
});

e2e-tests/playwright/e2e/external-database/verify-tls-config-with-external-rds.spec.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test.describe("Verify TLS configuration with RDS PostgreSQL health check", () =>
5050

5151
// Validate certificates are available — skip gracefully if not set
5252
const rdsCerts = readCertificateFile(process.env.RDS_DB_CERTIFICATES_PATH);
53-
if (!rdsCerts || !rdsUser || !rdsPassword) {
53+
if (rdsCerts === null || rdsCerts === undefined || !rdsUser || !rdsPassword) {
5454
testInfo.skip(
5555
true,
5656
"RDS environment variables not configured (RDS_DB_CERTIFICATES_PATH, RDS_USER, RDS_PASSWORD) — RDS tests are opt-in",
@@ -74,10 +74,7 @@ test.describe("Verify TLS configuration with RDS PostgreSQL health check", () =>
7474
test.beforeAll(async ({}, testInfo) => {
7575
test.setTimeout(135000);
7676
if (!config.host) {
77-
testInfo.skip(
78-
true,
79-
`RDS_*_HOST not set for ${config.name} — skipping`,
80-
);
77+
testInfo.skip(true, `RDS_*_HOST not set for ${config.name} — skipping`);
8178
return;
8279
}
8380
test.info().annotations.push({
@@ -86,8 +83,8 @@ test.describe("Verify TLS configuration with RDS PostgreSQL health check", () =>
8683
});
8784
await clearDatabase({
8885
host: config.host,
89-
user: rdsUser!,
90-
password: rdsPassword!,
86+
user: rdsUser,
87+
password: rdsPassword,
9188
certificatePath: process.env.RDS_DB_CERTIFICATES_PATH,
9289
});
9390
});
@@ -101,8 +98,8 @@ test.describe("Verify TLS configuration with RDS PostgreSQL health check", () =>
10198
test.setTimeout(600000);
10299
await configurePostgresCredentials(kubeClient, namespace, {
103100
host: config.host,
104-
user: rdsUser!,
105-
password: rdsPassword!,
101+
user: rdsUser,
102+
password: rdsPassword,
106103
});
107104
await kubeClient.restartDeployment(deploymentName, namespace);
108105
});

e2e-tests/playwright/e2e/plugin-division-mode-schema/schema-mode-db.ts

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import { expect } from "@playwright/test";
66
import { Client } from "pg";
77
import type { ClientConfig } from "pg";
8-
import { KubeClient } from "../../utils/kube-client";
8+
99
import { base64Decode } from "../../utils/helper";
10+
import { KubeClient } from "../../utils/kube-client";
1011

1112
/** Default schema-mode test database user (overridable via SCHEMA_MODE_DB_USER). */
1213
export const SCHEMA_MODE_DEFAULT_DB_USER = "bn_backstage";
@@ -99,9 +100,7 @@ const defaultConnectionOptions: Partial<ClientConfig> = {
99100
keepAliveInitialDelayMillis: 10000,
100101
};
101102

102-
export async function connectWithSslFallback(
103-
config: ClientConfig,
104-
): Promise<Client> {
103+
export async function connectWithSslFallback(config: ClientConfig): Promise<Client> {
105104
// Try SSL first (single attempt), fall back to non-SSL if the server doesn't support it.
106105
const sslConfig = { ...defaultConnectionOptions, ...config };
107106
const sslClient = new Client(sslConfig);
@@ -110,17 +109,10 @@ export async function connectWithSslFallback(
110109
return sslClient;
111110
} catch (sslError) {
112111
await sslClient.end().catch(() => {});
113-
const sslMsg =
114-
sslError instanceof Error ? sslError.message : String(sslError);
112+
const sslMsg = sslError instanceof Error ? sslError.message : String(sslError);
115113
// Bitnami PostgreSQL sub-chart doesn't enable SSL by default
116-
if (
117-
sslMsg.includes("SSL") ||
118-
sslMsg.includes("ssl") ||
119-
sslMsg.includes("does not support")
120-
) {
121-
console.log(
122-
`SSL connection failed (${sslMsg}), falling back to non-SSL...`,
123-
);
114+
if (sslMsg.includes("SSL") || sslMsg.includes("ssl") || sslMsg.includes("does not support")) {
115+
console.log(`SSL connection failed (${sslMsg}), falling back to non-SSL...`);
124116
return connectWithRetry({ ...config, ssl: false });
125117
}
126118
// For non-SSL errors (e.g. ECONNREFUSED), retry with SSL (port-forward may not be ready)
@@ -321,57 +313,38 @@ export async function configureSchemaMode(
321313
}
322314
}
323315

324-
if (!svcName) {
325-
console.warn(
326-
"No PostgreSQL service found in namespace — schema-mode tests will skip",
327-
);
316+
if (svcName === undefined || svcName === "") {
317+
console.warn("No PostgreSQL service found in namespace — schema-mode tests will skip");
328318
return;
329319
}
330320

331321
// Find admin password
332322
const secretCandidates =
333323
installMethod === "operator"
334-
? [
335-
`backstage-psql-secret-${releaseName}`,
336-
`${releaseName}-postgresql`,
337-
"postgres-cred",
338-
]
339-
: [
340-
`${releaseName}-postgresql`,
341-
`backstage-psql-secret-${releaseName}`,
342-
"postgres-cred",
343-
];
344-
345-
const passwordKeys = [
346-
"postgres-password",
347-
"POSTGRESQL_ADMIN_PASSWORD",
348-
"POSTGRES_PASSWORD",
349-
];
324+
? [`backstage-psql-secret-${releaseName}`, `${releaseName}-postgresql`, "postgres-cred"]
325+
: [`${releaseName}-postgresql`, `backstage-psql-secret-${releaseName}`, "postgres-cred"];
326+
327+
const passwordKeys = ["postgres-password", "POSTGRESQL_ADMIN_PASSWORD", "POSTGRES_PASSWORD"];
350328

351329
let adminPassword: string | undefined;
352330
for (const sec of secretCandidates) {
353331
try {
354-
const result = await kubeClient.coreV1Api.readNamespacedSecret(
355-
sec,
356-
namespace,
357-
);
358-
const data = result.body.data || {};
332+
const result = await kubeClient.coreV1Api.readNamespacedSecret(sec, namespace);
333+
const data = result.body.data ?? {};
359334
for (const key of passwordKeys) {
360335
if (data[key]) {
361336
adminPassword = base64Decode(data[key]);
362337
break;
363338
}
364339
}
365-
if (adminPassword) break;
340+
if (adminPassword !== undefined && adminPassword !== "") break;
366341
} catch {
367342
// not found, try next
368343
}
369344
}
370345

371-
if (!adminPassword) {
372-
console.warn(
373-
"Could not resolve PostgreSQL admin password — schema-mode tests will skip",
374-
);
346+
if (adminPassword === undefined || adminPassword === "") {
347+
console.warn("Could not resolve PostgreSQL admin password — schema-mode tests will skip");
375348
return;
376349
}
377350

@@ -381,11 +354,8 @@ export async function configureSchemaMode(
381354
process.env.SCHEMA_MODE_DB_ADMIN_USER = "postgres";
382355
process.env.SCHEMA_MODE_DB_ADMIN_PASSWORD = adminPassword;
383356
process.env.SCHEMA_MODE_DB_PASSWORD =
384-
process.env.SCHEMA_MODE_DB_PASSWORD || SCHEMA_MODE_DEFAULT_DB_PASSWORD;
385-
process.env.SCHEMA_MODE_DB_USER =
386-
process.env.SCHEMA_MODE_DB_USER || SCHEMA_MODE_DEFAULT_DB_USER;
357+
process.env.SCHEMA_MODE_DB_PASSWORD ?? SCHEMA_MODE_DEFAULT_DB_PASSWORD;
358+
process.env.SCHEMA_MODE_DB_USER = process.env.SCHEMA_MODE_DB_USER ?? SCHEMA_MODE_DEFAULT_DB_USER;
387359

388-
console.log(
389-
`Schema-mode env configured: port-forward svc/${svcName} in ${namespace}`,
390-
);
360+
console.log(`Schema-mode env configured: port-forward svc/${svcName} in ${namespace}`);
391361
}

0 commit comments

Comments
 (0)