Skip to content

K8SPG-1062: treat pgbouncer with 0 replicas as disabled#1670

Open
pooknull wants to merge 4 commits into
mainfrom
K8SPG-1062
Open

K8SPG-1062: treat pgbouncer with 0 replicas as disabled#1670
pooknull wants to merge 4 commits into
mainfrom
K8SPG-1062

Conversation

@pooknull

@pooknull pooknull commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

https://perconadev.atlassian.net/browse/K8SPG-1062

DESCRIPTION

Problem:
When pgbouncer is scaled down to 0, it's service remains and pg endpoint is still points to the pgbouncer service.

Solution:
Operator should treat pgbouncer with 0 size as disabled throughout the operator.

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PG version?
  • Does the change support oldest and newest supported Kubernetes version?

@pooknull
pooknull marked this pull request as ready for review July 14, 2026 10:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses K8SPG-1062 by making the operator treat PgBouncer configured with replicas: 0 as disabled, preventing the Pg endpoint/host selection and reconciliation from continuing to target or maintain PgBouncer resources when it is intentionally scaled to zero.

Changes:

  • Added PGBouncerEnabled() helpers to both upstream (v1beta1) and Percona (v2) proxy specs to centralize the “replicas == 0 means disabled” logic.
  • Updated host selection and PgBouncer reconciliation paths to use PGBouncerEnabled() instead of only checking for nil proxy/PgBouncer configs.
  • Added unit test coverage for the “zero replicas” behavior in host selection and PgBouncer Service generation.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/apis/upstream.pgv2.percona.com/v1beta1/postgrescluster_types.go Adds PostgresProxySpec.PGBouncerEnabled() to treat replicas: 0 as disabled for upstream clusters.
pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go Adds PGProxySpec.PGBouncerEnabled() for Percona CRD usage.
percona/controller/pgcluster/status.go Uses PGBouncerEnabled() to select primary service host when PgBouncer is effectively disabled.
percona/controller/pgcluster/gethost_test.go Adds a test case ensuring replicas: 0 results in primary-service host selection.
internal/pgbouncer/reconcile.go Skips PgBouncer asset reconciliation when PGBouncerEnabled() is false.
internal/controller/postgrescluster/postgres.go Avoids adding PgBouncer connection info to user secrets when replicas: 0.
internal/controller/postgrescluster/pgbouncer.go Treats replicas: 0 like disabled across PgBouncer resource reconciliation (create/update vs delete).
internal/controller/postgrescluster/pgbouncer_test.go Adds a test ensuring PgBouncer Service is not “specified” when replicas: 0.

@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
backup-enable-disable passed 00:00:00
builtin-extensions passed 00:00:00
cert-manager-tls passed 00:00:00
custom-envs passed 00:00:00
custom-tls passed 00:00:00
database-init-sql passed 00:00:00
demand-backup passed 00:00:00
demand-backup-offline-snapshot passed 00:13:35
dynamic-configuration passed 00:00:00
finalizers passed 00:00:00
init-deploy passed 00:00:00
huge-pages passed 00:00:00
major-upgrade-14-to-15 passed 00:00:00
major-upgrade-15-to-16 passed 00:00:00
major-upgrade-16-to-17 passed 00:00:00
major-upgrade-17-to-18 passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
monitoring passed 00:00:00
monitoring-pmm3 passed 00:00:00
one-pod passed 00:00:00
operator-self-healing passed 00:00:00
pitr passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
self-healing passed 00:00:00
sidecars passed 00:00:00
standby-pgbackrest passed 00:00:00
standby-streaming passed 00:00:00
start-from-backup passed 00:00:00
tablespaces passed 00:00:00
telemetry-transfer passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-minor passed 00:00:00
users passed 00:00:00
migration-from-crunchy-standby passed 00:00:00
migration-from-crunchy-pv passed 00:00:00
migration-from-crunchy-backup-restore passed 00:00:00
Summary Value
Tests Run 38/38
Job Duration 00:27:42
Total Test Time 00:13:35

commit: 5ae8a8d
image: perconalab/percona-postgresql-operator:PR-1670-5ae8a8d55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants