mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-18 10:29:50 +02:00
remove Users section from Patroni Bootstrap (#2490)
This commit is contained in:
@@ -28,8 +28,8 @@ const (
|
|||||||
replicationUserName = "standby"
|
replicationUserName = "standby"
|
||||||
poolerUserName = "pooler"
|
poolerUserName = "pooler"
|
||||||
adminUserName = "admin"
|
adminUserName = "admin"
|
||||||
exampleSpiloConfig = `{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"test":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"100","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`
|
exampleSpiloConfig = `{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"100","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`
|
||||||
spiloConfigDiff = `{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"test":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`
|
spiloConfigDiff = `{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = logrus.New().WithField("test", "cluster")
|
var logger = logrus.New().WithField("test", "cluster")
|
||||||
@@ -1115,17 +1115,13 @@ func TestCompareSpiloConfiguration(t *testing.T) {
|
|||||||
ExpectedResult bool
|
ExpectedResult bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
`{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"test":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"100","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`,
|
`{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"100","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"test":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"200","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`,
|
`{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"200","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
`{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"test":{"password":"","options":["CREATEDB"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"200","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
`{}`,
|
`{}`,
|
||||||
false,
|
false,
|
||||||
|
|||||||
+2
-10
@@ -64,9 +64,8 @@ type patroniDCS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type pgBootstrap struct {
|
type pgBootstrap struct {
|
||||||
Initdb []interface{} `json:"initdb"`
|
Initdb []interface{} `json:"initdb"`
|
||||||
Users map[string]pgUser `json:"users"`
|
DCS patroniDCS `json:"dcs,omitempty"`
|
||||||
DCS patroniDCS `json:"dcs,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type spiloConfiguration struct {
|
type spiloConfiguration struct {
|
||||||
@@ -430,13 +429,6 @@ PatroniInitDBParams:
|
|||||||
config.PgLocalConfiguration[patroniPGHBAConfParameterName] = patroni.PgHba
|
config.PgLocalConfiguration[patroniPGHBAConfParameterName] = patroni.PgHba
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Bootstrap.Users = map[string]pgUser{
|
|
||||||
opConfig.PamRoleName: {
|
|
||||||
Password: "",
|
|
||||||
Options: []string{constants.RoleFlagCreateDB, constants.RoleFlagNoLogin},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := json.Marshal(config)
|
res, err := json.Marshal(config)
|
||||||
return string(res), err
|
return string(res), err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
|
|||||||
PamRoleName: "zalandos",
|
PamRoleName: "zalandos",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{}}}`,
|
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"dcs":{}}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subtest: "Patroni configured",
|
subtest: "Patroni configured",
|
||||||
@@ -102,24 +102,17 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
|
|||||||
Slots: map[string]map[string]string{"permanent_logical_1": {"type": "logical", "database": "foo", "plugin": "pgoutput"}},
|
Slots: map[string]map[string]string{"permanent_logical_1": {"type": "logical", "database": "foo", "plugin": "pgoutput"}},
|
||||||
FailsafeMode: util.True(),
|
FailsafeMode: util.True(),
|
||||||
},
|
},
|
||||||
opConfig: &config.Config{
|
opConfig: &config.Config{},
|
||||||
Auth: config.Auth{
|
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin","pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"synchronous_mode":true,"synchronous_mode_strict":true,"synchronous_node_count":1,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}},"failsafe_mode":true}}}`,
|
||||||
PamRoleName: "zalandos",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin","pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"synchronous_mode":true,"synchronous_mode_strict":true,"synchronous_node_count":1,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}},"failsafe_mode":true}}}`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subtest: "Patroni failsafe_mode configured globally",
|
subtest: "Patroni failsafe_mode configured globally",
|
||||||
pgParam: &acidv1.PostgresqlParam{PgVersion: "15"},
|
pgParam: &acidv1.PostgresqlParam{PgVersion: "15"},
|
||||||
patroni: &acidv1.Patroni{},
|
patroni: &acidv1.Patroni{},
|
||||||
opConfig: &config.Config{
|
opConfig: &config.Config{
|
||||||
Auth: config.Auth{
|
|
||||||
PamRoleName: "zalandos",
|
|
||||||
},
|
|
||||||
EnablePatroniFailsafeMode: util.True(),
|
EnablePatroniFailsafeMode: util.True(),
|
||||||
},
|
},
|
||||||
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":true}}}`,
|
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"dcs":{"failsafe_mode":true}}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subtest: "Patroni failsafe_mode configured globally, disabled for cluster",
|
subtest: "Patroni failsafe_mode configured globally, disabled for cluster",
|
||||||
@@ -128,12 +121,9 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
|
|||||||
FailsafeMode: util.False(),
|
FailsafeMode: util.False(),
|
||||||
},
|
},
|
||||||
opConfig: &config.Config{
|
opConfig: &config.Config{
|
||||||
Auth: config.Auth{
|
|
||||||
PamRoleName: "zalandos",
|
|
||||||
},
|
|
||||||
EnablePatroniFailsafeMode: util.True(),
|
EnablePatroniFailsafeMode: util.True(),
|
||||||
},
|
},
|
||||||
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":false}}}`,
|
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"dcs":{"failsafe_mode":false}}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subtest: "Patroni failsafe_mode disabled globally, configured for cluster",
|
subtest: "Patroni failsafe_mode disabled globally, configured for cluster",
|
||||||
@@ -142,12 +132,9 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
|
|||||||
FailsafeMode: util.True(),
|
FailsafeMode: util.True(),
|
||||||
},
|
},
|
||||||
opConfig: &config.Config{
|
opConfig: &config.Config{
|
||||||
Auth: config.Auth{
|
|
||||||
PamRoleName: "zalandos",
|
|
||||||
},
|
|
||||||
EnablePatroniFailsafeMode: util.False(),
|
EnablePatroniFailsafeMode: util.False(),
|
||||||
},
|
},
|
||||||
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":true}}}`,
|
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"dcs":{"failsafe_mode":true}}}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@@ -157,8 +144,8 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
|
|||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if tt.result != result {
|
if tt.result != result {
|
||||||
t.Errorf("%s %s: Spilo Config is %v, expected %v for role %#v and param %#v",
|
t.Errorf("%s %s: Spilo Config is %v, expected %v and param %#v",
|
||||||
t.Name(), tt.subtest, result, tt.result, tt.opConfig.Auth.PamRoleName, tt.pgParam)
|
t.Name(), tt.subtest, result, tt.result, tt.pgParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user