Skip to content

Commit 273e644

Browse files
authored
feat(deployment): show command output on failure (#43)
This change adds an additional helper utility to run commands silently unless there is a failure, and adjusts the keycloak deployment script to use this when running a couple helm install and ugprade commands to help aid in troubleshooting setup problems. Assisted-By: Cursor Desktop rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
1 parent d6b77d3 commit 273e644

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

docs/overlay/reference/troubleshooting.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ oc login --token=<token> --server=<server>
123123

124124
### "Keycloak deployment failed"
125125

126-
**Problem:** Keycloak fails to deploy.
126+
**Problem:** Keycloak fails to deploy (e.g. during global setup or when using `auth: "keycloak"`).
127127

128128
**Solutions:**
129+
- **Check the build log for command output.** When the Keycloak deployment step fails, the test framework prints the failed command's stdout and stderr to the log. Look for **`[command stdout]:`** and **`[command stderr]:`** in the output — that shows the actual Helm (or other) command output and is the first place to look for the failure reason.
129130
- Check Keycloak namespace for errors:
130131
```bash
131132
oc get pods -n rhdh-keycloak

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@red-hat-developer-hub/e2e-test-utils",
3-
"version": "1.1.10",
3+
"version": "1.1.11",
44
"description": "Test utilities for RHDH E2E tests",
55
"license": "Apache-2.0",
66
"repository": {

src/deployment/keycloak/deployment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import KeycloakAdminClient from "@keycloak/keycloak-admin-client";
22
import { KubernetesClientHelper } from "../../utils/kubernetes-client.js";
3-
import { $ } from "../../utils/bash.js";
3+
import { $, runQuietUnlessFailure } from "../../utils/bash.js";
44
import {
55
DEFAULT_KEYCLOAK_CONFIG,
66
BITNAMI_CHART_REPO,
@@ -380,11 +380,11 @@ export class KeycloakHelper {
380380

381381
private async _deployWithHelm(): Promise<void> {
382382
await $`helm repo add bitnami ${BITNAMI_CHART_REPO} || true`;
383-
await $`helm repo update > /dev/null 2>&1`;
383+
await runQuietUnlessFailure`helm repo update`;
384384

385-
await $`helm upgrade --install ${this.deploymentConfig.releaseName} ${BITNAMI_CHART_NAME} \
385+
await runQuietUnlessFailure`helm upgrade --install ${this.deploymentConfig.releaseName} ${BITNAMI_CHART_NAME} \
386386
--namespace ${this.deploymentConfig.namespace} \
387-
--values ${this.deploymentConfig.valuesFile} > /dev/null 2>&1`;
387+
--values ${this.deploymentConfig.valuesFile}`;
388388

389389
await this.waitUntilReady();
390390
}

src/utils/bash.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,44 @@ import { $ } from "zx";
33
$.quiet = true;
44
$.stdio = ["inherit", "inherit", "inherit"];
55

6+
/** Shape of zx ProcessOutput used when checking command result. */
7+
interface ProcessResult {
8+
exitCode: number;
9+
stdout?: string;
10+
stderr?: string;
11+
}
12+
13+
/**
14+
* Runs a shell command with stdout/stderr captured. On success, output is not printed.
15+
* On non-zero exit, stdout and stderr are written to console.error and an error is thrown.
16+
* Use for noisy commands that should stay quiet on success but show output when they fail.
17+
*/
18+
export async function runQuietUnlessFailure(
19+
strings: TemplateStringsArray,
20+
...values: unknown[]
21+
): Promise<void> {
22+
const runWithPipe = $({
23+
stdio: ["pipe", "pipe", "pipe"],
24+
nothrow: true,
25+
});
26+
const result = (await (
27+
runWithPipe as (
28+
strings: TemplateStringsArray,
29+
...values: unknown[]
30+
) => ReturnType<typeof $>
31+
)(strings, ...values)) as ProcessResult;
32+
33+
if (result.exitCode !== 0) {
34+
if (result.stdout?.trim()) {
35+
console.error("[command stdout]:", result.stdout.trim());
36+
}
37+
if (result.stderr?.trim()) {
38+
console.error("[command stderr]:", result.stderr.trim());
39+
}
40+
throw new Error(
41+
`Command failed with exit code ${result.exitCode}. Output above.`,
42+
);
43+
}
44+
}
45+
646
export { $ };

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { envsubst } from "./common.js";
2-
export { $ } from "./bash.js";
2+
export { $, runQuietUnlessFailure } from "./bash.js";
33
export {
44
mergeYamlFiles,
55
mergeYamlFilesIfExists,

0 commit comments

Comments
 (0)