From 3ec270fa89b727202f6286453ba43256041a4bf3 Mon Sep 17 00:00:00 2001 From: Konstantin Renner Date: Thu, 9 Jul 2026 14:18:08 +0200 Subject: [PATCH] otbr: strip the CR from `ot-ctl state` before matching it #139 landed and did its job: the pod now logs otbr: persisted dataset found after 18 attempt(s); activating Thread and `ot-ctl state` reports `leader`, `ot-ctl br state` reports `running`, with the OMR prefix fd5f:5689:e6dc:1::/64 published again. The dataset appeared ~36s after ot-ctl began answering, so the old single-shot check never stood a chance. But the attach-confirmation block in that same PR then printed: otbr: WARNING Thread not attached after 60s (state=leader) ot-ctl speaks a serial-console protocol and terminates lines with CRLF, so `ot-ctl state | head -1` yields `leader\r` -- 7 bytes. That matches no shell glob, so the `case` fell through to the warning, and the stray CR is invisible in the log, making the message read as a flat contradiction. Verified with `od -c` in the live pod (`l e a d e r \r \n`) and by `case "leader\r" in leader) ...` failing to match while the tr-stripped value matches. `bash -n` clean, kustomize builds. The warning was cosmetic -- Thread attached correctly either way -- but a health line that says the opposite of the truth is worse than no line. Co-Authored-By: Claude Opus 4.8 (1M context) --- kubernetes/apps/otbr/deployment.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kubernetes/apps/otbr/deployment.yaml b/kubernetes/apps/otbr/deployment.yaml index 698695f9..f8cd9dd1 100644 --- a/kubernetes/apps/otbr/deployment.yaml +++ b/kubernetes/apps/otbr/deployment.yaml @@ -145,9 +145,16 @@ spec: # exists to prevent. Note the trailing `|| true`: this script # runs under `set -e`, so a bare failing test would kill the # container rather than log a warning. + # + # `tr -d '\r'` is load-bearing. ot-ctl speaks a serial-console + # protocol and terminates lines with CRLF, so `ot-ctl state` + # yields `leader\r` (7 bytes). That matches no shell glob, and + # the stray CR is invisible in logs — the first cut of this + # block printed "WARNING Thread not attached (state=leader)" + # while Thread was, in fact, the leader. STATE="" for i in $(seq 1 30); do - STATE=$(ot-ctl state 2>/dev/null | head -1 || true) + STATE=$(ot-ctl state 2>/dev/null | head -1 | tr -d '\r' || true) case "$STATE" in leader|router|child) echo "otbr: Thread attached as ${STATE}" -- 2.54.0