Skip to content

Commit b1e8392

Browse files
authored
Merge pull request #1749 from splunk/postgres-operator-secrets-confmaps
Postgres cluster reconciler creates Secret and ConfigMap
2 parents daced57 + 49a014c commit b1e8392

7 files changed

Lines changed: 338 additions & 22 deletions

File tree

api/v4/postgrescluster_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type ManagedRole struct {
4545
// Validation rules ensure immutability of Class, and that Storage and PostgresVersion can only be set once and cannot be removed or downgraded.
4646
// +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 + ')'"
4747
// +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) + ')'"
48+
// +kubebuilder:validation:XValidation:rule="!has(self.connectionPoolerEnabled) || !self.connectionPoolerEnabled || has(self.connectionPoolerConfig)",message="connectionPoolerConfig must be set when connectionPoolerEnabled is true"
4849
type PostgresClusterSpec struct {
4950
// This field is IMMUTABLE after creation.
5051
// +kubebuilder:validation:Required
@@ -110,6 +111,19 @@ type PostgresClusterSpec struct {
110111
ManagedRoles []ManagedRole `json:"managedRoles,omitempty"`
111112
}
112113

114+
// PostgresClusterResources defines references to Kubernetes resources related to the PostgresCluster, such as ConfigMaps and Secrets.
115+
type PostgresClusterResources struct {
116+
// ConfigMapRef references the ConfigMap with connection endpoints.
117+
// Contains: CLUSTER_ENDPOINTS, POOLER_ENDPOINTS (if connection pooler enabled)
118+
// +optional
119+
ConfigMapRef *corev1.LocalObjectReference `json:"configMapRef,omitempty"`
120+
121+
// SecretRef references the Secret with superuser credentials.
122+
// Contains: passwords for superuser
123+
// +optional
124+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
125+
}
126+
113127
// PostgresClusterStatus defines the observed state of PostgresCluster.
114128
type PostgresClusterStatus struct {
115129
// Phase represents the current phase of the PostgresCluster.
@@ -134,6 +148,10 @@ type PostgresClusterStatus struct {
134148
// ManagedRolesStatus tracks the reconciliation status of managed roles.
135149
// +optional
136150
ManagedRolesStatus *ManagedRolesStatus `json:"managedRolesStatus,omitempty"`
151+
152+
// Resources contains references to related Kubernetes resources like ConfigMaps and Secrets.
153+
// +optional
154+
Resources *PostgresClusterResources `json:"resources,omitempty"`
137155
}
138156

139157
// ManagedRolesStatus tracks the state of managed PostgreSQL roles.

config/crd/bases/enterprise.splunk.com_postgresclusters.yaml

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ spec:
5858
x-kubernetes-validations:
5959
- message: class is immutable
6060
rule: self == oldSelf
61+
connectionPoolerConfig:
62+
description: |-
63+
ConnectionPoolerConfig overrides the connection pooler configuration from the class.
64+
Only takes effect when connection pooling is enabled.
65+
properties:
66+
config:
67+
additionalProperties:
68+
type: string
69+
description: |-
70+
Config contains PgBouncer configuration parameters.
71+
Passed directly to CNPG Pooler spec.pgbouncer.parameters.
72+
See: https://cloudnative-pg.io/docs/1.28/connection_pooling/#pgbouncer-configuration-options
73+
type: object
74+
instances:
75+
default: 3
76+
description: |-
77+
Instances is the number of PgBouncer pod replicas.
78+
Higher values provide better availability and load distribution.
79+
format: int32
80+
maximum: 10
81+
minimum: 1
82+
type: integer
83+
mode:
84+
default: transaction
85+
description: Mode defines the connection pooling strategy.
86+
enum:
87+
- session
88+
- transaction
89+
- statement
90+
type: string
91+
type: object
6192
connectionPoolerEnabled:
6293
default: false
6394
description: |-
@@ -128,7 +159,6 @@ spec:
128159
type: string
129160
type: array
130161
postgresVersion:
131-
default: "18"
132162
description: |-
133163
PostgresVersion is the PostgreSQL version (major or major.minor).
134164
Examples: "18" (latest 18.x), "18.1" (specific minor), "17", "16"
@@ -216,9 +246,22 @@ spec:
216246
- class
217247
type: object
218248
x-kubernetes-validations:
219-
- message: Storage size cannot be removed and can only be increased
249+
- messageExpression: '!has(self.postgresVersion) ? ''postgresVersion cannot
250+
be removed once set (was: '' + oldSelf.postgresVersion + '')'' : ''postgresVersion
251+
major version cannot be downgraded (from: '' + oldSelf.postgresVersion
252+
+ '', to: '' + self.postgresVersion + '')'''
253+
rule: '!has(oldSelf.postgresVersion) || (has(self.postgresVersion) &&
254+
int(self.postgresVersion.split(''.'')[0]) >= int(oldSelf.postgresVersion.split(''.'')[0]))'
255+
- messageExpression: '!has(self.storage) ? ''storage cannot be removed
256+
once set (was: '' + string(oldSelf.storage) + '')'' : ''storage size
257+
cannot be decreased (from: '' + string(oldSelf.storage) + '', to:
258+
'' + string(self.storage) + '')'''
220259
rule: '!has(oldSelf.storage) || (has(self.storage) && quantity(self.storage).compareTo(quantity(oldSelf.storage))
221260
>= 0)'
261+
- message: connectionPoolerConfig must be set when connectionPoolerEnabled
262+
is true
263+
rule: '!self.connectionPoolerEnabled || self.connectionPoolerConfig
264+
!= null'
222265
status:
223266
description: PostgresClusterStatus defines the observed state of PostgresCluster.
224267
properties:
@@ -363,6 +406,43 @@ spec:
363406
type: string
364407
type: object
365408
x-kubernetes-map-type: atomic
409+
resources:
410+
description: Resources contains references to related Kubernetes resources
411+
like ConfigMaps and Secrets.
412+
properties:
413+
configMapRef:
414+
description: |-
415+
ConfigMapRef references the ConfigMap with connection endpoints.
416+
Contains: CLUSTER_ENDPOINTS, POOLER_ENDPOINTS (if connection pooler enabled)
417+
properties:
418+
name:
419+
default: ""
420+
description: |-
421+
Name of the referent.
422+
This field is effectively required, but due to backwards compatibility is
423+
allowed to be empty. Instances of this type with an empty value here are
424+
almost certainly wrong.
425+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
426+
type: string
427+
type: object
428+
x-kubernetes-map-type: atomic
429+
secretRef:
430+
description: |-
431+
SecretRef references the Secret with superuser credentials.
432+
Contains: passwords for superuser
433+
properties:
434+
name:
435+
default: ""
436+
description: |-
437+
Name of the referent.
438+
This field is effectively required, but due to backwards compatibility is
439+
allowed to be empty. Instances of this type with an empty value here are
440+
almost certainly wrong.
441+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
442+
type: string
443+
type: object
444+
x-kubernetes-map-type: atomic
445+
type: object
366446
type: object
367447
type: object
368448
served: true

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ rules:
110110
resources:
111111
- clusters
112112
- databases
113+
- poolers
113114
verbs:
114115
- create
115116
- delete
@@ -122,5 +123,6 @@ rules:
122123
- postgresql.cnpg.io
123124
resources:
124125
- clusters/status
126+
- poolers/status
125127
verbs:
126128
- get

config/samples/enterprise_v4_postgrescluster_override.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ spec:
2424
memory: "1Gi"
2525
# Enable connection pooler for this cluster
2626
# Takes precedence over the class-level connectionPoolerEnabled value
27-
connectionPoolerEnabled: true
27+
# connectionPoolerEnabled: true

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/onsi/gomega v1.39.1
2323
github.com/pkg/errors v0.9.1
2424
github.com/prometheus/client_golang v1.23.2
25+
github.com/sethvargo/go-password v0.3.1
2526
github.com/stretchr/testify v1.11.1
2627
github.com/wk8/go-ordered-map/v2 v2.1.7
2728
go.uber.org/zap v1.27.1
@@ -31,6 +32,7 @@ require (
3132
k8s.io/apimachinery v0.34.2
3233
k8s.io/client-go v0.34.2
3334
k8s.io/kubectl v0.26.2
35+
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
3436
sigs.k8s.io/controller-runtime v0.22.4
3537
)
3638

@@ -136,7 +138,6 @@ require (
136138
github.com/prometheus/common v0.66.1 // indirect
137139
github.com/prometheus/procfs v0.16.1 // indirect
138140
github.com/rs/xid v1.2.1 // indirect
139-
github.com/sethvargo/go-password v0.3.1 // indirect
140141
github.com/sirupsen/logrus v1.9.3 // indirect
141142
github.com/spf13/cobra v1.10.1 // indirect
142143
github.com/spf13/pflag v1.0.10 // indirect
@@ -184,7 +185,6 @@ require (
184185
k8s.io/component-base v0.34.2 // indirect
185186
k8s.io/klog/v2 v2.130.1 // indirect
186187
k8s.io/kube-openapi v0.0.0-20250905212525-66792eed8611 // indirect
187-
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
188188
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
189189
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
190190
sigs.k8s.io/randfill v1.0.0 // indirect

0 commit comments

Comments
 (0)