Skip to content

Commit

Permalink
feat(cluster): Allow to deploy multiple poolers (cloudnative-pg#357)
Browse files Browse the repository at this point in the history
* feat(cluster): Allow to deploy multiple poolers
* Update NOTES.txt

---------

Signed-off-by: Dmitriy Alekseev <[email protected]>
Signed-off-by: Itay Grudev <[email protected]>
Signed-off-by: Itay Grudev <[email protected]>
Co-authored-by: Itay Grudev <[email protected]>
Co-authored-by: Itay Grudev <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent 4647b6f commit 75a26f7
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 126 deletions.
31 changes: 28 additions & 3 deletions charts/cluster/examples/pgbouncer.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
type: postgresql
mode: standalone

cluster:
instances: 1
monitoring:
enabled: true
podMonitor:
enabled: true

backups:
enabled: false
pooler:
enabled: true
instances: 1

poolers:
- name: rw
type: rw
instances: 1
monitoring:
enabled: true
podMonitor:
enabled: true
relabelings:
- targetLabel: type
replacement: rw
- name: ro
type: ro
instances: 1
monitoring:
enabled: true
podMonitor:
enabled: true
relabelings:
- targetLabel: type
replacement: ro
2 changes: 1 addition & 1 deletion charts/cluster/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Configuration
{{- end }}
│ Storage │ {{ printf "%-56s" .Values.cluster.storage.size }} │
│ Storage Class │ {{ printf "%-56s" (default "Default" .Values.cluster.storage.storageClass) }} │
│ PGBouncer │ {{ printf "%-56s" (ternary "Enabled" "Disabled" .Values.pooler.enabled) }} │
│ PGBouncer │ {{ printf "%-56s" (ternary "Enabled" "Disabled" (gt (len .Values.poolers) 0)) }} │
│ Monitoring │ {{ include (printf "%s%s" "cluster.color-" (ternary "ok" "error" .Values.cluster.monitoring.enabled)) (printf "%-56s" (ternary "Enabled" "Disabled" .Values.cluster.monitoring.enabled)) }} │
╰───────────────────┴──────────────────────────────────────────────────────────╯

Expand Down
35 changes: 19 additions & 16 deletions charts/cluster/templates/pooler.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
{{ if .Values.pooler.enabled }}
{{- range .Values.poolers }}
---
apiVersion: postgresql.cnpg.io/v1
kind: Pooler
metadata:
name: {{ include "cluster.fullname" . }}-pooler-rw
name: {{ include "cluster.fullname" $ }}-pooler-{{ .name }}
spec:
cluster:
name: {{ include "cluster.fullname" . }}
instances: {{ .Values.pooler.instances }}
type: {{ .Values.pooler.type }}
name: {{ include "cluster.fullname" $ }}
instances: {{ .instances }}
type: {{ default "rw" .type }}
pgbouncer:
poolMode: {{ .Values.pooler.poolMode }}
poolMode: {{ default "session" .poolMode }}
{{- with .parameters }}
parameters:
{{- .Values.pooler.parameters | toYaml | nindent 6 }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{ with .monitoring }}
monitoring:
enablePodMonitor: {{ and .Values.pooler.monitoring.enabled .Values.pooler.monitoring.podMonitor.enabled }}
{{- if not (empty .Values.pooler.monitoring.podMonitor.relabelings) }}
{{- with .Values.pooler.monitoring.podMonitor.relabelings }}
{{- if not (empty .podMonitor) }}
enablePodMonitor: {{ and .enabled .podMonitor.enabled }}
{{- with .podMonitor.relabelings }}
podMonitorRelabelings:
{{- toYaml . | nindent 6 }}
{{ end }}
{{- end }}
{{- if not (empty .Values.pooler.monitoring.podMonitor.metricRelabelings) }}
{{- with .Values.pooler.monitoring.podMonitor.metricRelabelings }}
{{- with .podMonitor.metricRelabelings }}
podMonitorMetricRelabelings:
{{- toYaml . | nindent 6 }}
{{ end }}
{{- end }}
{{- with .Values.pooler.template }}
{{- end }}
{{- end }}
{{- with .template }}
template:
{{- . | toYaml | nindent 4 }}
{{- end }}
{{ end }}
{{- end }}
33 changes: 31 additions & 2 deletions charts/cluster/test/monitoring/01-monitoring_cluster-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,39 @@ spec:
key: ''
name: ''
relabelings:
- targetLabel: environment
replacement: test
- targetLabel: type
replacement: rw
action: replace
- targetLabel: team
replacement: alpha
action: replace
metricRelabelings:
- action: replace
sourceLabels:
- cluster
targetLabel: cnpg_cluster
- action: labeldrop
regex: cluster
---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: monitoring-cluster-pooler-ro
spec:
selector:
matchLabels:
cnpg.io/poolerName: monitoring-cluster-pooler-ro
podMetricsEndpoints:
- bearerTokenSecret:
key: ''
name: ''
relabelings:
- targetLabel: type
replacement: ro
action: replace
- targetLabel: team
replacement: alpha
action: replace
metricRelabelings:
- action: replace
sourceLabels:
Expand Down
57 changes: 39 additions & 18 deletions charts/cluster/test/monitoring/01-monitoring_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,42 @@ cluster:
foo: bar
backups:
enabled: false
pooler:
enabled: true
instances: 1
monitoring:
enabled: true
podMonitor:
relabelings:
- targetLabel: environment
replacement: test
- targetLabel: team
replacement: alpha
metricRelabelings:
- action: replace
sourceLabels:
- cluster
targetLabel: cnpg_cluster
- action: labeldrop
regex: cluster
poolers:
- name: rw
type: rw
instances: 1
monitoring:
enabled: true
podMonitor:
enabled: true
relabelings:
- targetLabel: type
replacement: rw
- targetLabel: team
replacement: alpha
metricRelabelings:
- action: replace
sourceLabels:
- cluster
targetLabel: cnpg_cluster
- action: labeldrop
regex: cluster
- name: ro
type: ro
instances: 1
monitoring:
enabled: true
podMonitor:
enabled: true
relabelings:
- targetLabel: type
replacement: ro
- targetLabel: team
replacement: alpha
metricRelabelings:
- action: replace
sourceLabels:
- cluster
targetLabel: cnpg_cluster
- action: labeldrop
regex: cluster
21 changes: 20 additions & 1 deletion charts/cluster/test/pooler/01-pooler_cluster-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ metadata:
status:
readyReplicas: 2
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pooler-cluster-pooler-ro
status:
readyReplicas: 2
---
apiVersion: postgresql.cnpg.io/v1
kind: Pooler
metadata:
Expand All @@ -14,5 +21,17 @@ spec:
name: pooler-cluster
instances: 2
pgbouncer:
poolMode: transaction
poolMode: session
type: rw
---
apiVersion: postgresql.cnpg.io/v1
kind: Pooler
metadata:
name: pooler-cluster-pooler-ro
spec:
cluster:
name: pooler-cluster
instances: 2
pgbouncer:
poolMode: session
type: ro
10 changes: 7 additions & 3 deletions charts/cluster/test/pooler/01-pooler_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ cluster:
storageClass: standard
backups:
enabled: false
pooler:
enabled: true
instances: 2
poolers:
- name: rw
type: rw
instances: 2
- name: ro
type: ro
instances: 2
54 changes: 2 additions & 52 deletions charts/cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,58 +338,8 @@
"nameOverride": {
"type": "string"
},
"pooler": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"instances": {
"type": "integer"
},
"monitoring": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"podMonitor": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"metricRelabelings": {
"type": "array"
},
"relabelings": {
"type": "array"
}
}
}
}
},
"parameters": {
"type": "object",
"properties": {
"default_pool_size": {
"type": "string"
},
"max_client_conn": {
"type": "string"
}
}
},
"poolMode": {
"type": "string"
},
"template": {
"type": "object"
},
"type": {
"type": "string"
}
}
"poolers": {
"type": "array"
},
"recovery": {
"type": "object",
Expand Down
75 changes: 45 additions & 30 deletions charts/cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,33 +368,48 @@ imageCatalog:
# - image: ghcr.io/your_repo/your_image:your_tag
# major: 16

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
instances: 3
# -- PgBouncer configuration parameters
parameters:
max_client_conn: "1000"
default_pool_size: "25"

monitoring:
# -- Whether to enable monitoring
enabled: false
podMonitor:
# -- Whether to enable the PodMonitor
enabled: true
# --The list of relabelings for the PodMonitor.
# Applied to samples before scraping.
relabelings: []
# -- The list of metric relabelings for the PodMonitor.
# Applied to samples before ingestion.
metricRelabelings: []

# -- Custom PgBouncer deployment template.
# Use to override image, specify resources, etc.
template: {}
poolers: []
# -
# # -- Pooler name
# name: rw
# # -- PgBouncer type of service to forward traffic to.
# type: rw
# # -- PgBouncer pooling mode
# poolMode: transaction
# # -- Number of PgBouncer instances
# instances: 3
# # -- PgBouncer configuration parameters
# 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: {}
# -
# # -- Pooler name
# name: ro
# # -- PgBouncer type of service to forward traffic to.
# type: ro
# # -- PgBouncer pooling mode
# poolMode: transaction
# # -- Number of PgBouncer instances
# instances: 3
# # -- PgBouncer configuration parameters
# 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 75a26f7

Please sign in to comment.