Skip to content

Commit

Permalink
feat(cluster): Added additional PgBouncer configuration options
Browse files Browse the repository at this point in the history
* Added monitoring settings
* Added pooler.type
* Added pooler.template to allow altering the pooler deployment

Signed-off-by: Itay Grudev <[email protected]>
  • Loading branch information
itay-grudev committed Mar 17, 2024
1 parent 866413f commit b62544d
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runs:
echo "Cluster not ready"
exit 1
fi
READY_INSTANCES=$(kubectl get cluster ${INPUT_CLUSTER_NAME} -o jsonpath='{.status.readyInstances}')
READY_INSTANCES=$(kubectl get clusters.postgresql.cnpg.io ${INPUT_CLUSTER_NAME} -o jsonpath='{.status.readyInstances}')
if [[ "$READY_INSTANCES" == ${INPUT_READY_INSTANCES} ]]; then
echo "Cluster up and running"
break
Expand Down
32 changes: 32 additions & 0 deletions .github/actions/verify-pooler-ready/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Verifies that a CNPG cluster has a certain amount of ready instances
description: Verifies that a CNPG cluster has a certain amount of ready instances
inputs:
pooler-name:
description: The name of the pooler to verify
required: true
default: database-cluster
ready-instances:
description: The amount of ready instances to wait for
required: true
default: "3"

runs:
using: composite
steps:
- name: Wait for cluster to become ready
shell: bash
run: |
ITER=0
while true; do
if [[ $ITER -ge 300 ]]; then
echo "Cluster not ready"
exit 1
fi
READY_INSTANCES=$(kubectl get cluster ${INPUT_POOLER_NAME} -o jsonpath='{.status.readyInstances}')
if [[ "$READY_INSTANCES" == ${INPUT_READY_INSTANCES} ]]; then
echo "Cluster up and running"
break
fi
sleep 1
(( ++ITER ))
done
37 changes: 36 additions & 1 deletion .github/workflows/tests-cluster-standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,42 @@ jobs:
database ./charts/cluster
- name: Verify that the cluster is ready
uses: ./.github/actions/verify-ready-instances
uses: ./.github/actions/verify-cluster-ready
with:
cluster-name: database-cluster
ready-instances: 1

test-cluster-pgbouncer:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Setup kind
uses: ./.github/actions/setup-kind

- name: Deploy the operator
uses: ./.github/actions/deploy-operator

- name: Deploy a standalone cluster
run: |
helm upgrade --install \
--values charts/cluster/examples/pgbouncer.yaml \
--namespace database \
--create-namespace \
--wait \
database ./charts/cluster
- name: Verify that the cluster is ready
uses: ./.github/actions/verify-cluster-ready
with:
cluster-name: database-cluster
ready-instances: 1

- name: Verify that the pooler is ready
uses: ./.github/actions/verify-pooler-ready
with:
pooler-name: database-cluster-pooler-rw
ready-instances: 1
2 changes: 1 addition & 1 deletion .github/workflows/tests-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
EOF
- name: Verify that the cluster is ready
uses: ./.github/actions/verify-ready-instances
uses: ./.github/actions/verify-cluster-ready
with:
cluster-name: cluster-example
ready-instances: 3
13 changes: 9 additions & 4 deletions charts/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| cluster.initdb | object | `{}` | BootstrapInitDB is the configuration of the bootstrap process when initdb is used See: https://cloudnative-pg.io/documentation/current/bootstrap/ See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-bootstrapinitdb |
| cluster.instances | int | `3` | Number of instances |
| cluster.logLevel | string | `"info"` | The instances' log level, one of the following values: error, warning, info (default), debug, trace |
| cluster.monitoring.customQueries | list | `[]` | |
| cluster.monitoring.enabled | bool | `false` | |
| cluster.monitoring.podMonitor.enabled | bool | `true` | |
| cluster.monitoring.prometheusRule.enabled | bool | `true` | |
| cluster.monitoring.customQueries | list | `[]` | Custom Prometheus metrics |
| cluster.monitoring.enabled | bool | `false` | Whether to enable monitoring |
| cluster.monitoring.podMonitor.enabled | bool | `true` | Whether to enable the PodMonitor |
| cluster.monitoring.prometheusRule | object | `{"enabled":true}` | PrometheusRule Automated Alerts |
| cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts |
| cluster.postgresGID | int | `26` | The GID of the postgres user inside the image, defaults to 26 |
| cluster.postgresUID | int | `26` | The UID of the postgres user inside the image, defaults to 26 |
| cluster.postgresql | object | `{}` | Configuration of the PostgreSQL server See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-PostgresConfiguration |
Expand All @@ -167,8 +168,12 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| nameOverride | string | `""` | Override the name of the chart |
| pooler.enabled | bool | `false` | Whether to enable PgBouncer |
| pooler.instances | int | `3` | Number of PgBouncer instances |
| pooler.monitoring.enabled | bool | `false` | Whether to enable monitoring |
| pooler.monitoring.podMonitor.enabled | bool | `true` | Whether to enable the PodMonitor |
| pooler.parameters | object | `{"default_pool_size":"25","max_client_conn":"1000"}` | PgBouncer configuration parameters |
| pooler.poolMode | string | `"transaction"` | PgBouncer pooling mode |
| pooler.template | object | `{}` | Custom PgBouncer deployment template Use to override image, specify resources, etc. |
| pooler.type | string | `"rw"` | PgBouncer type of service to forward traffic to. |
| recovery.azure.connectionString | string | `""` | |
| recovery.azure.containerName | string | `""` | |
| recovery.azure.inheritFromAzureAD | bool | `false` | |
Expand Down
8 changes: 8 additions & 0 deletions charts/cluster/examples/pgbouncer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mode: standalone
cluster:
instances: 1
backups:
enabled: false
pooler:
enabled: true
instances: 1
10 changes: 8 additions & 2 deletions charts/cluster/templates/pooler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ spec:
cluster:
name: {{ include "cluster.fullname" . }}
instances: {{ .Values.pooler.instances }}
type: rw
type: {{ .Values.pooler.type }}
pgbouncer:
poolMode: {{ .Values.pooler.poolMode }}
parameters:
{{- .Values.pooler.parameters | toYaml | nindent 6 }}
{{ end }}
monitoring:
enablePodMonitor: {{ and .Values.pooler.monitoring.enabled .Values.pooler.monitoring.podMonitor.enabled }}
{{- with .Values.pooler.template }}
template:
{{- . | toYaml | nindent 4 }}
{{- end }}
{{ end }}
22 changes: 22 additions & 0 deletions charts/cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@
"instances": {
"type": "integer"
},
"monitoring": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"podMonitor": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
},
"parameters": {
"type": "object",
"properties": {
Expand All @@ -241,6 +257,12 @@
},
"poolMode": {
"type": "string"
},
"template": {
"type": "object"
},
"type": {
"type": "string"
}
}
},
Expand Down
18 changes: 18 additions & 0 deletions charts/cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,16 @@ cluster:
superuserSecret: ""

monitoring:
# -- Whether to enable monitoring
enabled: false
podMonitor:
# -- Whether to enable the PodMonitor
enabled: true
# -- PrometheusRule Automated Alerts
prometheusRule:
# -- Whether to enable the PrometheusRule automated alerts
enabled: true
# -- Custom Prometheus metrics
customQueries: []
# - name: "pg_cache_hit_ratio"
# query: "SELECT current_database() as datname, sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio FROM pg_statio_user_tables;"
Expand Down Expand Up @@ -224,6 +229,8 @@ backups:
pooler:
# -- Whether to enable PgBouncer
enabled: false
# -- PgBouncer type of service to forward traffic to.
type: rw
# -- PgBouncer pooling mode
poolMode: transaction
# -- Number of PgBouncer instances
Expand All @@ -232,3 +239,14 @@ pooler:
parameters:
max_client_conn: "1000"
default_pool_size: "25"

monitoring:
# -- Whether to enable monitoring
enabled: false
podMonitor:
# -- Whether to enable the PodMonitor
enabled: true

# -- Custom PgBouncer deployment template
# Use to override image, specify resources, etc.
template: {}

0 comments on commit b62544d

Please sign in to comment.