Refs #5459 (item 1: `C.UTF-8` is not repaired and nobody is warned).
After the move to the `-standard-trixie` operand images, an index on a
`COLLATE "C.UTF-8"` column, or any text index in a database created with
`LC_COLLATE 'C.UTF-8'`, is silently corrupt: Debian bullseye's patched
`C.UTF-8` and the glibc 2.35+ `C.UTF-8` order characters differently,
but PostgreSQL records no collation version for `C.*` locales, so the
collation repair in the init Job never selected those indexes. On
PostgreSQL 15+ there was not even a warning. Lookups through such an
index miss rows, and a unique index on it stops seeing duplicates.
One commit. The repair pass now treats libc `C.<codeset>` collations,
and a libc `C.<codeset>` database default, as versioned by the Debian
release of the server's build (the `pgdgNN` suffix of `server_version`).
Their indexes then go through the existing resumable rebuild path (OID
mark, in-place handling for exclusion constraints, `_ccnew` leftovers,
unique-duplicate failure reporting), which this PR leaves unchanged.
Because PostgreSQL stores nothing to compare with, the release each
database was last repaired for is stored in a new per-database setting,
`cozystack.collation_release`, next to the existing
`cozystack.collation_repair`:
- a database without the setting gets the release of the server the pass
first sees it on. The pass looks before it waits for the rollout, so the
old release is persisted even if that run fails, and a retry that runs
after the primary restarted still rebuilds;
- if the server already runs the new glibc when the pass first sees the
database, a libc collation whose recorded version differs from the
server's (`en_US.utf8` 2.31 vs 2.41, present in every database created
from these images) marks it as not repaired for any release;
- otherwise (a new cluster, a database added later) the current release
is recorded and nothing is rebuilt;
- the setting is updated to the current release only when the database
is repaired without failures.
The PG<15 warning `database ... uses the locale C.UTF-8, for which this
PostgreSQL major records no collation version ...` no longer fires for
`C.*` locales, since those are now repaired. The range-partition warning
says for a `C.*` key that it is reported only once, instead of claiming
that a collation version was left as recorded.
The e2e postgres suite now also sets another release on its database,
creates a unique `C.utf8` column, and checks that the upgrade rebuilds
that index, that amcheck passes on it, and that the setting ends at the
server's release.
The change stays inside the `== refresh collation versions` SQL prelude
and its final block. It does not touch the rollout wait, the per-index
rebuild session or the extension section, which other open fixes for
A cluster where a pass without this change already ran on the new glibc
(v1.7.2-rc.1, or `main` since #5405) has already refreshed its libc
collation versions, so no trace of the move is left. This pass then
records the current release for it and does not rebuild its `C.*`
indexes. Rebuild those by hand with `REINDEX INDEX CONCURRENTLY` (or
`REINDEX DATABASE`), as the release note says.
description to rebuild indexes on `C.UTF-8` by hand. This PR merges
second, so it drops that sentence from `values.yaml`, `types.go`, the
README, the schema and the cozyrd: the init Job now rebuilds those
indexes itself.
Docker, no Kubernetes: data written on
`ghcr.io/cloudnative-pg/postgresql:17.7` / `13.22` (bullseye, glibc
2.31, `pgdg11`), then the same data directory started on
`17.12-standard-trixie` / `13.22-standard-trixie` (glibc 2.41,
`pgdg13`). The repair section was rendered with `helm template`,
extracted from the init-script Secret, and run from a container of the
trixie image with the env the Job sets (`PGHOST`, `PGUSER`,
`JOB_DEADLINE`). Data: 200,000 distinct keys mixing ASCII punctuation,
`é`, U+FFFD, U+FFFF, U+1D400 and U+1F600. Tables: a `UNIQUE` column
`COLLATE "C.UTF-8"`, an `en_US.utf8` column, a plain `C` column, and a
`cutf8db` database with `LC_COLLATE 'C.UTF-8'`.
| Scenario | Result |
| --- | --- |
| Pass from `main`, PG17 and PG13 | rebuilds only the `en_US.utf8`
index; `t_c_k_key`: `item order invariant violated`, 178,162 of 200,000
keys not found; `cutf8db.t_d_k`: 179,426 not found |
| This PR, Job starts on bullseye, server then restarts on trixie (PG17,
PG13) | `pgdg11` recorded while waiting; `C.UTF-8` column index,
`C.UTF-8` database default index and `en_US.utf8` index rebuilt; amcheck
ok, 0 misses; plain `C` index keeps its OID |
| This PR, first run times out waiting for the rollout, retry after the
restart (libc versions refreshed by hand in between so only the
persisted release can trigger) | retry rebuilds both `C.*` indexes;
amcheck ok, 0 misses |
| This PR, server already on trixie at first run | detected through the
stale libc collation versions; both `C.*` indexes rebuilt |
| Second and third run | nothing rebuilt, setting stays `pgdg13` |
| New cluster created on trixie | nothing rebuilt, `pgdg13` recorded |
| Range partitions on `C.UTF-8` and on `en_US.utf8` | partition indexes
rebuilt once; the `C.*` partition warned once; later runs rebuild
nothing |
`helm unittest packages/apps/postgres`: 31 suites, 247 tests passed.
Dev cluster (cozystack v1.7.0):
- Setup: an app installed from the v1.7.1 chart (`postgresql:17.7`,
bullseye, 2 instances). In `appdb`, a `UNIQUE` column `COLLATE
"C.UTF-8"` with 50,000 keys built from ASCII letters and punctuation,
`é`, U+FFFD, U+1D400 and U+1F600.
- `helm upgrade` to this branch passed on the first attempt. The init
Job logged `rebuilding index public.t_c_k_key in database appdb: its
collation changed version`.
- Afterwards:
- the Cluster runs `17.12-standard-trixie`;
- the index OID changed (16424 → 16507);
- `bt_index_check(t_c_k_key, true)` is clean on the primary, on the
replica and through `-ro`, with 0 lookup misses;
- `cozystack.collation_release` is `pgdg13`.
- A second upgrade rebuilt nothing.
The extended chainsaw e2e step has not run yet, so CI will be its first
run.
Docker, with the rendered repair pass run against
`17.12-standard-trixie` and `UNIQUE` columns `COLLATE "C.utf8"`:
- A database with no recorded release and a stale libc collation
(`CREATE COLLATION ... (provider = libc, locale = 'en_US.utf8', version
= '0')`): the index is rebuilt and `pgdg13` is recorded.
- A database whose only stale piece is its libc default collation
(`datcollversion` changed): the index is rebuilt, and `pgdg13` is
recorded.
- A fresh database: nothing is rebuilt, and `pgdg13` is recorded.
- A second run rebuilds nothing.
The e2e suite now also covers a database with no recorded release, the
state every existing cluster starts from. That database holds a stale
`en_US.utf8` libc collation and a `UNIQUE` column on `C.utf8`, and the
test asserts the new index OID, `bt_index_check`, and the recorded
release. A libc collation on locale `C` with an explicit version cannot
serve as the probe: `ALTER COLLATION ... REFRESH VERSION` refuses to
move it to the NULL version of a `C` locale.
- [ ] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:
The diff touches only
`packages/apps/postgres/templates/init-script.yaml` and the postgres e2e
test. No values, schema, README, API or CRD change, so none of the
generated reference docs move. Boxes are left empty for a maintainer to
decide: the website may describe the trixie move and its collation
repair in upgrade notes, and if it lists which collations get repaired,
`C.UTF-8` should be added there. I did not check that.
```release-note
[postgres] The init Job now also rebuilds indexes on libc `C.UTF-8` (and other `C.<codeset>`) collations, and on databases whose default collation is such a locale, when the server moves to an image built on another Debian release. PostgreSQL records no version for these collations, so before this fix such indexes stayed corrupt after the move to the standard-trixie images, with no warning. The Debian release each database was repaired for is kept in the `cozystack.collation_release` database setting. A cluster that already ran the previous repair on a trixie image (v1.7.2-rc.1 or a `main` build since the move) is not recognised: rebuild its indexes on `C.*` collations by hand with `REINDEX`.
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
* **Bug Fixes**
* PostgreSQL collation repair now detects changes affecting
`C.<codeset>` collations across PostgreSQL build releases, including
cases where PostgreSQL does not record collation versions. Affected
indexes are identified and rebuilt during repair.
* Partition-related warnings clarify when collation changes can or
cannot be detected. After repair, the process records the PostgreSQL
release to help identify when a later repair may be needed.
* **Documentation**
* Updated `allowCollationChange` guidance to explain that the
initialization process rebuilds indexes for `C.UTF-8` and other `C.*`
locales, removing the instruction to rebuild those indexes manually.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
(cherry picked from commit 0f84f1c8dc)
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. 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.
# 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.