Skip to content

Commit 09387b5

Browse files
committed
fix(e2e): fix external DB tests for operator deployments
For operator deployments, patching POSTGRES_* env vars directly onto the deployment is reverted by operator reconciliation. The external DB tests (Azure DB, RDS) configure postgres-cred secret with connection details, but those values never reached the RHDH container as env vars. Fix: - Add postgres-cred to extraEnvs.secrets in the Backstage CR so the operator injects all its keys as env vars automatically - Skip direct deployment env var patching in prepareForExternalDatabase for operator installs (same pattern as schema-mode setup) Assisted-by: OpenCode
1 parent e399500 commit 09387b5

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

e2e-tests/playwright/utils/postgres-config.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { readFileSync, existsSync } from "fs";
1414

1515
import { Client } from "pg";
1616

17-
import { base64Encode } from "./helper";
17+
import { base64Encode, resolveInstallMethod } from "./helper";
1818
import { KubeClient, BACKSTAGE_BACKEND_CONTAINER } from "./kube-client";
1919
import type { AppConfigYaml } from "./runtime-config";
2020

@@ -297,7 +297,11 @@ export async function prepareForExternalDatabase(
297297
// Schema-mode tests may have added individual secretKeyRef env vars pointing
298298
// to a *-postgresql secret. These override the bulk envFrom injection from
299299
// postgres-cred and must be removed before external DB tests.
300-
await removeSchemaModePatchedEnvVars(kubeClient, deploymentName, namespace);
300+
// Skip for operator — the operator manages env vars via extraEnvs.secrets
301+
// in the Backstage CR, so there are no direct deployment patches to remove.
302+
if (resolveInstallMethod() !== "operator") {
303+
await removeSchemaModePatchedEnvVars(kubeClient, deploymentName, namespace);
304+
}
301305

302306
// --- 2. Patch app-config ConfigMap to use external DB connection ---
303307
console.log("Patching app-config to use external database connection (env var placeholders)...");
@@ -315,10 +319,18 @@ export async function prepareForExternalDatabase(
315319
console.log("App-config patched for external database connection");
316320

317321
// --- 3. Add POSTGRES_* env vars to the deployment via secretKeyRef ---
318-
// The deployment starts with internal DB (no postgres-cred env vars).
319-
// Add individual env vars pointing to the postgres-cred secret so the
320-
// app-config ${POSTGRES_HOST} etc. placeholders resolve correctly.
321-
await ensurePostgresCredEnvVars(kubeClient, deploymentName, namespace);
322+
// Helm: patch individual env vars pointing to the postgres-cred secret so
323+
// the app-config ${POSTGRES_HOST} etc. placeholders resolve correctly.
324+
// Operator: skip — the Backstage CR already includes postgres-cred in
325+
// extraEnvs.secrets, so the operator injects all keys as env vars.
326+
// Patching the deployment directly would be reverted by reconciliation.
327+
if (resolveInstallMethod() !== "operator") {
328+
await ensurePostgresCredEnvVars(kubeClient, deploymentName, namespace);
329+
} else {
330+
console.log(
331+
"Skipping deployment env var patching (operator injects from postgres-cred via extraEnvs.secrets)",
332+
);
333+
}
322334
}
323335

324336
/**

e2e-tests/playwright/utils/runtime-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export function generateBackstageCR(config: RuntimeDeployConfig): BackstageCR {
388388
},
389389
extraEnvs: {
390390
envs,
391-
secrets: [{ name: "rhdh-runtime-config" }],
391+
secrets: [{ name: "rhdh-runtime-config" }, { name: "postgres-cred" }],
392392
},
393393
route: { enabled: true },
394394
},

0 commit comments

Comments
 (0)