Skip to content
Open
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: 9 additions & 0 deletions charts/postgres-operator/crds/operatorconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ spec:
connection_pooler_image:
type: string
default: "registry.opensource.zalan.do/acid/pgbouncer:master-32"
connection_pooler_labels:
type: object
additionalProperties:
type: string
default:
component: db-connection-pooler
connection_pooler_max_db_connections:
type: integer
default: 60
Expand All @@ -683,6 +689,9 @@ spec:
type: integer
minimum: 1
default: 2
connection_pooler_role_label:
type: string
default: "pooler-role"
connection_pooler_default_cpu_limit:
type: string
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
Expand Down
5 changes: 5 additions & 0 deletions charts/postgres-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,17 @@ configConnectionPooler:
connection_pooler_user: "pooler"
# docker image
connection_pooler_image: "registry.opensource.zalan.do/acid/pgbouncer:master-32"
# labels to add to the connection pooler deployment and pods
connection_pooler_labels:
component: db-connection-pooler
# max db connections the pooler should hold
connection_pooler_max_db_connections: 60
# default pooling mode
connection_pooler_mode: "transaction"
# number of pooler instances
connection_pooler_number_of_instances: 2
# role label to add to the connection pooler resources to filter them easier
connection_pooler_role_label: pooler-role
# default resources
connection_pooler_default_cpu_request: 500m
connection_pooler_default_memory_request: 100Mi
Expand Down
12 changes: 10 additions & 2 deletions docs/reference/operator_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ configuration they are grouped under the `kubernetes` key.
pooler deployment. The default is empty.

* **pod_role_label**
name of the label assigned to the Postgres pods (and services/endpoints) by
the operator. The default is `spilo-role`.
name of the label assigned to most cluster resources to distinguish objects
with relation to the primary instance from the replica(s). The default is `spilo-role`.

* **cluster_labels**
list of `name:value` pairs for additional labels assigned to the cluster
Expand Down Expand Up @@ -1069,6 +1069,14 @@ operator being able to provide some reasonable defaults.
* **connection_pooler_mode**
Default pooler mode, `session` or `transaction`. Default is `transaction`.

* **connection_pooler_labels**
List of `name:value` pairs for additional labels assigned to the pooler
objects. The default is `component:db-connection-pooler`.

* **connection_pooler_role_label**
name of the label assigned to most pooler resources to distinguish objects
with relation to the primary instance from the replica(s). The default is `pooler-role`.

* **connection_pooler_default_cpu_request**
**connection_pooler_default_memory_reques**
**connection_pooler_default_cpu_limit**
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
kubectl delete postgresql acid-minimal-cluster
kubectl delete deployments -l application=db-connection-pooler,cluster-name=acid-minimal-cluster
kubectl delete deployments -l application=spilo,cluster-name=acid-minimal-cluster,component=db-connection-pooler
kubectl delete statefulsets -l application=spilo,cluster-name=acid-minimal-cluster
kubectl delete services -l application=spilo,cluster-name=acid-minimal-cluster
kubectl delete configmap postgres-operator
Expand Down
4 changes: 2 additions & 2 deletions e2e/scripts/watch_objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ echo
echo 'Pods'
kubectl get pods -l application=spilo -o wide --all-namespaces
echo
kubectl get pods -l application=db-connection-pooler -o wide --all-namespaces
kubectl get pods -l application=spilo,component=db-connection-pooler -o wide --all-namespaces
echo
echo 'Statefulsets'
kubectl get statefulsets --all-namespaces
echo
echo 'Deployments'
kubectl get deployments --all-namespaces -l application=db-connection-pooler
kubectl get deployments --all-namespaces -l application=spilo,component=db-connection-pooler
kubectl get deployments --all-namespaces -l application=postgres-operator
echo
echo
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def test_enable_disable_connection_pooler(self):
the end turn connection pooler off to not interfere with other tests.
'''
k8s = self.k8s
pooler_label = 'application=db-connection-pooler,cluster-name=acid-minimal-cluster'
pooler_label = 'application=spilo,component=db-connection-pooler,cluster-name=acid-minimal-cluster'
master_pooler_label = 'connection-pooler=acid-minimal-cluster-pooler'
replica_pooler_label = master_pooler_label + '-repl'
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")
Expand Down
2 changes: 2 additions & 0 deletions manifests/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ data:
connection_pooler_default_memory_limit: 100Mi
connection_pooler_default_memory_request: 100Mi
connection_pooler_image: "registry.opensource.zalan.do/acid/pgbouncer:master-32"
connection_pooler_labels: "component:db-connection-pooler"
connection_pooler_max_db_connections: "60"
connection_pooler_mode: "transaction"
connection_pooler_number_of_instances: "2"
connection_pooler_role_label: pooler-role
connection_pooler_schema: "pooler"
connection_pooler_user: "pooler"
crd_categories: "all"
Expand Down
9 changes: 6 additions & 3 deletions manifests/minimal-fake-pooler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ kind: Deployment
metadata:
name: acid-minimal-cluster-pooler
labels:
application: db-connection-pooler
application: spilo
component: db-connection-pooler
connection-pooler: acid-minimal-cluster-pooler
spec:
replicas: 1
selector:
matchLabels:
application: db-connection-pooler
application: spilo
component: db-connection-pooler
connection-pooler: acid-minimal-cluster-pooler
cluster-name: acid-minimal-cluster
template:
metadata:
labels:
application: db-connection-pooler
application: spilo
component: db-connection-pooler
connection-pooler: acid-minimal-cluster-pooler
cluster-name: acid-minimal-cluster
spec:
Expand Down
9 changes: 9 additions & 0 deletions manifests/operatorconfiguration.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,12 @@ spec:
connection_pooler_image:
type: string
default: "registry.opensource.zalan.do/acid/pgbouncer:master-32"
connection_pooler_labels:
type: object
additionalProperties:
type: string
default:
component: db-connection-pooler
connection_pooler_max_db_connections:
type: integer
default: 60
Expand All @@ -681,6 +687,9 @@ spec:
type: integer
minimum: 1
default: 2
connection_pooler_role_label:
type: string
default: "pooler-role"
connection_pooler_default_cpu_limit:
type: string
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
Expand Down
3 changes: 3 additions & 0 deletions manifests/postgresql-operator-default-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@ configuration:
connection_pooler_default_memory_limit: 100Mi
connection_pooler_default_memory_request: 100Mi
connection_pooler_image: "registry.opensource.zalan.do/acid/pgbouncer:master-32"
connection_pooler_labels:
component: db-connection-pooler
# connection_pooler_max_db_connections: 60
connection_pooler_mode: "transaction"
connection_pooler_number_of_instances: 2
connection_pooler_role_label: pooler-role
# connection_pooler_schema: "pooler"
# connection_pooler_user: "pooler"
patroni:
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/acid.zalan.do/v1/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,17 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
"connection_pooler_image": {
Type: "string",
},
"connection_pooler_labels": {
Type: "object",
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
Schema: &apiextv1.JSONSchemaProps{
Type: "string",
},
},
},
"connection_pooler_role_label": {
Type: "string",
},
"connection_pooler_max_db_connections": {
Type: "integer",
},
Expand Down
22 changes: 12 additions & 10 deletions pkg/apis/acid.zalan.do/v1/operator_configuration_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@ type ScalyrConfiguration struct {

// ConnectionPoolerConfiguration defines default configuration for connection pooler
type ConnectionPoolerConfiguration struct {
NumberOfInstances *int32 `json:"connection_pooler_number_of_instances,omitempty"`
Schema string `json:"connection_pooler_schema,omitempty"`
User string `json:"connection_pooler_user,omitempty"`
Image string `json:"connection_pooler_image,omitempty"`
Mode string `json:"connection_pooler_mode,omitempty"`
MaxDBConnections *int32 `json:"connection_pooler_max_db_connections,omitempty"`
DefaultCPURequest string `json:"connection_pooler_default_cpu_request,omitempty"`
DefaultMemoryRequest string `json:"connection_pooler_default_memory_request,omitempty"`
DefaultCPULimit string `json:"connection_pooler_default_cpu_limit,omitempty"`
DefaultMemoryLimit string `json:"connection_pooler_default_memory_limit,omitempty"`
NumberOfInstances *int32 `json:"connection_pooler_number_of_instances,omitempty"`
Schema string `json:"connection_pooler_schema,omitempty"`
User string `json:"connection_pooler_user,omitempty"`
Image string `json:"connection_pooler_image,omitempty"`
Mode string `json:"connection_pooler_mode,omitempty"`
MaxDBConnections *int32 `json:"connection_pooler_max_db_connections,omitempty"`
Labels map[string]string `json:"connection_pooler_labels,omitempty"`
RoleLabel string `json:"connection_pooler_role_label,omitempty"`
DefaultCPURequest string `json:"connection_pooler_default_cpu_request,omitempty"`
DefaultMemoryRequest string `json:"connection_pooler_default_memory_request,omitempty"`
DefaultCPULimit string `json:"connection_pooler_default_cpu_limit,omitempty"`
DefaultMemoryLimit string `json:"connection_pooler_default_memory_limit,omitempty"`
}

// OperatorLogicalBackupConfiguration defines configuration for logical backup
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,8 @@ func TestCrossNamespacedSecrets(t *testing.T) {
Config{
OpConfig: config.Config{
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down
7 changes: 4 additions & 3 deletions pkg/cluster/connection_pooler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ func (c *Cluster) poolerUser(spec *acidv1.PostgresSpec) string {
func (c *Cluster) poolerLabelsSet(addExtraLabels bool) labels.Set {
poolerLabels := c.labelsSet(addExtraLabels)

// TODO should be config values
poolerLabels["application"] = "db-connection-pooler"
for k, v := range c.OpConfig.ConnectionPooler.Labels {
poolerLabels[k] = v
}

return poolerLabels
}
Expand All @@ -134,7 +135,7 @@ func (c *Cluster) connectionPoolerLabels(role PostgresRole, addExtraLabels bool)

if addExtraLabels {
extraLabels := map[string]string{}
extraLabels[c.OpConfig.PodRoleLabel] = string(role)
extraLabels[c.OpConfig.ConnectionPooler.RoleLabel] = string(role)

poolerLabelsSet = labels.Merge(poolerLabelsSet, extraLabels)
}
Expand Down
24 changes: 19 additions & 5 deletions pkg/cluster/connection_pooler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func deploymentUpdated(cluster *Cluster, err error, reason SyncReason) error {
for _, role := range [2]PostgresRole{Master, Replica} {

poolerLabels := cluster.labelsSet(false)
poolerLabels["application"] = "db-connection-pooler"
poolerLabels["component"] = "db-connection-pooler"
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)

if cluster.ConnectionPooler[role] != nil && cluster.ConnectionPooler[role].Deployment != nil &&
Expand All @@ -65,7 +65,7 @@ func objectsAreSaved(cluster *Cluster, err error, reason SyncReason) error {

for _, role := range []PostgresRole{Master, Replica} {
poolerLabels := cluster.labelsSet(false)
poolerLabels["application"] = "db-connection-pooler"
poolerLabels["component"] = "db-connection-pooler"
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)

if cluster.ConnectionPooler[role].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[role].Deployment.Labels, poolerLabels) {
Expand All @@ -86,7 +86,7 @@ func MasterObjectsAreSaved(cluster *Cluster, err error, reason SyncReason) error
}

poolerLabels := cluster.labelsSet(false)
poolerLabels["application"] = "db-connection-pooler"
poolerLabels["component"] = "db-connection-pooler"
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(Master)

if cluster.ConnectionPooler[Master].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[Master].Deployment.Labels, poolerLabels) {
Expand All @@ -106,7 +106,7 @@ func ReplicaObjectsAreSaved(cluster *Cluster, err error, reason SyncReason) erro
}

poolerLabels := cluster.labelsSet(false)
poolerLabels["application"] = "db-connection-pooler"
poolerLabels["component"] = "db-connection-pooler"
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(Replica)

if cluster.ConnectionPooler[Replica].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[Replica].Deployment.Labels, poolerLabels) {
Expand Down Expand Up @@ -170,6 +170,8 @@ func TestNeedConnectionPooler(t *testing.T) {
ReplicationUsername: replicationUserName,
},
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -301,6 +303,8 @@ func TestConnectionPoolerCreateDeletion(t *testing.T) {
Config{
OpConfig: config.Config{
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -336,7 +340,7 @@ func TestConnectionPoolerCreateDeletion(t *testing.T) {
}
for _, role := range [2]PostgresRole{Master, Replica} {
poolerLabels := cluster.labelsSet(false)
poolerLabels["application"] = "db-connection-pooler"
poolerLabels["component"] = "db-connection-pooler"
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)

if cluster.ConnectionPooler[role] != nil {
Expand Down Expand Up @@ -409,6 +413,8 @@ func TestConnectionPoolerSync(t *testing.T) {
Config{
OpConfig: config.Config{
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -678,6 +684,8 @@ func TestConnectionPoolerPodSpec(t *testing.T) {
PodServiceAccountName: "postgres-pod",
ConnectionPooler: config.ConnectionPooler{
MaxDBConnections: k8sutil.Int32ToPointer(60),
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -789,6 +797,8 @@ func TestConnectionPoolerDeploymentSpec(t *testing.T) {
ReplicationUsername: replicationUserName,
},
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -1003,6 +1013,8 @@ func TestPoolerTLS(t *testing.T) {
SpiloFSGroup: &spiloFSGroup,
},
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -1072,6 +1084,8 @@ func TestConnectionPoolerServiceSpec(t *testing.T) {
ReplicationUsername: replicationUserName,
},
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/k8sres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,8 @@ func TestEnableLoadBalancers(t *testing.T) {
subTest: "LBs enabled in config, disabled in manifest",
config: config.Config{
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down Expand Up @@ -3069,6 +3071,8 @@ func TestEnableLoadBalancers(t *testing.T) {
subTest: "LBs enabled in manifest, disabled in config",
config: config.Config{
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down
2 changes: 2 additions & 0 deletions pkg/cluster/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func TestPodAnnotationsSync(t *testing.T) {
PodManagementPolicy: "ordered_ready",
CustomPodAnnotations: customPodAnnotations,
ConnectionPooler: config.ConnectionPooler{
Labels: map[string]string{"component": "db-connection-pooler"},
RoleLabel: "pooler-role",
ConnectionPoolerDefaultCPURequest: "100m",
ConnectionPoolerDefaultCPULimit: "100m",
ConnectionPoolerDefaultMemoryRequest: "100Mi",
Expand Down
Loading
Loading