The collation repair ran at the end of the post-upgrade init-job and, when the image moved, waited for the primary to run it. Helm starts that hook as soon as the Cluster is patched; CNPG then rolls the replicas first and the primary last, and every instance whose clients hold sessions sits in smart shutdown for smartShutdownTimeout (180s on existing clusters). With three instances the wait took about eight of the Job's nine minutes, the Job printed "the init-job is out of time, the next run of it carries on" and the HelmRelease went UpgradeFailed until Flux retried. When the Job's psql met the primary restart instead, it failed with "FATAL: the database system is shutting down" and failed the upgrade the same way. A rebuild of a large index does not fit the hook budget either. Moving the repair into an ordinary manifest does not help: helm-controller waits for every Job of a release to complete within the same upgrade timeout. So a short post-upgrade hook, run after the init-job, creates the repair Job through the API, outside the release, and returns. The repair Job has an hour, keeps the wait for the new image and the resume marks it had, and is owned by the Cluster. It has a fixed name, so two repairs never run against one Cluster: the hook leaves one still running on the same image alone and deletes any other, waiting for its pod to go, before creating the new one, which also retries a repair that failed. The hook's Role reaches only that Job and the release's Cluster by name, apart from create, which RBAC cannot narrow, and is deleted once the hooks succeed. psql exits with status 2 both when an instance refuses connections while shutting down and when it drops a session, so both Jobs now rerun their script after a growing pause on that status instead of failing; the scripts are idempotent and their elapsed-time bounds keep counting across attempts. A connection lost during an index rebuild is reported the same way. smartShutdownTimeout stays as it is: the repair no longer waits inside the hook, so the rollout's length does not matter. The PostGIS extension update waits for the same rollout, so it moves into the repair Job with the collation pass, and the messages of both name the next upgrade of the release as what starts them again. A lost connection in the PostGIS pass is reported with the same status as in the collation pass, so the Job reconnects instead of giving up. The repair runs after install as well. The init-job used to record there which Debian release each database started on, and without that record the first image move is detected only if the repair reaches the primary before it restarts. The Job sets PGCONNECT_TIMEOUT, so a primary that does not answer is retried instead of using up the Job's deadline. A failed index rebuild no longer stops the PostGIS update that follows it: a unique index that duplicates keep from being rebuilt would otherwise hold the extensions back until an operator removes them. The Job still fails at its end. With an hour to spend, the repair now waits for the new image whenever the image changes, not only when an index already depends on a versioned collation. Otherwise it planned on the previous primary, missed an index created meanwhile, and the release it recorded at the end claimed that index repaired. The repair Job carries the WorkloadMonitor's selector labels, opts in to having its failure reported with workloads.cozystack.io/report-failure, and has no ttlSecondsAfterFinished, so a failed repair stays visible until the next upgrade replaces it instead of vanishing while the indexes stay wrong. Refs: #5459 Assisted-By: LLM Signed-off-by: Andrey Kolkov <androndo@gmail.com>
Chainsaw E2E tests
The Cozystack E2E app suite, written for Kyverno Chainsaw — a declarative, Kubernetes-native E2E test framework (CNCF, part of the Kyverno project; successor to KUTTL).
This directory replaces the per-app BATS suite that used to live in hack/e2e-apps/*.bats. The CI e2e job runs every suite under hack/e2e-chainsaw/ through hack/e2e-chainsaw-run.sh after make install-cozystack; cluster bootstrap (hack/e2e-prepare-cluster-container.bats, hack/e2e-install-cozystack.bats) and the OpenAPI checks (hack/e2e-test-openapi.bats) remain BATS.
Layout
hack/e2e-chainsaw/
├── .chainsaw.yaml # global Configuration (namespace, timeouts, JUnit report)
├── _lib/ # shell reused by the script-heavy suites
│ ├── run-kubernetes.sh # tenant Kubernetes bringup + LB/NFS/ouroboros checks
│ └── remediation-guard.sh
├── <app>/
│ ├── chainsaw-test.yaml # one or more Test definitions
│ └── <app>.yaml # the manifests the test applies
└── ...
A suite is a directory directly under hack/e2e-chainsaw/ in or below which Chainsaw finds a Test. Three layouts do that, and the selector (hack/select-e2e.sh) and the leak-guard allowlist both recognise the same three:
chainsaw-test.yaml, the usual one, orchainsaw-test.ymlwhen the.yamlis absent;- numbered step files such as
01-install.yaml, which Chainsaw turns into a Test on its own when neither of the above exists; - either of those in a subdirectory of the suite, since Chainsaw walks every subdirectory of the directory it is handed.
A parked chainsaw-test.yaml.disabled is none of these: the directory is then not a suite, is selected by nothing and cannot be allowlisted.
Suites: postgres, bucket, mariadb, mongodb, redis, valkey, qdrant, clickhouse, kafka, kafka-metadata, rabbitmq, etcd, openbao, harbor, foundationdb, external-dns, kuberture, vminstance, gateway, opensearch, monitoring, kubernetes-latest, kubernetes-previous, securitygroup, seaweedfs, computeplane, observability-proxy. kubernetes-proxmox is parked as chainsaw-test.yaml.disabled and runs only in .github/workflows/e2e-proxmox.yaml, which needs a Proxmox hypervisor.
What Chainsaw buys over the BATS suite
- Readable tests — a list of resources and expected states, not shell control flow. The
timeout N sh -ec "until kubectl get ..."+kubectl waitpair that appeared ~100 times collapses into a singleassertthat polls existence and state together. - Distinguishable failure modes — "object never created", "created but never ready", and "wrong status" all surface as a structured diff instead of an opaque shell timeout.
- Automatic diagnostics —
catchblocks dump events,describe, and pod logs on any failure (the BATS suite only did this inharbor.bats, by hand). - Automatic cleanup — resources Chainsaw applied are deleted (and waited on) in reverse order;
finallycovers operator-created leftovers. - CI-ready output — a JUnit
chainsaw-report.xmlis emitted for the test summary.
Test anatomy
Each suite is a directory with one or more Test docs (in one of the layouts above, usually a chainsaw-test.yaml) plus the manifests it applies. A step has try (operations: apply, assert, error, script, delete, …), optional catch (diagnostics on failure), and optional finally (teardown regardless of outcome).
Declarative suites assert on status.conditions and concrete fields. Inherently imperative suites keep their logic in script steps:
- openbao —
bao operator init/unsealviakubectl exec. - kuberture —
jqon Service annotations + external-dns split-horizon log assertions. - vminstance — a server-side dry-run eviction of the VM's launcher pod, checked against the VMI's
LiveMigratablecondition. - gateway — admission-rejection cases that need
kubectl --asimpersonation or error-message greps; the tenant apex is read from the namespacenamespace.cozystack.io/hostlabel at runtime so they pass on any host. - kubernetes-latest/previous — wrap
_lib/run-kubernetes.sh(Kamaji bringup, port-forward, LB/NFS/ouroboros). The scriptcds to the repo root (the test dir ishack/e2e-chainsaw/<suite>, so repo root is../../..).
Conventions / gotchas (Chainsaw v0.2.15)
- Condition asserts use the filter-as-list form, not the documented
[0]index:Thestatus: (conditions[?type == 'Ready']): - status: "True"(conditions[?type == 'Ready'])[0]: {status: "True"}idiom fails with "field not found in the input object". - A reading of a failure diff: the "actual" side is a projection onto the expected fields —
status: {}means the JMESPath expression failed, not that status is empty. Read the error line above the diff first. errorwith a bare resource ref (name only) asserts the resource does not exist (used for "PVC reclaimed", "no backup schedule", "child has no Gateway HR").scriptruns in the test directory with$NAMESPACEset to the config namespace (tenant-test).
Running locally
Requires a cluster with Cozystack installed and a tenant-test namespace (the environment hack/e2e-install-cozystack.bats produces). bucket and seaweedfs additionally need mc, nc, and jq on the host; kuberture/openbao/foundationdb/securitygroup/computeplane/kubernetes-latest/kubernetes-previous/vminstance need jq; observability-proxy needs curl and nc.
# install chainsaw
go install github.com/kyverno/chainsaw@latest # or: brew install kyverno/chainsaw/chainsaw
# run all suites (config picked up from .chainsaw.yaml)
cd hack/e2e-chainsaw
chainsaw test
# run a single suite
chainsaw test postgres/
kubernetes-latest/kubernetes-previous each bring up a full tenant Kubernetes cluster (~25 min, real worker nodes) and vminstance boots a nested VM — expect a long run for the full set.
CI integration
The e2e job in .github/workflows/pull-requests.yaml runs make -C packages/core/testing test-chainsaw (which execs hack/e2e-chainsaw-run.sh inside the e2e sandbox) and uploads chainsaw-report.xml. The runner calls chainsaw test once per suite directory, fails a suite whose pods outlive its cleanup by more than the default timeouts.cleanup (LEAKED-PODS suite=<dir> in the log; see docs/agents/e2e-testing.md §8 and _lib/leak-allowlist.txt for known, filed leaks), and merges the per-suite reports into that one file. A local chainsaw test as shown above runs the same tests without the leak check. The sandbox image (packages/core/testing/images/e2e-sandbox/Dockerfile) ships the chainsaw binary alongside kubectl/helm/mc/jq/nc, built from source with a patch that keeps an assert polling through transient API errors such as an etcd leader change; a released chainsaw run locally fails the assert on the first such error instead.