Repository navigation
fix(deploy/knative): make setup-ocp.sh failures loud and its gates unambiguous - #194
Merged
pdettori merged 1 commit intoAug 31, 2026
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #178.
#178 does not reproduce
Investigated before changing anything, and the reported exit 0 is a measurement artifact:
git log -Sshows one commit ever wrote that line (cb191209), withexit 1included, and it was unchanged at the commit the reporter ran (0e9b9fc, 2026-08-28).$KUBECTL: direct → 1;| tee→ 0 (pipeline reports the last command);$?read after an intervening command → 0.setup-ocp.sh,setup-k8s.sh, andsetup-kind.shfinds no failure path that fails to terminate. (My first pass flaggedsetup-k8s.sh:240; false positive — theexit 1is two lines down inside the brace group.)-o wide, which addsIP/NODE/NOMINATED NODE/READINESS GATES. The pasted table has onlyNAME READY STATUS RESTARTS AGE, so it came from a separate manualget pod— making the reported0that 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_errorhad no>&2, unlikesetup-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_successstay 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 wheneverlog_successfails — so all 17 gates reported correctly only becauseechohappens 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 adie()helper (fatal by construction), converts the remaininglog_error …; exit 1pairs to it, and adds anSH_SOURCE_ONLYhook mirroringsetup-kind.shso 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 exercisinglog_error/diebehaviourally through the source-only hook. Each assertion was checked against a planted regression — dropping>&2fails 3 cases, a non-terminatinglog_errorfails 1, reintroducing an SC2015 gate fails 1 — then the file was restored byte-identical.End-to-end on the real script:
>/dev/null--dry-runpnpm -r test: 209 knative-server tests pass, 0 failures repo-wide.make typecheck: clean.shellcheck: clean on all three scripts. The pre-existingsetup-kind-image.test.shstill passes.Scope
Only
setup-ocp.shis refactored — it's the script #178 was filed against and the one that carried all 17 SC2015 gates.setup-k8s.shalready routes diagnostics to stderr and uses terminating brace blocks;setup-kind.shuses bareecho "ERROR: …"with no helper family. Both are covered by the new terminate-on-failure test. Their remaining stylistic divergence (nolog_*helpers insetup-kind.sh;setup-k8s.shsendinglog_infoto 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.