feat(config): add connection_pooler generate-config fields

This commit is contained in:
Mitch Murphy 2026-06-05 13:43:56 -04:00
parent 40b6c68443
commit 9787922bf9
2 changed files with 47 additions and 10 deletions

View File

@ -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

View File

@ -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)
}
}