Skip to content

feat(postgres): add postgis image flavor - #2672

Closed
Matthieu ROBIN (matthieu-robin) wants to merge 2 commits into
cozystack:mainfrom
matthieu-robin:postgis-flavor
Closed

Matthieu ROBIN (matthieu-robin) wants to merge 2 commits into
cozystack:mainfrom
matthieu-robin:postgis-flavor

Conversation

@matthieu-robin

@matthieu-robin Matthieu ROBIN (matthieu-robin) commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

What this PR does

Adds a flavor: postgresql | postgis enum on the apps/postgres chart so tenants can opt in to the CloudNativePG PostGIS image (ghcr.io/cloudnative-pg/postgis) instead of the standard ghcr.io/cloudnative-pg/postgresql. The variant ships PostGIS and its companion extensions (postgis_topology, postgis_raster, pgrouting, address_standardizer) precompiled — they activate per database via the existing databases.<name>.extensions mechanism, no other plumbing required.

Design

  • Single source of truth for the image in a new postgres.imageName template helper. Both templates/db.yaml (the cnpg.io Cluster) and templates/init-job.yaml (the post-install role/DB management Job) call it, so they stay wire-compatible — the init Job's psql always matches the running server.
  • New files/postgis-versions.yaml mirrors the existing files/versions.yaml: maps the version enum (v13-v17) to the corresponding PostGIS image tag (e.g. 17.7-3.5). v18 is not yet covered by the upstream PostGIS image; selecting flavor: postgis with version: v18 fails at install with a clear error.
  • flavor is a bootstrap-time choice. Switching it on an existing release is documented as requiring a fresh release (or bootstrap.enabled: true with bootstrap.oldName and bootstrap.recoveryTime to restore from a backup) — CNPG cannot hot-swap between images with different on-disk capabilities.
  • No change to the existing extension creation flow (CREATE EXTENSION IF NOT EXISTS in init-script.yaml); it just works once the binaries are present.
  • Codegen propagated: api/apps/v1alpha1/postgresql/types.go, values.schema.json, the README parameters table and packages/system/postgres-rd/cozyrds/postgres.yaml were refreshed via make generate.

Release note

feat(postgres): add a `flavor` field on the postgres app accepting `postgresql` (default) or `postgis`. `postgis` boots the cluster from the CloudNativePG PostGIS image, enabling PostGIS extensions (postgis, postgis_topology, postgis_raster, pgrouting, address_standardizer) via the existing `databases.<name>.extensions` field. Supported for PostgreSQL v13-v17.

Test plan

  • helm unittest . — 18/18 (existing 13 + new 5 in tests/flavor_test.yaml covering default, explicit postgresql, postgis on Cluster, postgis on init Job, and the v18 failure path)
  • helm template t . -n tenant-test --set version=v17 --set flavor=postgis → both Cluster.spec.imageName and Job.spec.template.spec.containers[0].image resolve to ghcr.io/cloudnative-pg/postgis:17.7-3.5
  • helm template ... --set version=v18 --set flavor=postgis → fails with PostgreSQL version v18 is not supported by the postgis flavor, allowed versions are [v13 v14 v15 v16 v17]
  • go build ./... after codegen
  • Live cluster smoke test: deploy with flavor: postgis + databases.gis.extensions: [postgis], then SELECT postgis_full_version();

Summary by CodeRabbit

  • New Features

    • Added a flavor option to choose standard PostgreSQL or a PostGIS-enabled image; chart now switches all relevant container images (cluster and init jobs) and validates supported PostGIS/Postgres versions.
  • Documentation

    • Added "How to enable PostGIS", per-database extension guidance, version/upgrade notes, and updated backup/archive operation wording.
  • Tests

    • Added tests verifying flavor-to-image mapping and unsupported-version validation.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the apps/postgres chart by introducing a flavor parameter, enabling users to opt into a PostGIS-enabled PostgreSQL image. This change streamlines the deployment of spatial databases by providing precompiled extensions, while maintaining wire-compatibility between the cluster and initialization jobs through a unified image resolution strategy.

Highlights

  • PostGIS Support: Added a new flavor configuration option to the apps/postgres chart, allowing users to select between the standard PostgreSQL image and a precompiled PostGIS variant.
  • Image Management: Introduced a centralized postgres.imageName template helper to ensure consistency between the Cluster and the initialization Job, with a new files/postgis-versions.yaml mapping versions to image tags.
  • Validation and Testing: Implemented validation to prevent unsupported version selections for the PostGIS flavor and added comprehensive unit tests to verify image resolution and failure paths.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot dosubot Bot added area/database Issues or PRs related to managed databases (postgres, mariadb, redis, etcd, kafka, clickhouse) kind/feature Categorizes issue or PR as related to a new feature labels May 18, 2026
@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3c6f49eb-329e-416d-94b9-219d1034a79b

📥 Commits

Reviewing files that changed from the base of the PR and between f91b65c and 2d98d79.

📒 Files selected for processing (9)
  • api/apps/v1alpha1/postgresql/types.go
  • packages/apps/postgres/README.md
  • packages/apps/postgres/files/postgis-versions.yaml
  • packages/apps/postgres/templates/_versions.tpl
  • packages/apps/postgres/templates/db.yaml
  • packages/apps/postgres/templates/init-job.yaml
  • packages/apps/postgres/tests/flavor_test.yaml
  • packages/apps/postgres/values.schema.json
  • packages/apps/postgres/values.yaml
✅ Files skipped from review due to trivial changes (1)
  • packages/apps/postgres/files/postgis-versions.yaml
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/apps/postgres/values.yaml
  • packages/apps/postgres/templates/init-job.yaml
  • packages/apps/postgres/templates/_versions.tpl
  • packages/apps/postgres/values.schema.json
  • api/apps/v1alpha1/postgresql/types.go

📝 Walkthrough

Walkthrough

Adds a chart/configuration flag flavor (postgresql|postgis), API support, Helm templates for flavor-aware image selection (including PostGIS version mapping), manifest integration, tests, ApplicationDefinition schema exposure, and README docs for enabling PostGIS.

Changes

PostgreSQL Image Flavor Selection

Layer / File(s) Summary
API type definition for flavor
api/apps/v1alpha1/postgresql/types.go
Flavor type and ConfigSpec.Flavor field establish the contract, restricting values to postgresql and postgis via kubebuilder validation.
Helm chart values, schema, and PostGIS versions
packages/apps/postgres/values.yaml, packages/apps/postgres/values.schema.json, packages/apps/postgres/files/postgis-versions.yaml
Chart values add flavor: postgresql default, schema enforces enum validation, and new PostGIS version mapping file links versions to CloudNativePG PostGIS image tags.
Flavor-aware image selection templates
packages/apps/postgres/templates/_versions.tpl
New postgres.postgisVersionMap loads and validates PostGIS versions; postgres.imageName branches on flavor to select either PostgreSQL or PostGIS image reference and version.
Manifest template updates
packages/apps/postgres/templates/db.yaml, packages/apps/postgres/templates/init-job.yaml
CNPG Cluster and init Job manifests switch from hardcoded image paths to use the flavor-aware postgres.imageName helper.
Flavor selection test suite
packages/apps/postgres/tests/flavor_test.yaml
Tests default PostgreSQL image selection, explicit flavor choices, PostGIS image switching for Cluster and init Job, and version validation with appropriate error messages.
ApplicationDefinition schema sync
packages/system/postgres-rd/cozyrds/postgres.yaml
openAPISchema is extended with spec.flavor property and keysOrder is updated to include the new field in schema rendering.
User documentation
packages/apps/postgres/README.md
New "How to enable PostGIS" section and updated "Common parameters" table document flavor usage, extension requirements, and version constraints.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/M

Suggested reviewers

  • lexfrei
  • androndo
  • kvaps
  • lllamnyp
  • myasnikovdaniil

Poem

🐰 In charts and templates I softly tread,
flavor set to postgis or plain instead,
images picked, tests keeping watchful eyes,
docs tell the steps and version ties,
hop—your cluster now knows where to rise.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: adding PostGIS image flavor support to the PostgreSQL Helm chart, which is the primary objective across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Trivy (0.69.3)

Trivy execution failed: 2026-06-01T18:58:26Z FATAL Fatal error run error: fs scan error: scan error: scan failed: failed analysis: post analysis error: post analysis error: kubernetes scan error: fs filter error: fs filter error: walk error range error: stat smartylint.json: no such file or directory: range error: stat smartylint.json: no such file or directory


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/apps/postgres/README.md`:
- Around line 181-185: The README mentions a non-existent `bootstrap.recovery`
key; update the sentence to reference the actual chart values used for recovery
bootstrapping such as `bootstrap.enabled`, and the recovery-specific keys like
`bootstrap.oldName` and `bootstrap.recoveryTime` (or whichever recovery-related
keys are defined in the chart values) so users know to enable bootstrapping and
supply the old release name and recovery timestamp when performing a fresh
release from backup; replace the `bootstrap.recovery` token with these real
value names and ensure the wording instructs setting `bootstrap.enabled: true`
plus the appropriate recovery keys.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 52e9ee4f-b5e4-4ab3-9fcb-1710fbf796fe

📥 Commits

Reviewing files that changed from the base of the PR and between d0c12c6 and 639717b.

📒 Files selected for processing (10)
  • api/apps/v1alpha1/postgresql/types.go
  • packages/apps/postgres/README.md
  • packages/apps/postgres/files/postgis-versions.yaml
  • packages/apps/postgres/templates/_versions.tpl
  • packages/apps/postgres/templates/db.yaml
  • packages/apps/postgres/templates/init-job.yaml
  • packages/apps/postgres/tests/flavor_test.yaml
  • packages/apps/postgres/values.schema.json
  • packages/apps/postgres/values.yaml
  • packages/system/postgres-rd/cozyrds/postgres.yaml

Comment thread packages/apps/postgres/README.md Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a flavor parameter for PostgreSQL, enabling support for PostGIS by switching to the cloudnative-pg/postgis image. The changes include updates to the API types, Helm templates, documentation, and validation schemas, along with a new version mapping for PostGIS tags. Feedback was provided to improve the readability of the error message when an unsupported PostgreSQL version is used with the PostGIS flavor by formatting the list of allowed versions as a comma-separated string.

{{- define "postgres.postgisVersionMap" }}
{{- $versionMap := .Files.Get "files/postgis-versions.yaml" | fromYaml }}
{{- if not (hasKey $versionMap .Values.version) }}
{{- printf `PostgreSQL version %s is not supported by the postgis flavor, allowed versions are %s` $.Values.version (keys $versionMap | sortAlpha) | fail }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The error message uses $.Values.version and (keys $versionMap | sortAlpha). While functional, the bracketed list format produced by printf %s on a slice (e.g., [v13 v14 ...]) is slightly less readable than a comma-separated string. Consider using join ", " for a cleaner presentation, although the current implementation matches the test expectations.

    {{- printf `PostgreSQL version %s is not supported by the postgis flavor, allowed versions are %s` .Values.version (keys $versionMap | sortAlpha | join ", ") | fail }}

@github-actions github-actions Bot added the size/L This PR changes 100-499 lines, ignoring generated files label May 18, 2026
Matthieu added 2 commits June 1, 2026 20:52
Introduce a `flavor: postgresql | postgis` enum on the postgres app.
`postgis` swaps the CNPG image to `ghcr.io/cloudnative-pg/postgis`,
which ships PostGIS and companion extensions (postgis_topology,
postgis_raster, pgrouting, address_standardizer) precompiled, so
tenants can activate them per database via
`databases.<name>.extensions`. The cluster and the post-install init
Job share a single `postgres.imageName` helper to stay
wire-compatible. Tag mapping for the postgis variant lives in
`files/postgis-versions.yaml` (v13-v17 covered; v18 returns a clear
error at install).

Signed-off-by: Matthieu <[email protected]>
bootstrap.recovery does not exist in values.yaml. Point users at
bootstrap.enabled / bootstrap.oldName / bootstrap.recoveryTime instead.

Signed-off-by: Matthieu <[email protected]>
@lexfrei

Copy link
Copy Markdown
Contributor

Heads up, this conflicts with main and needs a rebase. Otherwise the postgis flavor still applies — there's no flavor/postgis wiring under packages/apps/postgres/ yet.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

This PR has had no activity for 60 days and was marked lifecycle/stale.
It will be closed in 14 days unless commented or labelled lifecycle/frozen.

@github-actions github-actions Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale label Sep 2, 2026
@github-actions

Copy link
Copy Markdown

Closed because no activity followed the lifecycle/stale warning.
Reopen if the change is still wanted.

@github-actions github-actions Bot added the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed label Sep 16, 2026
@github-actions github-actions Bot closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/database Issues or PRs related to managed databases (postgres, mariadb, redis, etcd, kafka, clickhouse) kind/feature Categorizes issue or PR as related to a new feature lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants