Skip to content

Conversation

@mbiagetti
Copy link
Contributor

@mbiagetti mbiagetti commented Jan 29, 2026

Adds a create_extension boolean field to extension metadata so that extensions providing only libraries or tools (e.g. wal2json) can skip CREATE EXTENSION tests. When create_extension is false, the extension is omitted entirely from the Database CR's extensions_spec and the status assertion skips the extensions field.

The generated database_assert_status map conditionally includes or excludes the extensions key, avoiding the Chainsaw limitation where extensions: null would require the field to exist in the actual resource. The psql verification job in check-extension.yaml also reads create_extension and skips when false.

Example generated values for create_extension: true (pgvector):

name: pgvector
sql_name: vector
shared_preload_libraries: []
pg_image: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
version: 0.8.1
create_extension: true
extensions:
    - name: pgvector
      image:
        reference: registry.pg-extensions:5000/pgvector-testing:0.8.1-18-trixie
database_config:
    extensions_spec:
        - ensure: present
          name: vector
          version: 0.8.1
database_assert_status:
    applied: true
    observedGeneration: 1
    extensions:
        - applied: true
          name: vector

Example generated values for create_extension: false (wal2json):

name: wal2json
sql_name: wal2json
shared_preload_libraries: []
pg_image: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
version: 2.6
create_extension: false
extensions:
    - name: wal2json
      image:
        reference: registry.pg-extensions:5000/wal2json-testing:2.6-18-trixie
database_config: {}
database_assert_status:
    applied: true
    observedGeneration: 1

Closes #85

@mbiagetti mbiagetti requested review from a team and NiccoloFei as code owners January 29, 2026 16:28
@NiccoloFei NiccoloFei force-pushed the mbiagetti/dev/85 branch 4 times, most recently from 60a3587 to 26b1448 Compare February 5, 2026 13:29
@NiccoloFei NiccoloFei force-pushed the mbiagetti/dev/85 branch 2 times, most recently from cc2f50c to b055ea9 Compare February 9, 2026 15:27
@gbartolini
Copy link
Contributor

I have tried this patch using an extension that doesn't need create extension like wal2json but I see that the tests are run anyway on the database.yaml file which still lists the extension:

apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
  name: (join('-', [$values.name, 'app']))
spec:
  name: app
  owner: app
  cluster:
    name: ($values.name)
  extensions: ($values.database_config.extensions_spec)

In my opinion, this test should be skipped or, if we want to, we should use a template that adds the extensions option only if the create extension capability is provided by the extension.

@gbartolini
Copy link
Contributor

gbartolini commented Feb 12, 2026

@mnencia it is not working for me. If I run:

task e2e:test:full TARGET=wal2json

I used this basic Dockerfile:

# SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
# SPDX-License-Identifier: Apache-2.0

ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
FROM $BASE AS builder

ARG PG_MAJOR
ARG EXT_VERSION

USER 0

RUN apt-get update && apt-get install -y --no-install-recommends \
  "postgresql-${PG_MAJOR}-wal2json=${EXT_VERSION}"

FROM scratch
ARG PG_MAJOR

# Licenses
# COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-wal2json/copyright /licenses/postgresql-${PG_MAJOR}-wal2json/

# Libraries
# COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/wal2json* /lib/

USER 65532:65532

And this metadata:

# SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
# SPDX-License-Identifier: Apache-2.0
metadata = {
  name                     = "wal2json"
  sql_name                 = "wal2json"
  image_name               = "wal2json"
  shared_preload_libraries = []
  extension_control_path   = []
  dynamic_library_path     = []
  ld_library_path          = []
  auto_update_os_libs      = false
  required_extensions      = []
  create_extension         = false

  versions = {
    trixie = {
        // renovate: suite=trixie-pgdg depName=postgresql-18-wal2json
        "18" = "2.6-3.pgdg13+1"
    }
    bookworm = {
        // renovate: suite=bookworm-pgdg depName=postgresql-18-wal2json
        "18" = "2.6-3.pgdg12+1"
    }
  }
}

I get this result:

[e2e:test-wal2json]     | 03:48:54 | verify-extension | Create a Cluster with the extension | ASSERT    | ERROR | postgresql.cnpg.io/v1/Database @ chainsaw-innocent-toucan/wal2json-app
[e2e:test-wal2json]         === ERROR
[e2e:test-wal2json]         --------------------------------------------------------------------
[e2e:test-wal2json]         postgresql.cnpg.io/v1/Database/chainsaw-innocent-toucan/wal2json-app
[e2e:test-wal2json]         --------------------------------------------------------------------
[e2e:test-wal2json]         * status.extensions: Required value: field not found in the input object
[e2e:test-wal2json]
[e2e:test-wal2json]         --- expected
[e2e:test-wal2json]         +++ actual
[e2e:test-wal2json]         @@ -5,6 +5,5 @@
[e2e:test-wal2json]            namespace: chainsaw-innocent-toucan
[e2e:test-wal2json]          status:
[e2e:test-wal2json]            applied: true
[e2e:test-wal2json]         -  extensions: null
[e2e:test-wal2json]            observedGeneration: 1
[e2e:test-wal2json]     | 03:48:54 | verify-extension | Create a Cluster with the extension | TRY       | END   |
[e2e:test-wal2json]     | 03:48:54 | verify-extension | Create a Cluster with the extension | CLEANUP   | BEGIN |
[e2e:test-wal2json]     | 03:48:54 | verify-extension | Create a Cluster with the extension | DELETE    | OK    | postgresql.cnpg.io/v1/Database @ chainsaw-innocent-toucan/wal2json-app
[e2e:test-wal2json]     | 03:48:54 | verify-extension | Create a Cluster with the extension | DELETE    | OK    | postgresql.cnpg.io/v1/Cluster @ chainsaw-innocent-toucan/wal2json
[e2e:test-wal2json]     | 03:48:54 | verify-extension | Create a Cluster with the extension | CLEANUP   | END   |
[e2e:test-wal2json]     | 03:48:54 | verify-extension | @chainsaw                           | CLEANUP   | BEGIN |
[e2e:test-wal2json]     | 03:48:54 | verify-extension | @chainsaw                           | DELETE    | OK    | v1/Namespace @ chainsaw-innocent-toucan
[e2e:test-wal2json]     | 03:49:04 | verify-extension | @chainsaw                           | CLEANUP   | END   |
[e2e:test-wal2json] --- FAIL: chainsaw (0.00s)
[e2e:test-wal2json]     --- FAIL: chainsaw/verify-extension (209.20s)
[e2e:test-wal2json] FAIL
[e2e:test-wal2json] Tests Summary...
[e2e:test-wal2json] - Passed  tests 0
[e2e:test-wal2json] - Failed  tests 1
[e2e:test-wal2json] - Skipped tests 0
[e2e:test-wal2json] Done with failures.
[e2e:test-wal2json] Stderr:
[e2e:test-wal2json] Error: some tests failed
task: [e2e:test:full] rm -f "./kubeconfig"
task: [e2e:test:full] rm -f "wal2json/values.yaml"
task: [e2e:test:full] rm -f "wal2json/bake-metadata.json"
task: Failed to run task "e2e:test:full": task: Failed to run task "e2e:test": exit status 1
...

mbiagetti and others added 7 commits February 12, 2026 09:08
Signed-off-by: Matteo <matteo.biagetti@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
TestingValues was missing the CreateExtension field, so the generated
values.yaml never contained create_extension and the psql verification
job always skipped.

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Bundle extension metadata with its configuration so
generateDatabaseConfig no longer re-parses metadata or re-fetches
image annotations for each extension.

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Skip extensions with create_extension = false from the Database CR
and status assertion entirely, rather than listing them with
ensure: absent.

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
@mnencia
Copy link
Member

mnencia commented Feb 12, 2026

Sorry Gabriele. I missed pushing the last version of the code. I apologize for the time wasted.

@gbartolini
Copy link
Contributor

No worries, that's ok. Now everything works!

@gbartolini gbartolini merged commit 4179216 into cloudnative-pg:main Feb 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make CREATE EXTENSION tests optional

5 participants