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
5 changes: 5 additions & 0 deletions chart/newsfragments/71237.significant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PgBouncer Deployment now sets ``terminationGracePeriodSeconds`` (default ``120``)

The PgBouncer Deployment previously relied on the Kubernetes default termination grace period of 30 seconds, which SIGKILLed the pod mid-drain: the chart's default preStop hook (``killall -INT pgbouncer && sleep 120``) needs up to 120 seconds to drain client connections, so on a node drain or eviction in-flight connections were cut after 30 seconds instead of being released.

The new ``pgbouncer.terminationGracePeriodSeconds`` value defaults to ``120`` to match the preStop drain window. PgBouncer exits as soon as the last client connection is released, so the full 120 seconds is an upper bound, not a fixed wait. Set the value to ``30`` to restore the previous behaviour.
1 change: 1 addition & 0 deletions chart/templates/pgbouncer/pgbouncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ spec:
{{- end }}
tolerations: {{- toYaml $tolerations | nindent 8 }}
topologySpreadConstraints: {{- toYaml $topologySpreadConstraints | nindent 8 }}
terminationGracePeriodSeconds: {{ .Values.pgbouncer.terminationGracePeriodSeconds }}
serviceAccountName: {{ include "pgbouncer.serviceAccountName" . }}
enableServiceLinks: {{ .Values.enableServiceLinks }}
securityContext: {{ $securityContext | nindent 8 }}
Expand Down
14 changes: 14 additions & 0 deletions chart/tests/helm_tests/other/test_pgbouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,20 @@ def test_should_add_component_specific_labels(self):
assert "labels" in jmespath.search("spec.template.metadata", docs[0])
assert jmespath.search("spec.template.metadata.labels", docs[0])["test_label"] == "test_label_value"

@pytest.mark.parametrize(
("pgbouncer_values", "expected"),
[
({"enabled": True}, 120),
({"enabled": True, "terminationGracePeriodSeconds": 30}, 30),
],
)
def test_pgbouncer_termination_grace_period_seconds(self, pgbouncer_values, expected):
docs = render_chart(
values={"pgbouncer": pgbouncer_values},
show_only=["templates/pgbouncer/pgbouncer-deployment.yaml"],
)
assert expected == jmespath.search("spec.template.spec.terminationGracePeriodSeconds", docs[0])


class TestPgbouncerConfig:
"""Tests PgBouncer config."""
Expand Down
6 changes: 6 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7801,6 +7801,12 @@
}
]
},
"terminationGracePeriodSeconds": {
"description": "Grace period for PgBouncer to finish after SIGTERM is sent from Kubernetes. The default matches the default preStop hook, which needs up to 120 seconds to drain client connections.",
"type": "integer",
"default": 120,
"x-docsSection": "Kubernetes"
},
"securityContexts": {
"description": "Security context definition for the PgBouncer.",
"type": "object",
Expand Down
6 changes: 6 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,12 @@ pgbouncer:
# Allow existing queries clients to complete within 120 seconds
command: ["/bin/sh", "-c", "killall -INT pgbouncer && sleep 120"]

# Grace period for PgBouncer to finish after SIGTERM is sent from Kubernetes.
# Matches the default preStop hook above, which needs up to 120 seconds to
# drain client connections; with a shorter grace period the pod is killed
# mid-drain and in-flight connections are cut.
terminationGracePeriodSeconds: 120

metricsExporterSidecar:
resources: {}
# limits:
Expand Down