Skip to content

feat(k8s): mesh self-heal detect+recover for post-suspend 503 (Part of #1899) - #2179

Merged
cwiklik merged 4 commits into
rossoctl:mainfrom
cwiklik:feat/mesh-selfheal-preflight-1899
Jul 13, 2026
Merged

cwiklik merged 4 commits into
rossoctl:mainfrom
cwiklik:feat/mesh-selfheal-preflight-1899

Conversation

@cwiklik

@cwiklik cwiklik commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What

Adds a detect-and-recover tool + skill for the Istio Ambient "everything returns 503" outage seen on long-running / suspended dev/Kind clusters. Part A of the agreed A+B mitigation for #1899 (B = feature-flagged CronJob remediator, targeted for v0.8).

  • scripts/k8s/mesh-recover.sh — read-only by default: probes a backend-dependent gateway route (kagenti-ui/kagenti-api, which flip to 503 in an outage — not edge-redirect routes like kiali), checks ztunnel cert/logs (discovers the ztunnel namespace, since Kind uses istio-system and the chart uses istio-ztunnel), and optionally the SPIRE agent. --fix runs the proven recovery — rollout restart of ztunnel + waypoints + the gateway (and, with --include-spire, the SPIRE agent). --json for automation. Exit 0 healthy / 2 degraded.
  • .claude/skills/istio:mesh-selfheal/ — skill wrapping the above: when-to-use, the two-domain note (mesh mTLS vs. the separate SPIRE reattest issue), manual fallback commands, diagnostics, and testing.
  • scripts/k8s/induce-mesh-outage.sh — Kind-guarded test harness that induces the symptom (CA down + ztunnel pods deleted → mesh-wide 503) and asserts the full detect → --fix → re-probe loop; --break / --restore / --self-test.
  • Registration: istio parent skill table, a k8s:health cross-reference, and the skills README.md tree.

Why

Root cause of #1899: the Ambient data plane serves expired istiod-issued mTLS certs and never re-fetches after a host suspend / clock jump, so every gateway route 503s while pods look healthy. (SPIRE is a separate identity plane; its reattest deadlock affects AuthBridge, not routing.) The durable data-plane fix is upstream — istio/ztunnel#1679; this is the kagenti-side dev-cluster mitigation.

Scope / safety

  • dev/Kind only; nothing auto-runs. --fix and the induce harness are opt-in and refuse to run outside a kind-* context (without --force).
  • No production behavior change; no new always-on components.

Testing

  • mesh-recover.sh — healthy cluster → exit 0; degraded (bad target) → exit 2 + printed dry-run recovery; --json → clean JSON.
  • induce-mesh-outage.sh --self-test on a live Kind cluster: induced 503 → detected (exit 2) → --fix → healthy (exit 0). This caught and fixed a real probe bug (edge-redirect routes gave a false-healthy).

Part of #1899. Durable fix tracked upstream: istio/ztunnel#1679.

Assisted-By: Claude Code

…rossoctl#1899)

Add scripts/k8s/mesh-recover.sh (detect the Istio Ambient expired-cert 503
outage on long-running/suspended dev clusters; --fix restarts ztunnel +
waypoints + gateway) and the istio:mesh-selfheal skill. Includes
scripts/k8s/induce-mesh-outage.sh, a Kind-guarded test harness that induces
the symptom and verifies the detect -> fix -> re-probe loop. Read-only by
default; dev/Kind scope. Durable data-plane fix tracked upstream
(istio/ztunnel#1679).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@rubambiza rubambiza added the ready-for-ai-review Request automated AI code review from clawgenti label Jul 13, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds mesh-recover.sh + induce-mesh-outage.sh and the istio:mesh-selfheal skill — a clean, well-scoped detect/recover tool for the post-suspend Ambient 503 outage. All checks pass. Ready for human review.


Reviewed by clawgenti using github:pr-review

Comment thread scripts/k8s/mesh-recover.sh Outdated
fi
elif [[ "$code" == "000" ]]; then
record "mesh-reachability" "INCONCLUSIVE" "could not connect to ${GATEWAY_URL} — is the Kind port-map / port-forward up?"
log_warn "Gateway ${GATEWAY_URL} unreachable (curl 000). Not a 503; check the port-map. Treating as needs-attention."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: INCONCLUSIVE cases (curl 000, no ztunnel found) set DEGRADED=true inline rather than via record(), so they show up inconsistently in the JSON output — the record() call records INCONCLUSIVE status but the outer DEGRADED flag is set separately. Consider routing through record "mesh-reachability" "INCONCLUSIVE" "..." and then checking for both DEGRADED and INCONCLUSIVE statuses when deciding the exit code, for consistency.

Comment thread scripts/k8s/induce-mesh-outage.sh Outdated
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RECOVER="${HERE}/mesh-recover.sh"

usage() { grep '^#' "$0" | sed 's/^# \{0,1\}//; 1d'; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: usage() parses comment lines from the script header (grep '^#' "$0" | sed ...) — this is a common pattern but fragile if the shebang or leading comment format ever changes. Since the help text is short, an explicit cat <<'EOF' heredoc (like mesh-recover.sh uses) would be more robust.

- mesh-recover.sh: route INCONCLUSIVE through record() instead of setting
  DEGRADED inline; add a distinct INCONCLUSIVE state so an unreachable gateway
  (curl 000 = port-map issue, not a mesh outage) no longer triggers a pointless
  restart. New exit code 3 = inconclusive; JSON gains an "inconclusive" field.
- induce-mesh-outage.sh: replace the comment-grep usage() with an explicit
  heredoc (robust to header/shebang changes).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds mesh-recover.sh, induce-mesh-outage.sh, and the istio:mesh-selfheal skill — a well-scoped detect/recover tool for the post-suspend Ambient 503 outage. Both scripts use set -euo pipefail, DCO sign-off is present on all commits, and CI is green.

  • Nit: SKILL.md documents exit codes as 0 healthy · 2 degraded · 1 usage error, but mesh-recover.sh adds a third exit code 3 (INCONCLUSIVE, e.g. gateway unreachable or no ztunnel found). The script's own --help output and inline comments are correct; only the skill doc summary is missing this code.

Reviewed by clawgenti using github:pr-review

scripts/k8s/mesh-recover.sh --fix --include-spire
```

Exit codes: `0` healthy · `2` degraded (or fix attempted) · `1` usage/precondition error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The exit code summary is missing exit 3 (INCONCLUSIVE — gateway unreachable or no ztunnel daemonset found). The script's own usage() output (and the inline comment at the INCONCLUSIVE variable declaration) are already correct; this line just needs · 3 inconclusive (unreachable / not Ambient) added. E.g.:

Exit codes: `0` healthy · `2` degraded (or fix attempted) · `3` inconclusive (unreachable / not Ambient) · `1` usage/precondition error.

@cwiklik

cwiklik commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Deploy & Test (e2e) failure is unrelated to this PR — safe to merge on the other green checks.

Root cause (from the failed run): the AuthBridge Weather (advanced) E2E stage clones and runs deploy_and_verify_advanced.sh from kagenti-extensions@main, and its pip install -r requirements.txt fails with a dependency conflict:

ERROR: Cannot install -r requirements.txt (line 4), -r requirements.txt (line 6) and
langchain-core==1.4.8 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible

All Kubernetes steps before it (secret sync, weather-tool-advanced rollout) succeeded — the failure is purely a Python dependency-resolution conflict in the external kagenti-extensions repo.

This PR only adds two shell scripts under scripts/k8s/ and Markdown skill files under .claude/skills/ — it touches no Python requirements, no chart/deploy path, and not kagenti-extensions, so it cannot have caused this. The conflict is deterministic (not flaky), so a re-run won't clear it; the fix belongs in kagenti-extensions requirements pins.

All other checks (lint, shellcheck, chart/helm, backend-tests, security scans, DCO) pass.

Assisted-By: Claude Code

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Well-scoped dev/Kind mesh self-heal tooling for the Ambient expired-cert 503 outage (#1899). mesh-recover.sh is read-only by default with --fix gated; induce-mesh-outage.sh is Kind-guarded and refuses to run outside a kind-* context without --force. No always-on components and no production behavior change. The backend-dependent probe-host choice (avoiding edge-redirect routes like kiali that would give a false-healthy) and the ztunnel-namespace discovery are nice touches. Reviewed the skill markdown and both scripts in full — no supply-chain concerns (the .claude/ changes are documentation only, no hooks or executable config).

The failing Deploy & Test check is unrelated to this PR: a langchain-core dependency-resolution conflict in the externally-cloned kagenti-extensions AuthBridge E2E. These scripts are dev-only and not exercised by CI.

Approving. Three cosmetic nits inline — take or leave.

Areas reviewed: Shell, Docs, .claude/ skills
Commits: 2, all signed-off

Assisted-By: Claude Code

Comment thread scripts/k8s/mesh-recover.sh Outdated
# Recovery
# ---------------------------------------------------------------------------
recover_mesh() {
local ns wp gw

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: local ns wp gw declares wp, but it's never assigned or used in recover_mesh() (shellcheck SC2034). Safe to drop it from the declaration.

Comment thread scripts/k8s/induce-mesh-outage.sh Outdated

while [[ $# -gt 0 ]]; do
case "$1" in
--break) MODE=break; shift ;;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: MODE=break / MODE=restore trip shellcheck SC2209 because break/restore read like builtins. It works correctly (assigns the literal string), but quoting — MODE='break' / MODE='restore' — silences the warning and makes the string-assignment intent explicit.

scripts/k8s/mesh-recover.sh --fix --include-spire
```

Exit codes: `0` healthy · `2` degraded (or fix attempted) · `1` usage/precondition error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This lists exit codes 0 / 2 / 1, but the script's own --help also documents 3 inconclusive (gateway unreachable / not an Ambient cluster — a restart won't help). Worth adding 3 here so the skill doc matches the script.

cwiklik added 2 commits July 13, 2026 14:53
- SKILL.md: add exit code 3 (inconclusive) to the exit-code summary so it
  matches the script's --help.
- mesh-recover.sh: drop unused 'wp' from recover_mesh() locals (SC2034).
- induce-mesh-outage.sh: quote MODE='break'/'restore'/'selftest' (SC2209).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik merged commit d61730a into rossoctl:main Jul 13, 2026
23 of 24 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Jul 13, 2026
cwiklik added a commit that referenced this pull request Aug 24, 2026
Part B of the mesh-wide-503 self-heal (Part A = scripts/k8s/mesh-recover.sh +
skills, shipped in 0.7 via #2179): a CronJob in rossoctl-deps that periodically
probes the gateway and, on a recoverable outage (expired ztunnel/waypoint certs
after a host suspend), runs mesh-recover.sh --fix with cooldown / max-restart
safety and loud Events.

- Feature flag meshSelfHeal.enabled (Helm value, OFF by default); renders only on
  non-OpenShift (the ambient cert-expiry failure mode is Kind/dev-specific).
- Reuses mesh-recover.sh unchanged (auto-discovers ztunnel ns + probe host; exit
  0 healthy / 2 degraded / 3 inconclusive). Helm .Files.Get can't read outside the
  chart, so a verbatim copy lives in charts/rossoctl-deps/files/ kept in sync by
  scripts/check-mesh-recover-sync.sh.
- Wrapper adds scheduling + cooldown/max-restart(window) gating (state ConfigMap)
  + k8s Events. Probes the in-cluster gateway Service http-istio.
- CronJob pod is out of ambient (istio.io/dataplane-mode: none) so its own kubectl
  calls don't traverse the broken ztunnel; nonroot/read-only/drop-ALL; least-priv
  RBAC (patch deployments/daemonsets for rollout restart; state CM; events).

Verified: helm template OFF->none, ON+Kind->full set, ON+OCP->none; helm lint clean;
wrapper shellcheck-clean; sync guard passing. Durable fix is upstream (istio/ztunnel#1679).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
cwiklik added a commit that referenced this pull request Aug 25, 2026
…03 docs (Part of #1899)

Design spec for the remaining #1899 items after Parts A (#2179) and B (#2452):
proactive near-expiry SVID/CA detection (advisory WARN via k8s:health), Kind-only
SPIRE TTL right-sizing, and a 503-after-suspend troubleshooting doc.

Assisted-By: Claude Code
Signed-off-by: cwiklik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants