Skip to content

k8s: CNPG CRD codegen — Cluster, ScheduledBackup, and the barman-cloud ObjectStore #1319

Closed

Description

@lex00

Part of #1318 · the largest of the four CRD gaps blocking a Fountain production deployment.

Repo/where. INTENTIUS/chant. All work in the k8s lexicon at lexicons/k8s/. Design rule: spec-true — type the real upstream API, no chant-flavored abstraction.

Goal. Code-generate typed CloudNativePG resources through the existing CRD codegen pipeline (the path that produced KubeRay, Argo, Gateway API, cert-manager, Flux), plus the barman-cloud plugin's ObjectStore.

Why these three kinds

BinaryBourbon/fountain's k8s/ overlay runs its Postgres this way, and all three are load-bearing:

  • postgresql.cnpg.io/v1 Cluster (k8s/postgres.yaml) — instances, imageName, bootstrap.initdb (database/owner/postInitTemplateSQL), storage (storageClass/size), resources, and the plugins[] block that wires WAL archiving (name: barman-cloud.cloudnative-pg.io, isWALArchiver: true, parameters.barmanObjectName).
  • postgresql.cnpg.io/v1 ScheduledBackup (k8s/scheduledbackup.yaml) — schedule (six fields, leading seconds, unlike vanilla cron), backupOwnerReference, cluster.name, method: plugin, pluginConfiguration.name.
  • barmancloud.cnpg.io/v1 ObjectStore (k8s/objectstore.yaml) — retentionPolicy, configuration.destinationPath/endpointURL/s3Credentials.{accessKeyId,secretAccessKey}/wal.compression/data.compression.

Without these, chant lifecycle diff --live reports the whole database tier as unsupported-kind unobserved. That is the correct behaviour and not a correctness bug — but it is a hole in the estate exactly where the stateful, hardest-to-recover component lives.

Backup and Pooler are cheap to add from the same base URL and worth taking while we are here; Database/Publication/Subscription are not needed by any known consumer, so leave them out rather than dragging in the whole group (see the "do not fetch a whole provider" note in crd-sources.ts).

Files to touch

  • lexicons/k8s/src/crd/crd-sources.ts — add a CNPG_VERSION const, a CNPG_CRD_BASE, a BARMAN_PLUGIN_VERSION const + URL, a doc comment listing the kinds and the operator-install command (mirror the KubeRay / cert-manager blocks), and the entries in CRD_SOURCES.

  • lexicons/k8s/src/crd/parser.ts — add to GROUP_NAMESPACE_OVERRIDES:

    • "postgresql.cnpg.io": "Cnpg"
    • "barmancloud.cnpg.io": "Cnpg"

    Required. The first-segment rule would otherwise produce K8s::Postgresql::Cluster and K8s::Barmancloud::ObjectStore. Mapping two groups onto one namespace is the established Flux pattern (five *.toolkit.fluxcd.io groups all map to Flux); the kinds do not collide.

  • lexicons/k8s/src/codegen/patches.ts — only if npm run generate fails. The CNPG Cluster schema is large and deeply nested (it embeds a full pod template); if it trips the recursion cap, add a targeted SchemaPatch like the existing JSONSchemaProps one.

Verified sources

All four return 200 as of filing:

https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/v1.29.1/config/crd/bases/postgresql.cnpg.io_clusters.yaml
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/v1.29.1/config/crd/bases/postgresql.cnpg.io_scheduledbackups.yaml
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/v1.29.1/config/crd/bases/postgresql.cnpg.io_backups.yaml
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/v1.29.1/config/crd/bases/postgresql.cnpg.io_poolers.yaml
https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/v0.7.0/config/crd/bases/barmancloud.cnpg.io_objectstores.yaml

On the pin. Fountain runs operator 1.29.1, so v1.29.1 is the version that matches a real consumer; latest is v1.30.0. Pick one deliberately and record it in the doc comment. Barman plugin latest is v0.14.0; v0.7.0 is verified above — check whether the ObjectStore schema moved between them before pinning.

Steps

  1. Add the version consts + base URLs near the other version consts in crd-sources.ts, with the doc comment.
  2. Add the entries to CRD_SOURCES.
  3. Add the two group→namespace overrides in parser.ts.
  4. From lexicons/k8s/: npm run generate, then npm run build -w @intentius/chant-lexicon-k8s.
  5. If generation errors on schema size/recursion, add a schemaPatches entry and re-run.

Definition of done

  • K8s::Cnpg::Cluster, ::ScheduledBackup, ::ObjectStore (and ::Backup, ::Pooler) import from the k8s generated barrel and serialize to valid YAML with the right apiVersion/kind.
  • Fountain's k8s/postgres.yaml, k8s/scheduledbackup.yaml and k8s/objectstore.yaml are reproducible from typed chant source — that is the acceptance test, not a synthetic fixture.
  • The six-field ScheduledBackup schedule round-trips (it is a string, so this is really a docs/test note — a five-field cron here silently means something else).
  • Versions recorded in crd-sources.ts with the operator-install comment.
  • npm run generate && npm run build -w @intentius/chant-lexicon-k8s clean; lexicons/k8s/src/codegen/{snapshot,typecheck,naming}.test.ts pass.

Notes

Activity

  1. added
    enhancement
    needs-review
    on Aug 2, 2026
  2. lex00 commented on Aug 3, 2026

    @lex00
    ContributorAuthor

    Pins decided:

    • CNPG v1.29.1 — matches the operator fountain actually runs, not latest (v1.30.0). Generating from 1.30 would type fields a 1.29 API server rejects, and the consumer is the point. Same reasoning the existing pins follow (cert-manager is on v1.16.2, not latest).
    • barman-cloud plugin v0.14.0 — latest. ObjectStore is the plugin's whole surface and the fields in use (retentionPolicy, destinationPath, endpointURL, s3Credentials, wal/data compression) are stable across 0.7 → 0.14.

    Both verified 200 at filing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementneeds-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions