Repository navigation
feat: feature-flagged mesh self-heal CronJob - #2452
Conversation
…1899) Part B of the mesh-wide-503 self-heal (Part A = scripts/k8s/mesh-recover.sh + skills, shipped in 0.7 via rossoctl#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]>
pdettori
left a comment
There was a problem hiding this comment.
Well-structured Part B of the mesh self-heal work. Verified: the chart copy of mesh-recover.sh is byte-identical to scripts/k8s/mesh-recover.sh (sync guard correct), the rossoctl.labels helper and .Values.openshift gate exist and match existing conventions, and the RBAC is tight and least-privilege (read + patch for rollout restart, named state ConfigMap, events create). Feature is off by default and Kind-only, so nothing here blocks merge.
The three inline suggestions are runtime-viability concerns on a path that hasn't been live-tested yet (live Kind test is a listed follow-up). None block merge, but all three should be resolved before meshSelfHeal.enabled is turned on:
- Event YAML breaks when it embeds the JSON
--jsonsummary (verified locally —kubectl create -f -rejects it), silently dropping the key Warning events. registry.k8s.io/kubectlvery likely has nocurl(and maybe nobash), which would make the probe a silent no-op.runAsNonRoot: truewith norunAsUsermay block pod admission if the image defaults to root.
Author: cwiklik (MEMBER — maintainer) · Commits: 1, signed-off · CI: passing (E2E HyperShift pending maintainer /run-e2e)
Assisted-By: Claude Code
| namespace: ${NS} | ||
| type: ${1} | ||
| reason: ${2} | ||
| message: ${3} |
There was a problem hiding this comment.
suggestion — The Event heredoc embeds the raw --json summary into an unquoted YAML scalar (message: ${3}), and several call sites pass ${summary} (MeshInconclusive rc=3, MeshCooldown, MeshRestartCapHit, MeshDegraded). Because the JSON contains :, kubectl create -f - fails to parse it — I reproduced this locally and it errors with "mapping values are not allowed here". That means those events silently hit the non-fatal || log "event emit failed" path and never get created — i.e. exactly the "loud Events" the design promises for kubectl describe cronjob are the ones that go missing. (MeshHealthy and MeshRecoverAttempted carry no summary, so they still work.)
Suggested fix: emit the message as a literal block scalar so the JSON can't break YAML:
message: |-
${3}(indented under the heredoc), or strip/escape the JSON before interpolating.
There was a problem hiding this comment.
Fixed in d088139. emit_event now flattens the message to one line and emits it as a literal block scalar (`message: |-`), so the `:`-laden JSON summary can't break the Event YAML. Verified live on kind-rossoctl: the `MeshDegraded` Event was created carrying the full `{"degraded":true,...}` summary. Confirmed the old plain-scalar form reproduces your exact error (`kubectl create` → "mapping values are not allowed in this context"), and the new form parses.
| # Cron schedule for the probe+remediate tick. | ||
| schedule: "*/5 * * * *" | ||
| # Stock image with bash + kubectl + curl (no custom image built for this). | ||
| image: "registry.k8s.io/kubectl:v1.31.0" |
There was a problem hiding this comment.
suggestion — registry.k8s.io/kubectl is a minimal (debian-base) image that very likely ships no curl, but mesh-recover.sh relies on curl to probe the gateway (check_mesh_reachability, curl calls at mesh-recover.sh:150,153). With no curl the probe returns 000 → INCONCLUSIVE, so the self-heal never fires — a silent no-op rather than a visible failure. bash may also be absent even though the CronJob runs command: ["bash", ...].
Since the live Kind test is a follow-up, this path is currently unverified. Please confirm the image actually has bash + curl at runtime, or switch to an image that bundles them (e.g. one with a shell + curl alongside kubectl).
There was a problem hiding this comment.
Fixed in d088139. You were right, and it's worse than "likely no curl": `registry.k8s.io/kubectl` has no shell at all (User=0, entrypoint `/bin/kubectl`, `sh` not found), so `command: ["bash", ...]` couldn't even exec. Switched to `docker.io/alpine/k8s:1.31.0`, which bundles bash + curl + kubectl (pinned, non-floating). Verified live: the wrapper exec'd, curl probed the gateway (503 → restart → 200).
| serviceAccountName: mesh-selfheal | ||
| restartPolicy: Never | ||
| securityContext: | ||
| runAsNonRoot: true |
There was a problem hiding this comment.
suggestion — runAsNonRoot: true is set without a runAsUser. If the chosen image's default user is root (UID 0), the kubelet rejects the pod at admission ("container has runAsNonRoot and image will run as root") and the CronJob never runs. Recommend pinning an explicit non-root runAsUser (and verifying the image supports running as that UID) so startup doesn't depend on the image's default user — this pairs with the image-choice question on values.yaml.
There was a problem hiding this comment.
Fixed in d088139. Pinned `runAsUser/runAsGroup/fsGroup: 65532` (the image defaults to root, so `runAsNonRoot` alone would fail admission). Also added a writable `HOME` emptyDir so kubectl's discovery cache works under `readOnlyRootFilesystem: true`. Verified live: the pod was admitted and Succeeded as UID 65532 with no runAsNonRoot rejection and no cache warnings.
…ossoctl#2452 review) Addresses the three runtime-viability findings from review on rossoctl#2452, all verified live on kind-rossoctl (which happened to be in the rossoctl#1899 degraded state, so the full detect -> restart -> re-probe path ran end to end): 1. Event YAML broke on the JSON summary. The --json summary contains ':', so interpolating it into a plain `message: ${3}` scalar made `kubectl create -f -` fail with "mapping values are not allowed here" — the very Warning Events the design promises were silently dropped. Flatten the message to one line and emit it as a literal block scalar (|-). 2. registry.k8s.io/kubectl has no shell and no curl, so `command: ["bash"]` could not exec and the curl gateway probe would no-op. Switch to docker.io/alpine/k8s:1.31.0, which bundles bash + curl + kubectl (pinned, non-floating). 3. runAsNonRoot: true without an explicit runAsUser lets the kubelet reject the pod at admission when the image defaults to root. Pin runAsUser/runAsGroup/fsGroup 65532. Also give kubectl a writable HOME (emptyDir) so its discovery cache works under readOnlyRootFilesystem. Verified: pod admitted and Succeeded as UID 65532; bash+curl ran the probe (503 -> rollout restart ztunnel + http-istio -> 200); MeshDegraded Event created with the full JSON summary embedded. mesh-recover.sh chart copy untouched (sync guard still passes); shellcheck clean. Assisted-By: Claude Code Signed-off-by: cwiklik <[email protected]>
…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]>
Summary
Part B of the mesh-wide-503 self-heal (#1899). Part A —
scripts/k8s/mesh-recover.sh+ thek8s:health/istio:mesh-selfhealskills — shipped in 0.7 (#2179). This adds the hands-off remediator: a feature-flagged CronJob (inrossoctl-deps) that periodically probes the gateway and, on a recoverable mesh outage (expired ztunnel/waypoint mTLS certs after a host suspend → HTTP 503 on all*.localtest.meroutes), runsmesh-recover.sh --fixwith cooldown / max-restart safety and loud Events.Part of #1899 (not Closes — #1899 stays open as the umbrella; the durable fix is upstream, istio/ztunnel#1679).
Design
meshSelfHeal.enabled(chart-level flag). Renders only on non-OpenShift — the ambient cert-expiry failure mode is Kind/dev-specific.mesh-recover.shunchanged (auto-discovers the ztunnel namespace + probe host; exit0healthy /2degraded /3inconclusive). Helm.Files.Getcan't read outside the chart, so a verbatim copy lives incharts/rossoctl-deps/files/, kept identical byscripts/check-mesh-recover-sync.sh.mesh-selfheal-wrapper.sh) adds only scheduling + safety: detect → cooldown / max-restart(rolling-window) gating (persisted in a small state ConfigMap) →--fix→ k8s Events. Probes the in-cluster gateway Servicehttp-istio.rossoctl-system.svc.istio.io/dataplane-mode: none) so its ownkubectlcalls don't traverse the broken ztunnel it's repairing;concurrencyPolicy: Forbid; nonroot / read-only rootfs / drop-ALL; least-privilege RBAC (get/list + patch deployments+daemonsets forrollout restart; state ConfigMap get/patch; events create).Files
charts/rossoctl-deps/values.yaml—meshSelfHealblock (flag, schedule, image, gatewayUrl, cooldown/max/window, resources).charts/rossoctl-deps/files/mesh-recover.sh— verbatim copy of the Part A engine.charts/rossoctl-deps/files/mesh-selfheal-wrapper.sh— the scheduling/gating/Events wrapper.charts/rossoctl-deps/templates/mesh-selfheal.yaml— scripts CM + state CM + SA + ClusterRole/Binding + Role/Binding + CronJob, gatedenabled AND not openshift.scripts/check-mesh-recover-sync.sh—diff -qguard for the chart copy.Verification
helm template: OFF → no objects, ON+Kind → full set, ON+OpenShift → no objects (Kind-only gate).helm lintclean · wrapper shellcheck-clean · sync guard passing.Follow-ups (not in this PR)
scripts/check-mesh-recover-sync.shinto pre-commit.scripts/k8s/induce-mesh-outage.sh.Refs: Part A #2179 · umbrella #1899 · upstream istio/ztunnel#1679.
Assisted-By: Claude Code