Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/v4/postgrescluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ManagedRole struct {
// Validation rules ensure immutability of Class, and that Storage and PostgresVersion can only be set once and cannot be removed or downgraded.
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.postgresVersion) || (has(self.postgresVersion) && int(self.postgresVersion.split('.')[0]) >= int(oldSelf.postgresVersion.split('.')[0]))",messageExpression="!has(self.postgresVersion) ? 'postgresVersion cannot be removed once set (was: ' + oldSelf.postgresVersion + ')' : 'postgresVersion major version cannot be downgraded (from: ' + oldSelf.postgresVersion + ', to: ' + self.postgresVersion + ')'"
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.storage) || (has(self.storage) && quantity(self.storage).compareTo(quantity(oldSelf.storage)) >= 0)",messageExpression="!has(self.storage) ? 'storage cannot be removed once set (was: ' + string(oldSelf.storage) + ')' : 'storage size cannot be decreased (from: ' + string(oldSelf.storage) + ', to: ' + string(self.storage) + ')'"
// +kubebuilder:validation:XValidation:rule="!has(self.connectionPoolerEnabled) || !self.connectionPoolerEnabled || has(self.connectionPoolerConfig)",message="connectionPoolerConfig must be set when connectionPoolerEnabled is true"
// +kubebuilder:validation:XValidation:rule="!has(self.connectionPoolerConfig)",message="connectionPoolerConfig cannot be overridden on PostgresCluster"
type PostgresClusterSpec struct {
// This field is IMMUTABLE after creation.
// +kubebuilder:validation:Required
Expand Down Expand Up @@ -97,7 +97,6 @@ type PostgresClusterSpec struct {
// +optional
ConnectionPoolerEnabled *bool `json:"connectionPoolerEnabled,omitempty"`

// ConnectionPoolerConfig overrides the connection pooler configuration from the class.
// Only takes effect when connection pooling is enabled.
// +optional
ConnectionPoolerConfig *ConnectionPoolerConfig `json:"connectionPoolerConfig,omitempty"`
Expand All @@ -109,6 +108,12 @@ type PostgresClusterSpec struct {
// +listType=map
// +listMapKey=name
ManagedRoles []ManagedRole `json:"managedRoles,omitempty"`

// ClusterDeletionPolicy controls the deletion behavior of the underlying CNPG Cluster when the PostgresCluster is deleted.
// +kubebuilder:validation:Enum=Delete;Retain
// +kubebuilder:default=Retain
// +optional
ClusterDeletionPolicy string `json:"clusterDeletionPolicy,omitempty"`
}

// PostgresClusterResources defines references to Kubernetes resources related to the PostgresCluster, such as ConfigMaps and Secrets.
Expand Down
1 change: 1 addition & 0 deletions api/v4/postgresclusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:validation:XValidation:rule="!has(self.config) || !has(self.config.connectionPoolerEnabled) || !self.config.connectionPoolerEnabled || (has(self.cnpg) && has(self.cnpg.connectionPooler))",message="cnpg.connectionPooler must be set when config.connectionPoolerEnabled is true"
// PostgresClusterClassSpec defines the desired state of PostgresClusterClass.
// PostgresClusterClass is immutable after creation - it serves as a template for Cluster CRs.
type PostgresClusterClassSpec struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ spec:
required:
- provisioner
type: object
x-kubernetes-validations:
- message: cnpg.connectionPooler must be set when config.connectionPoolerEnabled
is true
rule: '!has(self.config) || !has(self.config.connectionPoolerEnabled)
|| !self.config.connectionPoolerEnabled || (has(self.cnpg) && has(self.cnpg.connectionPooler))'
status:
description: PostgresClusterClassStatus defines the observed state of
PostgresClusterClass.
Expand Down
67 changes: 60 additions & 7 deletions config/crd/bases/enterprise.splunk.com_postgresclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,65 @@ spec:
x-kubernetes-validations:
- message: class is immutable
rule: self == oldSelf
cnpg:
description: CNPG contains the resolved CloudNativePG-specific configuration,
merged from the class.
properties:
connectionPooler:
description: |-
ConnectionPooler contains PgBouncer connection pooler configuration.
When enabled, creates RW and RO pooler deployments for clusters using this class.
properties:
config:
additionalProperties:
type: string
description: |-
Config contains PgBouncer configuration parameters.
Passed directly to CNPG Pooler spec.pgbouncer.parameters.
See: https://cloudnative-pg.io/docs/1.28/connection_pooling/#pgbouncer-configuration-options
type: object
instances:
default: 3
description: |-
Instances is the number of PgBouncer pod replicas.
Higher values provide better availability and load distribution.
format: int32
maximum: 10
minimum: 1
type: integer
mode:
default: transaction
description: Mode defines the connection pooling strategy.
enum:
- session
- transaction
- statement
type: string
type: object
primaryUpdateMethod:
default: switchover
description: |-
PrimaryUpdateMethod determines how the primary instance is updated.
"restart" - tolerate brief downtime (suitable for development)
"switchover" - minimal downtime via automated failover (production-grade)

NOTE: When using "switchover", ensure clusterConfig.instances > 1.
Switchover requires at least one replica to fail over to.
enum:
- restart
- switchover
type: string
type: object
cnpgDeletionPolicy:
default: Retain
description: CNPGDeletionPolicy controls the deletion behavior of
the underlying CNPG Cluster when the PostgresCluster is deleted.
enum:
- Delete
- Retain
type: string
connectionPoolerConfig:
description: |-
ConnectionPoolerConfig overrides the connection pooler configuration from the class.
Only takes effect when connection pooling is enabled.
description: Only takes effect when connection pooling is enabled.
properties:
config:
additionalProperties:
Expand Down Expand Up @@ -258,10 +313,8 @@ spec:
'' + string(self.storage) + '')'''
rule: '!has(oldSelf.storage) || (has(self.storage) && quantity(self.storage).compareTo(quantity(oldSelf.storage))
>= 0)'
- message: connectionPoolerConfig must be set when connectionPoolerEnabled
is true
rule: '!self.connectionPoolerEnabled || self.connectionPoolerConfig
!= null'
- message: connectionPoolerConfig cannot be overridden on PostgresCluster
rule: '!has(self.connectionPoolerConfig)'
status:
description: PostgresClusterStatus defines the observed state of PostgresCluster.
properties:
Expand Down
2 changes: 2 additions & 0 deletions config/samples/enterprise_v4_postgrescluster_override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ metadata:
spec:
# Reference the ClusterClass to inherit defaults - this is required, immutable, and must match the name of an existing ClusterClass
class: postgresql-dev
# ClusterDeletionPolicy is set to "Retain" to keep the underlying CNPG Cluster when this PostgresCluster is deleted
clusterDeletionPolicy: Delete
instances: 2
# Storage and PostgreSQL version are overridden from the ClusterClass defaults. Validation rules on the PostgresCluster resource will prevent removing these fields or setting them to lower values than the original overrides.
storage: 1Gi
Expand Down
Loading
Loading