Skip to content

[Bug]: PostgreSQL Extension Names with Underscores Fail to Create Clusters #9383

@shusaan

Description

@shusaan

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

No response

Version

1.27 (latest patch)

What version of Kubernetes are you using?

1.34

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

Problem Description

I am working on this feature
When attempting to create a CloudNativePG cluster with PostgreSQL extensions that have underscores in their names (e.g., pg_ivm), the cluster fails to start with the following error:

Job.batch "cluster-pg-ivm-1-initdb" is invalid: 
[spec.template.spec.volumes[3].name: Invalid value: "pg_ivm": 
a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', 
and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', 
regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]

Root Cause

The issue occurs in two places:

  1. CRD Validation Pattern

    • Current pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
    • This pattern only allows lowercase letters, numbers, and hyphens
    • PostgreSQL extension names commonly use underscores (e.g., pg_ivm, pg_stat_statements, pg_trgm)
  2. Volume Name Generation

    • The operator uses the extension name directly as the Kubernetes volume name
    • Kubernetes volume names must follow RFC 1123 DNS label rules, which do not allow underscores
    • Even if the CRD validation is patched, the volume creation still fails

Reproduction Steps

  1. Apply a cluster manifest with an extension containing underscores:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-pg-ivm
  namespace: cnpg-system
spec:
  imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
  instances: 1
  storage:
    size: 1Gi
  postgresql:
    extensions:
    - name: pg_ivm
      image:
        reference: ghcr.io/shusaan/pg_ivm-testing:1.13-18-trixie
  1. The cluster fails to create with the volume name validation error

Attempted Workarounds

Patching the CRD directly does not solve the issue:

kubectl patch crd clusters.postgresql.cnpg.io --type=json -p='[{
  "op": "replace",
  "path": "/spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/postgresql/properties/extensions/items/properties/name/pattern",
  "value": "^[a-zA-Z0-9_]([-_a-zA-Z0-9]*[a-zA-Z0-9])?$"
}]'

This allows the CRD validation to pass, but the cluster still fails because the volume name contains underscores.

Cluster resource

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

triagePending triage

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions