The failure snapshot selected pods by their STATUS column, so a pod whose container runs while its readiness probe never passes -- STATUS Running, READY 0/1 -- was dropped from the report entirely. That is a common way for a suite to time out: the replica never joins, its owning HelmRelease sits in InProgress, and the artifact carries no trace of the pod the run died on. Select on the READY column instead, which also covers the partially ready multi-container case, and keep every phase that was collected before. On one degraded cluster that is four of the seven broken pods the old filter reported nothing about. The VMI and VM sections had the same blind spot and now share one selector that reads READY as the last field, because a Pending object prints fewer columns than a Running one and the two kinds differ only in how many columns precede READY. READY counts ready containers rather than the pod's Ready condition, so a pod held back by an unsatisfied readiness gate is out of scope; a test pins that rather than leaving it to be found in an empty directory. Logs are requested for every container of a selected pod rather than skipped for Pending ones, and the per-pod collection moved into a helper so it can be driven against a stub kubectl. kubectl's refusal is the finding, and an empty result is ambiguous on its own: a read against an unscheduled pod exits 0 having printed nothing, which is what a container that started and stayed quiet also leaves. Every site that classifies a failed read now orders its branches the same way, naming the timeout first where both a cutoff and an uncapturable stderr apply. The CRD gate in the summary had no such branch at all: it returned in silence, which is byte-identical to the CRD being absent, so every section behind that gate vanished from a report whose only real problem was that the machine writing it had nowhere to put a temp file. Collection used to stop silently. A walk that hit its cap said so in the job log and nowhere in the artifact. Now the pod walk leaves COLLECTION-TRUNCATED.txt when it stops at COZY_REPORT_PODS_MAX or COZY_REPORT_PODS_BUDGET, CONTAINER-LOGS-TRUNCATED.txt on a pod cut off part way through, COLLECTION-FAILED.txt when the pod list never came back rather than the empty tree a healthy cluster produces, and COLLECTION-UNBOUNDED.txt when timeout is missing locally, which is a fact about the machine writing the report and not about the cluster. Tenant namespaces are collected first, so a cap that only bites on a broadly degraded cluster is not spent on platform pods while the pod the suite died on falls off the end. Container logs are read with --tail=2000 where they were previously read whole, and every bounded file states the bound it was written under, because --tail drops the oldest lines and nothing else in the output would say so. COZY_REPORT_POD_TAIL=-1 restores the complete log. The bounded whole-object read no longer merges stderr into pod.yaml, vm.yaml and vmi.yaml, which are read by yq rather than by eye: a warning on an otherwise complete read left an unparseable file. stderr goes to a scratch file and is copied in only when kubectl returned no object, and the truncation markers those files carry are written as YAML comments, since a bare marker line after a complete mapping is a second top-level node. Six latent faults surfaced while making these reads report. The kamaji module was gated on the LINSTOR controller, so a cluster without LINSTOR got no kamaji evidence at all, which is what a tenant-kubernetes bootstrap timeout needs most. The Flux sources section nested one jsonpath filter inside another, which kubectl rejects outright, so it printed nothing on every report ever taken and read as "all sources Ready". The HelmRelease listing took a single field as STATUS where STATUS is the Ready condition's whole message, so every failed release rendered as one word. The services section filtered for a pending LoadBalancer address on the CLUSTER-IP column, which never carries that value. The cozystack module read its image from a Deployment the installer stopped shipping when it moved to the operator, putting kubectl's NotFound in the first file of the report. And the cozystack apps section gated all three of its kinds on a CRD in an aggregated API group, so it never ran once; two of those names were wrong, and both are collected again. The tests avoid EXIT-trap cleanup, and e2e-testing.md says why: a bats test that installs one and then fails prints no TAP line at all, so output grepped for `not ok` reads as green, while hack/cozytest.sh reports the same failure correctly. A guard enforces that over a named list of files rather than a glob with exceptions, because a list of exceptions is the same claim written so that forgetting to shorten it makes it false. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
29 KiB
E2E Testing Conventions
Guidance for writing, changing, and reviewing Cozystack's end-to-end (E2E) tests and the CI that runs them. Read this before touching anything under hack/e2e-chainsaw/, the bootstrap/OpenAPI BATS (hack/e2e-*.bats), hack/*.sh test helpers, the E2E CI workflow (.github/workflows/pull-requests.yaml), or packages/core/testing/.
The app suite is Kyverno Chainsaw (hack/e2e-chainsaw/, one directory per app, each with a chainsaw-test.yaml). Cluster bootstrap (hack/e2e-install-cozystack.bats, hack/e2e-prepare-cluster.bats) and the OpenAPI checks (hack/e2e-test-openapi.bats) remain BATS.
The core principle
Retries do not recover flakes — they hide deterministic bugs and triple diagnostic wall-time. An audit of 30 PR runs found that across sampled failures, 25/25 retry attempts failed: the retry loop never once turned a red run green, it only delayed surfacing real bugs (Helm namespace conflicts, seaweedfs/harbor races, a vminstance disk race) that looked like flakes because the retry sometimes coincided with transient state clearing.
Every convention below follows from that finding: fail fast, fail loud, make the failure legible. A test that flakes is a test (or a product) with a real race to fix, not a test to wrap in a retry. Chainsaw's per-assertion polling is the structural expression of this: each assert waits on its own condition to its own timeout, and a failure is reported as a structured diff plus auto-captured events/describe/logs — not a generic non-zero exit.
Conventions
1. No retries on deterministic steps; retry only pure infrastructure
Run E2E testsandInstall Cozystackrun once. On failure they print❌ ... (no retry — see diagnostics below)and dump state. Do not reintroduce a retry loop around them. The E2E step is a singlechainsaw testinvocation — there is no per-app retry loop to bring back, because Chainsaw already polls each assertion to its own timeout.Prepare environmentkeeps its 3× retry — and only it — because it is pure infrastructure (Talos image download, sandbox VM boot, network) where a transient runner hiccup is a genuine flake with no application logic involved.- Rule of thumb: retry is justified only for a step that contains no product or test logic.
2. Prefer declarative asserts over imperative waits
A Chainsaw assert polls until the resource matches its expected shape or the per-operation timeout fires, so it subsumes both "the resource exists" and "the field/condition reached this value" in one operation — the old until kubectl get …; do sleep 2; done existence backstop followed by kubectl wait --for=… is no longer needed.
- assert:
timeout: 6m
resource:
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: postgres-test
status:
(conditions[?type == 'Ready']):
- status: "True"
- Condition checks use the filter-as-list form
(conditions[?type == 'Ready']). Chainsaw v0.2.15 throws "field not found" on the indexed(...)[0]form. - Imperative checks that no Kubernetes API condition models — S3 reachability through a port-forward, an external LB HTTP path, MetalLB advertisement — stay in a
scriptstep. A baresleep Ninside such a script is allowed only when nothing better models the wait; annotate it with aTODO(e2e-replace-fixed-timeouts):comment. The bootstrap BATS (hack/e2e-install-cozystack.bats,hack/e2e-chainsaw/_lib/run-kubernetes.sh) carries the sanctioneduntil kubectl getexceptions.
3. Let Chainsaw own cleanup; no test-level EXIT/RETURN traps
Trap-based cleanup was the single biggest source of false failures in the BATS suite: an EXIT trap ran cleanup in a context where shell variables were unset, set -u killed it, and a successful test was marked failed — then retried twice into real failures.
- Chainsaw deletes the resources it
apply-ed during its cleanup phase (bounded by thedelete/cleanuptimeouts inhack/e2e-chainsaw/.chainsaw.yaml). Do not hand-roll teardown for resources Chainsaw created. - A self-contained
trap '… ' EXITinside a singlescriptstep — to kill a port-forward or remove a temp dir — is fine, because it runs in a contained subprocess with its variables in scope. Seehack/e2e-chainsaw/bucket/chainsaw-test.yaml. What is banned is test-level trap-based cleanup of the BATS kind. - The ban extends to the unit BATS under
hack/*.bats, for a second reason worth knowing before you debug one: anEXITtrap inside an@testbody replaces the one thebatsbinary installs for its own bookkeeping, and a test that then fails prints no TAP line at all. It does not appear asnot ok; it disappears, and the run ends with# bats warning: Executed N instead of expected M testsand a non-zero exit. Verified with Bats 1.14.0. Anyone reading the tail of the output, or grepping it fornot ok, sees a green suite — and the CI runnerhack/cozytest.sh, which is not thebatsbinary, reports the same failure correctly, so the two disagree exactly when it matters. Clean up at the end of the test body instead: both runners set-e, so the cleanup is unreachable on failure and the scratch directory is left behind for inspection, which is what you want from a failed test anyway. When a suite reports zero failures, confirm it also reports how many tests it ran: an exit code answers "did anything fail", never "did anything run". A guard test inhack/cozyreport.batsenforces this over a named list of files, which grows as the remaining ones are converted; a file not yet on that list may still carry a trap, so reconcile its1..Nplan against itsokcount before believing a green-looking run.
4. Do not mask cleanup or teardown failures
- Resources a test creates that Chainsaw cannot reclaim — because a controller, not the test, owns them (e.g. the Velero
Backup,BackupStorageLocation, and credentials secret incozy-veleroin the disabledhack/e2e-chainsaw/backup/suite) — must be pruned explicitly. Do not|| trueover a stuck delete and leave stale state for the next run. - For nested tenants, tear down child → parent with a hard wait for deletion between each. Deleting the parent while a child is still uninstalling wedges the parent's cleanup Job on the child namespace, and both stuck uninstalls occupy helm-controller workers past the end of the test — starving whichever suite runs next. The kubernetes suites encode this ordering in
hack/e2e-chainsaw/_lib/run-kubernetes.sh.
5. The install gate must have teeth
The install test fails if any HelmRelease is not Ready. A toothless gate (backgrounded kubectl wait discarding child exit codes + a bare echo instead of exit 1) once shipped a permanently-failing platform HR through green CI for weeks.
- Use a single
kubectl wait hr --all -A, then an outcome-based re-list (covers HRs created after the snapshot), andexit 1on any non-Ready HR. - Dump the full Ready-condition message per non-Ready HR so the real error is in the test output. See
hack/e2e-install-cozystack.bats.
6. Assert the parent HelmRelease did not remediate — via status.history
A parent HelmRelease that hit its wait timeout, uninstalled, and reinstalled is a silent race we want to catch. Do not check .status.installFailures / .status.upgradeFailures: Flux's ClearFailures() zeroes those on every successful reconcile, so checking them after the HR is Ready is vacuous and passes against a reverted fix.
- Inspect
.status.historyinstead — afailedoruninstalledSnapshot survives a later successful reconcile. Use the shared helper inhack/e2e-chainsaw/_lib/remediation-guard.sh(helmrelease_has_remediation_cycle) from ascriptstep.
7. Test-Impact Analysis (TIA), default-on
hack/select-e2e.sh walks the packages/core/platform/sources/*.yaml dependency graph and runs only the Chainsaw suites affected by a diff. A suite is a directory under hack/e2e-chainsaw/ containing a chainsaw-test.yaml.
- Conservative escalation: edits to
packages/library/,packages/core/,api/,cmd/,internal/, top-levelhack/*.sh|*.batshelpers, the sharedhack/e2e-chainsaw/_lib/, the chainsaw confighack/e2e-chainsaw/.chainsaw.yaml, theMakefile, or the E2E workflows escalate to the full suite. A per-suite edit (any file underhack/e2e-chainsaw/<app>/) selects only that suite. - The
full-e2ePR label forces the whole suite. - The selection is passed to
make test-chainsaw CHAINSAW_SUITES="<names>", which runschainsaw test <names>fromhack/e2e-chainsaw/(empty = the whole suite). - The coverage gap TIA opens on PRs is closed at release-cut time: the "Prepare release" commit bakes image digests into
packages/core/(and other packages), which TIA escalates to the full suite — so the release PR exercises the whole suite against the commit the tag will point at.
When adding a new app package, confirm select-e2e.sh maps it correctly (it has a unit test, hack/select-e2e_test.bats). A new app whose suite directory does not yet exist will not be selected — add hack/e2e-chainsaw/<app>/chainsaw-test.yaml first.
What TIA does and does not do
Be precise about TIA's scope — it is narrower than "skip E2E for unrelated PRs," and the wiring has consequences worth knowing before you rely on it or change it.
- It trims only which suites
chainsaw testruns, not the expensive stages.Prepare environmentandInstall Cozystack(the full platform install) run regardless of the selection. TIA only decides theCHAINSAW_SUITESpassed to the final E2E step. A perfect narrow saves the suite tail, not the bulk of wall-time. (Package image builds are scoped separately — byhack/build-matrix.sh, on the PR diff — while the Talos and installer/finalize legs still run for non-docs PRs; that is a distinct mechanism from TIA's suite trimming.) Select E2E testsruns afterInstall Cozystackand has noalways(). GitHub implicitly ANDs a step'sif:withsuccess(), so if install fails the selector (andRun E2E tests) are skipped entirely. On a red install you will not see TIA narrow anything — that is the ordering, not a selector bug.- Most PRs legitimately escalate to the full suite. Platform manifests live under
packages/core/, Go underapi//internal/, helpers underhack/, plus theMakefile— touching any one triggers the full suite. So "all suites selected" is usually correct, not a failure to narrow. - Two skip layers, with a gap. The
planjob computes a coarse docs-only gate (code, true for any change outsidedocs/**) that skips the whole build+E2E pipeline for docs-only PRs, plus a per-package build matrix (hack/build-matrix.sh) that scopes which images build. TIA's finer skip (select-e2e.shignoringdocs/,dashboards/, and*.md) only trims the suite selection. A PR touching onlydashboards/*.jsontherefore still runs install, then skips just the Chainsaw suites — near-zero savings. If you need such PRs to skip the pipeline, widen theplandocs-gate, notselect-e2e.sh.
8. Failure must be self-explanatory — diagnostics are first-class
- On install failure, the CI step dumps
kubectl get hr -A -o wide, adescribeof each non-Ready HR, and sorted events, all under collapsible::group::blocks. - On E2E failure, the CI step dumps
kubectl get hr -A, sorted events, and COSI bucket/claim/access readiness columns (those CRDs ship no printer columns, so plaingetshows only NAME/AGE). Thechainsaw testrun is one step, so this dump is at run level; Chainsaw's own per-Testcatchblocks add scoped events/describe/podLogs for the failing suite. - Inside a suite, attach scoped diagnostics with a top-level
catch:block (events,describe,podLogs,get) rather than letting a bare assert failure through — seehack/e2e-chainsaw/bucket/chainsaw-test.yamlandhack/e2e-chainsaw/harbor/chainsaw-test.yaml. This replaces the BATS... || { echo …; kubectl get/describe …; false; }idiom. make collect-report→hack/cozyreport.shuploads a fullcozyreport.tgz(operator/Flux/cert-manager logs, LINSTOR, Kamaji, Talos dmesg, COSI YAML) on every run, and the Chainsaw JUnit report (chainsaw-report.xml) is uploaded as its own artifact.- The report's per-pod evidence, under
kubernetes/pods/incozyreport.tgz, is selected by the READY column rather than by STATUS — so a pod left at0/1 Runningby a readiness probe that never passes is in scope, where before it was not. In scope is not the same as collected: the walk stops atCOZY_REPORT_PODS_MAXpods orCOZY_REPORT_PODS_BUDGETseconds, and what it did not reach is named in the artifact rather than dropped in silence, as the next point describes. Selecting on the STATUS column alone drops exactly that pod, and it is a common way for a suite to time out: the replica never joins, its HelmRelease sits inInProgress, and the artifact carries no trace of the pod the run died on. TerminalSucceeded/Completedpods stay excluded, since they legitimately end unready. Widening the selection and capping the walk are only safe together if the widening cannot displace what the uncapped walk always kept, so the collection order splits by evidence class before namespace: every pod that is notRunning— a crash loop,Pending,Error, the class the collector took before this — is ordered ahead of every pod that isRunningbut unready, andCOZY_REPORT_PREFER_NSorders within each of those two classes rather than across the whole selection. Otherwise a failed install with more not-Ready pods than the cap spends it on newly-in-scope tenant pods and drops the container logs of the platform pod that is actually crashing. - Every bound that the report's pod collection hits is named in the artifact, not only in the job log. The pod walk stops at
COZY_REPORT_PODS_MAXpods orCOZY_REPORT_PODS_BUDGETseconds and leavesCOLLECTION-TRUNCATED.txtnaming whichever fired; a pod it cut off part way through leavesCONTAINER-LOGS-TRUNCATED.txt; a pod list that never came back leavesCOLLECTION-FAILED.txtrather than the empty tree a healthy cluster produces; a missing localtimeoutleavesCOLLECTION-UNBOUNDED.txt, because the reads still run, just without a ceiling, and a missing dependency on the machine writing the report is not a statement about the cluster; a kind this cluster does not serve at all —kubectl get vm -Aon an install without KubeVirt, which exits non-zero — leavesKIND-NOT-SERVED.txtrather than a failure marker, since that is the cluster answering correctly and a marker that fires on healthy installs is one a reader learns to skip; and a knob value the collector could not use is named too, appended toCOLLECTION-TRUNCATED.txtwhen there is one, written toCOLLECTION-NOTES.txtwhen there is not, and appended toCOLLECTION-FAILED.txtinstead when the pod list itself never returned, so the note always sits beside the failure it accompanies rather than in a file the reader has no reason to open, and a bound that turns out to be the default is not mistaken for the bound that was asked for. A pod whose container list came back as a prefix — kubectl named some containers and then failed — leavesCONTAINER-LIST-INCOMPLETE.txtbeside the logs it did manage to read, because the containers it never named have no file at all and their absence would otherwise read as containers that were silent. A read that succeeded while kubectl also wrote to stderr — a deprecation notice, a partial-result warning — leaves that message inREAD-WARNINGS.txtbeside the object rather than inside it, sincepod.yamland the logs are machine-read and a warning line in them costs the parser the file, while dropping it altogether would be the silent loss of evidence this tree exists to prevent. A pod directory whose containers produced any log at all also carriesCONTAINER-LOGS-BOUND.txt, naming the--tailbound those logs were written under (a pod whose every container was silent has no bounded log to describe, so the file is absent), because--taildrops the oldest lines and nothing in a log says so; it sits beside the logs rather than inside them, since a log read in full is a complete artifact and the platform's controllers log JSON per line, so a trailing prose line would break every parser that could read the file before. A pod whose container list could not be read leaveslogs-UNAVAILABLE.txtin its own directory, carrying kubectl's reason, because a pod directory holdingpod.yamlanddescribe.txtand no logs at all otherwise reads as a pod whose containers were silent. The VM, VMI and services loops carry the same pair of bounds as constants rather than knobs, so a failed install that leaves every LoadBalancer without an address collects the first of them and names the rest instead of running the report step past the job's own limit, which would lose the tarball rather than truncate it. Whichever bound stopped a walk says so inCOLLECTION-TRUNCATED.txt, count and clock alike, because objects removed by the clock while the count note stood alone would read as a cap that never fired. The read that feeds each loop is bounded too: the budget cannot start until rows arrive, so an apiserver hanging on the cluster-wide list would otherwise spend the whole collection step with the deadline never consulted. The budget is a deadline for starting a read rather than for finishing the walk, and it is rechecked between containers but not between a container's current and previous log, so the ceiling is the budget plus one pod's object reads plus both log reads of one container, which is the price of never leaving a half-written file behind. COZY_REPORT_POD_TAILbounds each container log at 2000 lines by default, and a log that was read successfully records which bound it was written under, since--taildrops the oldest lines and a file that begins mid-stream looks exactly like a complete one;-1restores kubectl's own default of the whole log.COZY_REPORT_PREFER_NS(defaulttenant-) is collected first, so a cap that only bites on a broadly degraded cluster is not spent on platform namespaces while the pod the suite died on falls off the end.- Capture the PREVIOUS container instance, not just the current one. For a crash-looping pod
kubectl logs(and the ChainsawpodLogscollector, which in v0.2.15 has nopreviousoption — it does acceptname/namespace/selector/container/tail/timeout/cluster/clusters) shows the Nth restart — a fresh replay of the same startup path — while the evidence that explains the failure sits in the immediately preceding instance, reachable only via--previousand lost for good once the kubelet garbage-collects that container.hack/e2e-capture-previous-logs.shcloses this once for every suite from the globalerror.catch(and fromhack/cozytest.shfor the BATS tests) rather than per-suite: it discovers containers withrestartCount > 0at runtime — init containers included, since an interrupted bootstrap lives there — orders the app suites'tenant-testnamespace first (a best-effort ordering only — it never restricts the capture, and for a suite whose pods live in a child tenant namespace it simply degrades to input order), and dumps each to the job log and tosnapshots/<test>/previous-logs/. Containers that never restarted are skipped, so a healthy run emits one line, not a page of "previous terminated container not found". Every way the capture can come up short is named rather than inferred: theCOZY_PREVLOG_MAXoverflow, a malformed cap, aCOZY_PREVLOG_TAILthat was rejected and fell back to 200 (a zero or leading-zero tail asks kubectl for nothing, which would otherwise be reported as the container having logged nothing), the tail bound each kept log was written under — named incapture-notes.txtbeside the logs rather than inside them, since--taildrops the oldest lines and nothing in the output says so while a log read in full is a complete artifact that a trailing prose line would stop any parser from reading, and suppressed on-1because no bound was applied then — a pod list that never returned (which is NOT the same as "nothing restarted" and must not be reported as such), a read that timed out versus one kubectl itself refused (kubelet GC, RBAC, an unreachable node — different problems that a blanket "kubelet GC" line would hide), a previous instance that produced no output, and a capture the outer backstop cut short. A partial log is kept and marked truncated, never deleted — it is the only copy of something already gone from the cluster. Each of those lines the script itself emits is written tosnapshots/<test>/previous-logs/capture-notes.txtas well as to the job log, and the directory is created before the first of them, so a reader who has only the uploaded artifact can still tell a capture that found nothing from one that never ran. The outer backstop firing is the exception: that line comes from the callers, after the script has already been killed, and reaches the job log only. - A catch script needs an explicit
timeout:that exceeds the inner budgets it contains. A Chainsawscriptop is bounded bytimeouts.exec(5m in.chainsaw.yaml) unless it overrides it, so a catch whose owntimeout -k …wrappers sum past that is structurally guaranteed to be killed — it reportsSCRIPT | ERROR | signal: killedand yields nothing. That kill is strictly worse than an innertimeoutfiring: SIGKILL takes out the process group, so the collector dies mid-write and every later step in the script is skipped, whereas an innertimeoutexits 124, leaves a partial capture on disk, and lets the rest of the catch run. Size the op timeout above the sum of the inner budgets and let the inner ones be what fires. - Set
crust-gather --durationexplicitly. It is crust-gather's own budget for the collection phase and it defaults to 60s; on elapse it abandons the collection and skips its finish step, leaving a partial tree with nothing to say the rest is missing. The outer wall-clock must exceed it, because the API discovery crust-gather runs first is not covered by that budget at all — with an unhealthy aggregated APIService (the state a failed e2e is usually in) aggregated discovery times out and the fallback re-walks every group, which can consume the entire outer timeout before a single object is written. Do not diagnose a killed snapshot by bumping the outer number alone; the two budgets bound different phases. Send the collector's output to a log inside the snapshot rather than/dev/nullso "complete or truncated?" is answerable from the artifact. - Per-failed-test crust-gather snapshots are the richest diagnostic — a
crust-gather serve-able archive of the cluster at the moment of failure, before cleanup. The globalerror.catchinhack/e2e-chainsaw/.chainsaw.yamlcaptures the host cluster into_out/cozyreport/snapshots/<test>/hoston any failure (the Chainsaw analog of thehack/cozytest.shEXIT-trap snapshot used by the BATS tests); the kubernetes suites additionally snapshot their tenant cluster fromhack/e2e-chainsaw/_lib/run-kubernetes.shwhile the tenant API LB is still routable.hack/cozyreport.shfoldssnapshots/into the artifact. Do not remove the global catch — without it the Chainsaw suite uploads a report with no per-test cluster state.
9. Keep the test environment deterministic
- Pre-pull every kubeovn / linstor / cert-manager image onto all nodes before those HelmReleases install (
hack/e2e-prepull-images.sh), so clustered workloads (OVN raft, LINSTOR, the cert-manager webhook) do not fail on per-node image-pull stagger. - Exclude loop devices from host LVM scanning in the Talos machine config so the host does not activate volume groups inside loop-mounted e2e disk images.
- Fail fast on node readiness (≈5m, then bail) rather than marching into LB/NFS tests that will also fail — it saves several minutes per attempt and keeps the real failure at the top of the log.
Chainsaw v0.2.15 gotchas
The suite is pinned to Chainsaw v0.2.15 (the latest release as of May 2026); none of the traps below are fixed upstream yet, so the workarounds stay until a bump is possible. Each one has already cost a debugging session — this is the "no one gets it right the first time" list, worth a read before writing a new assert.
- Condition asserts must use the filter-as-list form.
(conditions[?type == 'Ready'])evaluates to a list; assert against it with a list body (- status: "True"). The indexed(conditions[?type == 'Ready'])[0]form throwsfield not found(also enforced by convention 2). - No number literals / backticks in JMESPath.
ports[?port == `443`]mis-evaluates in v0.2.15 — the numeric comparison silently returns the wrong set. Assert ports (and any numeric field) with the exact-ordered projection form instead:(ports[*].port): [80, 443].sort()andcontains(list, <number>)are likewise broken with numeric arguments. error:fails hard on an unknown GVK. Unlike the BATS! kubectl get <kind>idiom (which passes when the type is absent), a Chainsawerror:op against a kind whose CRD is not installed errors the step rather than asserting absence. If a type may legitimately not exist (a version rename, an optional component), gate the check behind a positive precondition or do it in ascriptstep — never a bareerror:. This is what broke the etcd suite on thev1alpha1→v1alpha2rename.- No conditional Test-level
skip. There is noskip: <expr>; an env-var-gated test mustexit 0early inside ascriptstep (see theETCD_E2E_S3_ROUNDTRIPgate). A Test with no matching gate always runs. finallyis step-level, not test-level. To guarantee teardown of something Chainsaw did not create, put the work and its own cleanup in a singlescriptstep; there is no test-widefinallyblock to hang it on.- Cleanup is bounded and blocking — it surfaces latent teardown bugs. Chainsaw waits for the resources it applied to actually delete (within the
delete/cleanuptimeouts inhack/e2e-chainsaw/.chainsaw.yaml) and fails the test if they don't. This is deliberate — a stuck uninstall starves the next suite — but it means a teardown path the BATS suite masked with|| truenow surfaces ascontext deadline exceededat cleanup. The failure is honest, not new; fix the teardown rather than widening the timeout (see cozystack/cozystack#3271, a pre-delete hook that hung on a nodeless tenant). - Reading a failure diff: the "actual" side is a projection. Chainsaw projects the live object onto the expected fields, so
status: {}in a diff means "the expression matched nothing / evaluated empty," not "status is literally empty." The real reason is theerrorline above the diff — read that first. - A
catch/cleanupscript's cwd is the failing suite's directory (hack/e2e-chainsaw/<suite>/), so../../..is the repo root. The suitescd ../../..and then source shared helpers by repo-root-relative path (hack/e2e-chainsaw/_lib/…) rather than juggling../hops.
Reviewer checklist for a new or changed E2E test
- No new retry loop unless the step is pure infra (image pull / VM boot / network).
- Resource readiness uses a Chainsaw
assert(not an imperativeuntil kubectl get …; kubectl wait); condition checks use the filter-as-list form(conditions[?type == 'Ready']). - Imperative-only waits live in a
scriptstep; any baresleepcarries aTODO(e2e-replace-fixed-timeouts):justification. - No test-level
EXIT/RETURNtrap — rely on Chainsaw cleanup; a self-contained trap is allowed only inside a singlescriptstep (port-forward / temp dir). - Controller-created artifacts the test cannot reclaim are pruned explicitly; nested tenants delete child → parent with a wait-for-deletion between.
- Standard HR-Ready assert timeout is 5–6m; longer waits (harbor 10m, NFS 10m, VM image pulls, platform-wide install 15m) are justified in-line.
- Failure path attaches scoped diagnostics via a
catch:block, never a silent pass. - If it touches parent-HR behavior, add the
status.historyremediation guard (hack/e2e-chainsaw/_lib/remediation-guard.sh).
In-flight direction (not yet the merged standard)
These are being explored on branches and may become conventions; do not assume they are the current main behavior:
- Cilium orphaned-endpoint self-heal — an interim CI watchdog that evicts a single confirmed-orphan Cilium endpoint ("IP already in use", cilium/cilium#38313). Explicitly a mitigation to remove once a fixed Cilium ships; it refuses to touch an endpoint backing a live pod so real duplicate-IP bugs stay visible.
- Cluster state snapshot/restore between test groups instead of reinstalling.