From 9787922bf9ea69a8b95ef0153678cf50ee441c68 Mon Sep 17 00:00:00 2001 From: Mitch Murphy Date: Fri, 5 Jun 2026 13:43:56 -0400 Subject: [PATCH] feat(config): add connection_pooler generate-config fields --- pkg/util/config/config.go | 25 +++++++++++++++---------- pkg/util/config/config_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index a14022407..02f1c9930 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -153,16 +153,21 @@ type LogicalBackup struct { // Operator options for connection pooler type ConnectionPooler struct { - NumberOfInstances *int32 `name:"connection_pooler_number_of_instances" default:"2"` - Schema string `name:"connection_pooler_schema" default:"pooler"` - User string `name:"connection_pooler_user" default:"pooler"` - Image string `name:"connection_pooler_image" default:"ghcr.io/zalando/postgres-operator/pgbouncer:latest"` - Mode string `name:"connection_pooler_mode" default:"transaction"` - MaxDBConnections *int32 `name:"connection_pooler_max_db_connections" default:"60"` - ConnectionPoolerDefaultCPURequest string `name:"connection_pooler_default_cpu_request"` - ConnectionPoolerDefaultMemoryRequest string `name:"connection_pooler_default_memory_request"` - ConnectionPoolerDefaultCPULimit string `name:"connection_pooler_default_cpu_limit"` - ConnectionPoolerDefaultMemoryLimit string `name:"connection_pooler_default_memory_limit"` + NumberOfInstances *int32 `name:"connection_pooler_number_of_instances" default:"2"` + Schema string `name:"connection_pooler_schema" default:"pooler"` + User string `name:"connection_pooler_user" default:"pooler"` + Image string `name:"connection_pooler_image" default:"ghcr.io/zalando/postgres-operator/pgbouncer:latest"` + Mode string `name:"connection_pooler_mode" default:"transaction"` + MaxDBConnections *int32 `name:"connection_pooler_max_db_connections" default:"60"` + ConnectionPoolerDefaultCPURequest string `name:"connection_pooler_default_cpu_request"` + ConnectionPoolerDefaultMemoryRequest string `name:"connection_pooler_default_memory_request"` + ConnectionPoolerDefaultCPULimit string `name:"connection_pooler_default_cpu_limit"` + ConnectionPoolerDefaultMemoryLimit string `name:"connection_pooler_default_memory_limit"` + GenerateConfig bool `name:"connection_pooler_generate_config" default:"false"` + Command []string `name:"connection_pooler_command"` + Args []string `name:"connection_pooler_args" default:"/etc/pgbouncer/pgbouncer.ini"` + AuthType string `name:"connection_pooler_auth_type" default:"scram-sha-256"` + ConfigPath string `name:"connection_pooler_config_path" default:"/etc/pgbouncer/pgbouncer.ini"` } // Config describes operator config diff --git a/pkg/util/config/config_test.go b/pkg/util/config/config_test.go index c5fd48d93..c5f7a2dac 100644 --- a/pkg/util/config/config_test.go +++ b/pkg/util/config/config_test.go @@ -335,3 +335,35 @@ func TestNewFromMap(t *testing.T) { }) } } + +func TestConnectionPoolerGenerateConfigDefaults(t *testing.T) { + cfg := NewFromMap(map[string]string{}) + + if cfg.ConnectionPooler.GenerateConfig { + t.Errorf("expected GenerateConfig default false, got true") + } + if cfg.ConnectionPooler.AuthType != "scram-sha-256" { + t.Errorf("expected AuthType scram-sha-256, got %q", cfg.ConnectionPooler.AuthType) + } + if cfg.ConnectionPooler.ConfigPath != "/etc/pgbouncer/pgbouncer.ini" { + t.Errorf("expected ConfigPath /etc/pgbouncer/pgbouncer.ini, got %q", cfg.ConnectionPooler.ConfigPath) + } + if len(cfg.ConnectionPooler.Args) != 1 || cfg.ConnectionPooler.Args[0] != "/etc/pgbouncer/pgbouncer.ini" { + t.Errorf("expected Args [/etc/pgbouncer/pgbouncer.ini], got %#v", cfg.ConnectionPooler.Args) + } + + cfg2 := NewFromMap(map[string]string{ + "connection_pooler_generate_config": "true", + "connection_pooler_auth_type": "md5", + "connection_pooler_args": "/custom/pgbouncer.ini", + }) + if !cfg2.ConnectionPooler.GenerateConfig { + t.Errorf("expected GenerateConfig true") + } + if cfg2.ConnectionPooler.AuthType != "md5" { + t.Errorf("expected AuthType md5, got %q", cfg2.ConnectionPooler.AuthType) + } + if len(cfg2.ConnectionPooler.Args) != 1 || cfg2.ConnectionPooler.Args[0] != "/custom/pgbouncer.ini" { + t.Errorf("expected Args [/custom/pgbouncer.ini], got %#v", cfg2.ConnectionPooler.Args) + } +}