Skip to content

fix(deploy/knative): make setup-ocp.sh failures loud and its gates unambiguous - #194

Merged
pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/setup-script-failure-contract
Aug 31, 2026
Merged

pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/setup-script-failure-contract

Conversation

@pdettori

Copy link
Copy Markdown
Member

Refs #178.

#178 does not reproduce

Investigated before changing anything, and the reported exit 0 is a measurement artifact:

  • The gate has always exited non-zero. git log -S shows one commit ever wrote that line (cb191209), with exit 1 included, and it was unchanged at the commit the reporter ran (0e9b9fc, 2026-08-28).
  • A direct run exits 1. Replicating the construct verbatim with a stubbed $KUBECTL: direct → 1; | tee → 0 (pipeline reports the last command); $? read after an intervening command → 0.
  • No script logs-and-continues. A brace-aware audit of setup-ocp.sh, setup-k8s.sh, and setup-kind.sh finds no failure path that fails to terminate. (My first pass flagged setup-k8s.sh:240; false positive — the exit 1 is two lines down inside the brace group.)
  • The tell is in the issue's own transcript. The script prints the pod table with -o wide, which adds IP / NODE / NOMINATED NODE / READINESS GATES. The pasted table has only NAME READY STATUS RESTARTS AGE, so it came from a separate manual get pod — making the reported 0 that command's status, not the script's.

Worth noting for #177's write-up: the "a broken bring-up reported success" conclusion there was very likely the same artifact. Nothing has been silently swallowing failures.

Three real weaknesses it did point at

1. Diagnostics went to stdout. log_warn/log_error had no >&2, unlike setup-k8s.sh. This is precisely what made the ✗ "easy to miss": redirect stdout and the failure disappears; pipe it and diagnostics interleave with progress. Both now go to stderr. log_info/log_success stay on stdout — they're progress, not diagnostics, and nothing parses them.

2. Every gate used the SC2015 shape. cmd && log_success "…" || { fail } runs the failure branch whenever log_success fails — so all 17 gates reported correctly only because echo happens to return 0. All 17 are now if/else, including the five counted (vfail) async checks and the two intentionally non-fatal warn-and-continue ones. shellcheck is now clean on the script (it previously emitted 17 SC2015 notes).

3. Nothing pinned the contract. The regression #178 actually feared — a future edit dropping an exit — was unguarded. Adds a die() helper (fatal by construction), converts the remaining log_error …; exit 1 pairs to it, and adds an SH_SOURCE_ONLY hook mirroring setup-kind.sh so the helpers can be exercised without a cluster.

Verification

New test (setup-script-failure-contract.test.ts, 11 cases) pins all three invariants, covering all three setup scripts for the terminate-on-failure one, and exercising log_error/die behaviourally through the source-only hook. Each assertion was checked against a planted regression — dropping >&2 fails 3 cases, a non-terminating log_error fails 1, reintroducing an SC2015 gate fails 1 — then the file was restored byte-identical.

End-to-end on the real script:

Case Result
unreachable cluster exit 1, error on stderr, 0 lines on stdout
same, with >/dev/null failure still visible — the #178 concern
--dry-run completes unchanged, exit 0, warning on stderr

pnpm -r test: 209 knative-server tests pass, 0 failures repo-wide. make typecheck: clean. shellcheck: clean on all three scripts. The pre-existing setup-kind-image.test.sh still passes.

Scope

Only setup-ocp.sh is refactored — it's the script #178 was filed against and the one that carried all 17 SC2015 gates. setup-k8s.sh already routes diagnostics to stderr and uses terminating brace blocks; setup-kind.sh uses bare echo "ERROR: …" with no helper family. Both are covered by the new terminate-on-failure test. Their remaining stylistic divergence (no log_* helpers in setup-kind.sh; setup-k8s.sh sending log_info to stderr too) is left alone rather than folded into a bug fix.

Suggest closing #178 as not-a-bug once this lands, since the contract it asked for is now enforced by test rather than holding by luck.

make lint fails on this machine before and after (Type tag 'typescript' is not recognized — pre-commit's identify is too old). Pre-existing and unrelated.

…ambiguous

rossoctl#178 reported that setup-ocp.sh exits 0 after logging "✗ Sandbox pod not
Ready". That does not reproduce. The gate has ended in `exit 1` since it was
written (cb19120, unchanged at the commit the reporter ran), a direct run
does exit 1, and no failure path in setup-ocp.sh / setup-k8s.sh /
setup-kind.sh logs and continues. Exit 0 shows up only when the caller drops
it -- a `| tee` pipeline, or reading $? past the script. The issue's own
transcript points at the latter: the pod table it pastes lacks the IP/NODE
columns that the script's `get pod -o wide` prints, so it came from a
separate manual `get pod`, and the 0 is that command's status.

The premise was wrong, but it pointed at three real weaknesses:

  - log_warn/log_error wrote to **stdout**, unlike setup-k8s.sh. That is what
    made the ✗ "easy to miss": redirect stdout and the failure vanishes; pipe
    it and diagnostics interleave with progress. Both now go to stderr.
    log_info/log_success stay on stdout -- they are progress, not diagnostics,
    and nothing parses them.

  - Every readiness gate used `cmd && log_success ... || { fail }`, which
    shellcheck flags 17 times (SC2015): the *failure* branch runs whenever
    log_success fails, so these reported correctly only because `echo`
    happens to return 0. All 17 are now if/else. shellcheck is clean.

  - Nothing pinned the exit-code contract, so a future edit could drop an
    `exit` silently -- the thing rossoctl#178 feared. Adds a `die()` helper (fatal by
    construction), converts the remaining `log_error ...; exit 1` pairs to it,
    and adds an SH_SOURCE_ONLY hook mirroring setup-kind.sh so the helpers are
    testable.

The new test pins all three: diagnostics on stderr, every logged failure
terminates (or is counted and terminated later), and no gate uses the SC2015
shape. It covers all three setup scripts for the terminate invariant, and
exercises log_error/die behaviourally via the source-only hook. Each
assertion was checked against a planted regression.

Verified: unreachable cluster exits 1 with the error on stderr and nothing on
stdout, and the failure still surfaces under `>/dev/null`; --dry-run
completes unchanged; 209 knative-server tests pass; typecheck clean;
shellcheck clean on all three scripts.

Refs rossoctl#178

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit db29c69 into rossoctl:main Aug 31, 2026
10 checks passed
@pdettori
pdettori deleted the fix/setup-script-failure-contract branch August 31, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant