Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
fb43ee9
WIP Connection pooler support
erthalion Jan 14, 2020
4c69b2b
Improve cleaning up
erthalion Jan 15, 2020
2b2f29f
Add CRD configuration
erthalion Jan 20, 2020
b40ea2c
Add more tests
erthalion Jan 22, 2020
6c37520
Various improvements
erthalion Feb 12, 2020
55873f0
Add test for both ways to enable connection pool
erthalion Feb 13, 2020
b66b163
add validation for postgresql CRD
FxKu Feb 13, 2020
f2c9905
reflect connectionPool validation in Go code and publish in manifests…
FxKu Feb 13, 2020
6dad833
Cleanup configuration
erthalion Feb 13, 2020
be438b7
WIP Connection pooler support
erthalion Jan 14, 2020
c028be4
Improve cleaning up
erthalion Jan 15, 2020
7254039
Add CRD configuration
erthalion Jan 20, 2020
8bd2086
Add more tests
erthalion Jan 22, 2020
3ff1147
Various improvements
erthalion Feb 12, 2020
82e9d40
Add test for both ways to enable connection pool
erthalion Feb 13, 2020
17d077e
add validation for postgresql CRD
FxKu Feb 13, 2020
f0ceafa
reflect connectionPool validation in Go code and publish in manifests…
FxKu Feb 13, 2020
2384e1e
Cleanup configuration
erthalion Feb 13, 2020
c9a1c8e
add enableConnectionPool to validation and some nior fixes
FxKu Feb 13, 2020
99f2b03
add enableConnectionPool to validation and some nior fixes
FxKu Feb 13, 2020
4f2457b
clean up merge conflict
FxKu Feb 13, 2020
6ddac2f
update codegen
FxKu Feb 13, 2020
e266484
Add a real pgbouncer image
erthalion Feb 13, 2020
e11f787
Rename replicas to avoid potential confusion about terminology
erthalion Feb 13, 2020
8a81bc7
Capture output for debugging purposes
erthalion Feb 13, 2020
898d441
And output the resulting completed process
erthalion Feb 13, 2020
447a659
Report status in e2e
erthalion Feb 14, 2020
0095be0
Fix uninitialized ConnectionPool structure usage
erthalion Feb 14, 2020
a9d02ba
Address review
erthalion Feb 14, 2020
515bb2d
Address review, add ConnectionPool init for sync
erthalion Feb 17, 2020
4add317
Merge branch 'master' into feature/connection-pooler
erthalion Feb 17, 2020
35d82e5
Do sync also when there are no deployment
erthalion Feb 17, 2020
97217e2
Delete if a new specification is nil
erthalion Feb 17, 2020
6612933
Adjust sync logic
erthalion Feb 19, 2020
2afaa59
update code-gen
FxKu Feb 19, 2020
cf85db5
merge with master and resolve conflict
FxKu Feb 20, 2020
619c543
E2E tests for connection pool
erthalion Feb 20, 2020
3e98832
Add more tests
erthalion Feb 24, 2020
037d712
Sync due to defaults
erthalion Mar 2, 2020
918df14
Add possibility to set max db connections
erthalion Mar 3, 2020
2bba673
update codegen
FxKu Mar 4, 2020
4d12615
reflect new pooler parameter in validation + define same pooler image…
FxKu Mar 4, 2020
e0df9de
Sync in case of missing deployment
erthalion Mar 4, 2020
a38a5aa
Add test for sync with flag
erthalion Mar 5, 2020
07adaf2
Extend labels for connection pool
erthalion Mar 5, 2020
f1646c8
minor changes to docs and manifests
FxKu Mar 5, 2020
e645ca5
Prevent original labels from update
erthalion Mar 5, 2020
ab118dd
Prevent operator from wrongly syncing pooler user
erthalion Mar 5, 2020
80fee17
Various fixes
erthalion Mar 6, 2020
e6f1e8b
Merge branch 'master' into feature/connection-pooler
erthalion Mar 6, 2020
2e02379
Fix tests
erthalion Mar 6, 2020
c0a840c
Sync other way around
erthalion Mar 9, 2020
6d1a1ea
Fix role sync if default pool user/schema changed
erthalion Mar 13, 2020
4d61adf
Merge branch 'master' into feature/connection-pooler
erthalion Mar 16, 2020
cf6541b
Address feedback
erthalion Mar 17, 2020
1c7065e
Address feedback
erthalion Mar 17, 2020
48cdbb6
Minor improvements
erthalion Mar 19, 2020
20b2fb4
Defaults for user/schema fix
erthalion Mar 19, 2020
6ae3c3d
Adjust default resource configuration
erthalion Mar 19, 2020
f839806
Address feedback
erthalion Mar 19, 2020
7a9d898
Set min number of instances to 2
erthalion Mar 20, 2020
1ca8028
use min instances 2 everywhere and update reference docs
FxKu Mar 20, 2020
0aff65e
fix typo
FxKu Mar 20, 2020
bdb3eaf
some more minor changes
FxKu Mar 20, 2020
b0f5347
update pooler default image and add explanation for maxDBConnections …
FxKu Mar 20, 2020
21af410
lower CPU request and update docs
FxKu Mar 20, 2020
9f51d73
Use connection pool labels
erthalion Mar 24, 2020
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
41 changes: 41 additions & 0 deletions charts/postgres-operator/crds/operatorconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,47 @@ spec:
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
scalyr_server_url:
type: string
connection_pool:
type: object
properties:
connection_pool_schema:
type: string
#default: "pooler"
connection_pool_user:
type: string
#default: "pooler"
connection_pool_image:
type: string
#default: "registry.opensource.zalan.do/acid/pgbouncer"
connection_pool_max_db_connections:
type: integer
#default: 60
connection_pool_mode:
type: string
enum:
- "session"
- "transaction"
#default: "transaction"
connection_pool_number_of_instances:
type: integer
minimum: 2
#default: 2
connection_pool_default_cpu_limit:
type: string
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
#default: "1"
connection_pool_default_cpu_request:
type: string
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
#default: "500m"
connection_pool_default_memory_limit:
type: string
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
#default: "100Mi"
connection_pool_default_memory_request:
type: string
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
#default: "100Mi"
status:
type: object
additionalProperties:
Expand Down
51 changes: 51 additions & 0 deletions charts/postgres-operator/crds/postgresqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,64 @@ spec:
uid:
format: uuid
type: string
connectionPool:
type: object
properties:
dockerImage:
type: string
maxDBConnections:
type: integer
mode:
type: string
enum:
- "session"
- "transaction"
numberOfInstances:
type: integer
minimum: 2
resources:
type: object
required:
- requests
- limits
properties:
limits:
type: object
required:
- cpu
- memory
properties:
cpu:
type: string
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
memory:
type: string
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
requests:
type: object
required:
- cpu
- memory
properties:
cpu:
type: string
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
memory:
type: string
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
schema:
type: string
user:
type: string
databases:
type: object
additionalProperties:
type: string
# Note: usernames specified here as database owners must be declared in the users key of the spec key.
dockerImage:
type: string
enableConnectionPool:
type: boolean
enableLogicalBackup:
type: boolean
enableMasterLoadBalancer:
Expand Down
1 change: 1 addition & 0 deletions charts/postgres-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ rules:
- apps
resources:
- statefulsets
- deployments
verbs:
- create
- delete
Expand Down
1 change: 1 addition & 0 deletions charts/postgres-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ data:
{{ toYaml .Values.configDebug | indent 2 }}
{{ toYaml .Values.configLoggingRestApi | indent 2 }}
{{ toYaml .Values.configTeamsApi | indent 2 }}
{{ toYaml .Values.configConnectionPool | indent 2 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ configuration:
{{ toYaml .Values.configLoggingRestApi | indent 4 }}
scalyr:
{{ toYaml .Values.configScalyr | indent 4 }}
connection_pool:
{{ toYaml .Values.configConnectionPool | indent 4 }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/postgres-operator/values-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ configScalyr:
# Memory request value for the Scalyr sidecar
scalyr_memory_request: 50Mi

configConnectionPool:
# db schema to install lookup function into
connection_pool_schema: "pooler"
# db user for pooler to use
connection_pool_user: "pooler"
# docker image
connection_pool_image: "registry.opensource.zalan.do/acid/pgbouncer"
# max db connections the pooler should hold
connection_pool_max_db_connections: 60
# default pooling mode
connection_pool_mode: "transaction"
# number of pooler instances
connection_pool_number_of_instances: 2
# default resources
connection_pool_default_cpu_request: 500m
connection_pool_default_memory_request: 100Mi
connection_pool_default_cpu_limit: "1"
connection_pool_default_memory_limit: 100Mi

rbac:
# Specifies whether RBAC resources should be created
create: true
Expand Down
20 changes: 20 additions & 0 deletions charts/postgres-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ configTeamsApi:
# URL of the Teams API service
# teams_api_url: http://fake-teams-api.default.svc.cluster.local

# configure connection pooler deployment created by the operator
configConnectionPool:
# db schema to install lookup function into
connection_pool_schema: "pooler"
# db user for pooler to use
connection_pool_user: "pooler"
# docker image
connection_pool_image: "registry.opensource.zalan.do/acid/pgbouncer"
# max db connections the pooler should hold
connection_pool_max_db_connections: 60
# default pooling mode
connection_pool_mode: "transaction"
# number of pooler instances
connection_pool_number_of_instances: 2
# default resources
connection_pool_default_cpu_request: 500m
connection_pool_default_memory_request: 100Mi
connection_pool_default_cpu_limit: "1"
connection_pool_default_memory_limit: 100Mi

rbac:
# Specifies whether RBAC resources should be created
create: true
Expand Down
13 changes: 11 additions & 2 deletions docker/DebugDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ MAINTAINER Team ACID @ Zalando <team-acid@zalando.de>

# We need root certificates to deal with teams api over https
RUN apk --no-cache add ca-certificates go git musl-dev
RUN go get github.com/derekparker/delve/cmd/dlv

COPY build/* /

CMD ["/root/go/bin/dlv", "--listen=:7777", "--headless=true", "--api-version=2", "exec", "/postgres-operator"]
RUN addgroup -g 1000 pgo
RUN adduser -D -u 1000 -G pgo -g 'Postgres Operator' pgo

RUN go get github.com/derekparker/delve/cmd/dlv
RUN cp /root/go/bin/dlv /dlv
RUN chown -R pgo:pgo /dlv

USER pgo:pgo
RUN ls -l /

CMD ["/dlv", "--listen=:7777", "--headless=true", "--api-version=2", "exec", "/postgres-operator"]
34 changes: 34 additions & 0 deletions docs/reference/cluster_manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ These parameters are grouped directly under the `spec` key in the manifest.
is `false`, then no volume will be mounted no matter how operator was
configured (so you can override the operator configuration). Optional.

* **enableConnectionPool**
Tells the operator to create a connection pool with a database. If this
field is true, a connection pool deployment will be created even if
`connectionPool` section is empty. Optional, not set by default.

* **enableLogicalBackup**
Determines if the logical backup of this cluster should be taken and uploaded
to S3. Default: false. Optional.
Expand Down Expand Up @@ -360,6 +365,35 @@ CPU and memory limits for the sidecar container.
memory limits for the sidecar container. Optional, overrides the
`default_memory_limits` operator configuration parameter. Optional.

## Connection pool

Parameters are grouped under the `connectionPool` top-level key and specify
configuration for connection pool. If this section is not empty, a connection
pool will be created for a database even if `enableConnectionPool` is not
present.

* **numberOfInstances**
How many instances of connection pool to create.

* **schema**
Schema to create for credentials lookup function.

* **user**
User to create for connection pool to be able to connect to a database.

* **dockerImage**
Which docker image to use for connection pool deployment.

* **maxDBConnections**
How many connections the pooler can max hold. This value is divided among the
pooler pods.

* **mode**
In which mode to run connection pool, transaction or session.

* **resources**
Resource configuration for connection pool deployment.

## Custom TLS certificates

Those parameters are grouped under the `tls` top-level key.
Expand Down
37 changes: 37 additions & 0 deletions docs/reference/operator_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,40 @@ scalyr sidecar. In the CRD-based configuration they are grouped under the

* **scalyr_memory_limit**
Memory limit value for the Scalyr sidecar. The default is `500Mi`.

## Connection pool configuration

Parameters are grouped under the `connection_pool` top-level key and specify
default configuration for connection pool, if a postgres manifest requests it
but do not specify some of the parameters. All of them are optional with the
operator being able to provide some reasonable defaults.

* **connection_pool_number_of_instances**
How many instances of connection pool to create. Default is 2 which is also
the required minimum.

* **connection_pool_schema**
Schema to create for credentials lookup function. Default is `pooler`.

* **connection_pool_user**
User to create for connection pool to be able to connect to a database.
Default is `pooler`.

* **connection_pool_image**
Docker image to use for connection pool deployment.
Default: "registry.opensource.zalan.do/acid/pgbouncer"

* **connection_pool_max_db_connections**
How many connections the pooler can max hold. This value is divided among the
pooler pods. Default is 60 which will make up 30 connections per pod for the
default setup with two instances.

* **connection_pool_mode**
Default pool mode, `session` or `transaction`. Default is `transaction`.

* **connection_pool_default_cpu_request**
**connection_pool_default_memory_reques**
**connection_pool_default_cpu_limit**
**connection_pool_default_memory_limit**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these params take into account the set_memory_request_to_limit parameter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I don't think they need to - probably it makes sense to make those always equal just by default, since connection pooler resource requirements are usually rather stable.

Default resource configuration for connection pool deployment. The internal
default for memory request and limit is `100Mi`, for CPU it is `500m` and `1`.
53 changes: 53 additions & 0 deletions docs/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,59 @@ monitoring is outside the scope of operator responsibilities. See
[administrator documentation](administrator.md) for details on how backups are
executed.

## Connection pool

The operator can create a database side connection pool for those applications,
where an application side pool is not feasible, but a number of connections is
high. To create a connection pool together with a database, modify the
manifest:

```yaml
spec:
enableConnectionPool: true
```

This will tell the operator to create a connection pool with default
configuration, through which one can access the master via a separate service
`{cluster-name}-pooler`. In most of the cases provided default configuration
should be good enough.

To configure a new connection pool, specify:

```
spec:
connectionPool:
# how many instances of connection pool to create
number_of_instances: 2

# in which mode to run, session or transaction
mode: "transaction"

# schema, which operator will create to install credentials lookup
# function
schema: "pooler"

# user, which operator will create for connection pool
user: "pooler"

# resources for each instance
resources:
requests:
cpu: 500m
memory: 100Mi
limits:
cpu: "1"
memory: 100Mi
```

By default `pgbouncer` is used to create a connection pool. To find out about
pool modes see [docs](https://www.pgbouncer.org/config.html#pool_mode) (but it
should be general approach between different implementation).

Note, that using `pgbouncer` means meaningful resource CPU limit should be less
than 1 core (there is a way to utilize more than one, but in K8S it's easier
just to spin up more instances).

## Custom TLS certificates

By default, the spilo image generates its own TLS certificate during startup.
Expand Down
Loading