Skip to content

Commit 53c8e10

Browse files
authored
Make superuser for dbo user configurable (#552)
1 parent 1e4f364 commit 53c8e10

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

api/v1/postgres_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func (p *Postgres) ToPeripheralResourceLookupKey() types.NamespacedName {
602602
}
603603
}
604604

605-
func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *corev1.ConfigMap, sc string, pgParamBlockList map[string]bool, rbs *BackupConfig, srcDB *Postgres, patroniTTL, patroniLoopWait, patroniRetryTimeout uint32) (*unstructured.Unstructured, error) {
605+
func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *corev1.ConfigMap, sc string, pgParamBlockList map[string]bool, rbs *BackupConfig, srcDB *Postgres, patroniTTL, patroniLoopWait, patroniRetryTimeout uint32, dboIsSuperuser bool) (*unstructured.Unstructured, error) {
606606
if z == nil {
607607
z = &zalando.Postgresql{}
608608
}
@@ -657,6 +657,9 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
657657
// Create database owner
658658
z.Spec.Users = make(map[string]zalando.UserFlags)
659659
z.Spec.Users[ownerName] = zalando.UserFlags{"createdb", "createrole"}
660+
if dboIsSuperuser {
661+
z.Spec.Users[ownerName] = zalando.UserFlags{"createdb", "createrole", "superuser"}
662+
}
660663
// Add auditor user
661664
z.Spec.Users["auditor"] = zalando.UserFlags{"nologin"}
662665

api/v1/postgres_types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func TestPostgresRestoreTimestamp_ToUnstructuredZalandoPostgresql(t *testing.T)
349349
p := &Postgres{
350350
Spec: tt.spec,
351351
}
352-
got, _ := p.ToUnstructuredZalandoPostgresql(nil, tt.c, tt.sc, tt.pgParamBlockList, tt.rbs, tt.srcDB, 130, 10, 60)
352+
got, _ := p.ToUnstructuredZalandoPostgresql(nil, tt.c, tt.sc, tt.pgParamBlockList, tt.rbs, tt.srcDB, 130, 10, 60, false)
353353

354354
jsonZ, err := runtime.DefaultUnstructuredConverter.ToUnstructured(got)
355355
if err != nil {

controllers/postgres_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type PostgresReconciler struct {
8686
EnableWalGEncryption bool
8787
PostgresletFullname string
8888
EnableBootstrapStandbyFromS3 bool
89+
EnableSuperUserForDBO bool
8990
}
9091

9192
// Reconcile is the entry point for postgres reconciliation.
@@ -357,7 +358,7 @@ func (r *PostgresReconciler) createOrUpdateZalandoPostgresql(ctx context.Context
357358
return fmt.Errorf("failed to fetch zalando postgresql: %w", err)
358359
}
359360

360-
u, err := instance.ToUnstructuredZalandoPostgresql(nil, sidecarsCM, r.StorageClass, r.PgParamBlockList, restoreBackupConfig, restoreSouceInstance, patroniTTL, patroniLoopWait, patroniRetryTimout)
361+
u, err := instance.ToUnstructuredZalandoPostgresql(nil, sidecarsCM, r.StorageClass, r.PgParamBlockList, restoreBackupConfig, restoreSouceInstance, patroniTTL, patroniLoopWait, patroniRetryTimout, r.EnableSuperUserForDBO)
361362
if err != nil {
362363
return fmt.Errorf("failed to convert to unstructured zalando postgresql: %w", err)
363364
}
@@ -373,7 +374,7 @@ func (r *PostgresReconciler) createOrUpdateZalandoPostgresql(ctx context.Context
373374
// Update zalando postgresql
374375
mergeFrom := client.MergeFrom(rawZ.DeepCopy())
375376

376-
u, err := instance.ToUnstructuredZalandoPostgresql(rawZ, sidecarsCM, r.StorageClass, r.PgParamBlockList, restoreBackupConfig, restoreSouceInstance, patroniTTL, patroniLoopWait, patroniRetryTimout)
377+
u, err := instance.ToUnstructuredZalandoPostgresql(rawZ, sidecarsCM, r.StorageClass, r.PgParamBlockList, restoreBackupConfig, restoreSouceInstance, patroniTTL, patroniLoopWait, patroniRetryTimout, r.EnableSuperUserForDBO)
377378
if err != nil {
378379
return fmt.Errorf("failed to convert to unstructured zalando postgresql: %w", err)
379380
}

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const (
7373
enableWalGEncryptionFlg = "enable-walg-encryption"
7474
enableForceSharedIPFlg = "enable-force-shared-ip"
7575
enableBootstrapStandbyFromS3Flg = "enable-bootsrtap-standby-from-s3"
76+
enableSuperUserForDBOFlg = "enable-superuser-for-dbo"
7677
)
7778

7879
var (
@@ -126,6 +127,7 @@ func main() {
126127
enableWalGEncryption bool
127128
enableForceSharedIP bool
128129
enableBootstrapStandbyFromS3 bool
130+
enableSuperUserForDBO bool
129131

130132
portRangeStart int
131133
portRangeSize int
@@ -265,6 +267,9 @@ func main() {
265267
viper.SetDefault(enableBootstrapStandbyFromS3Flg, true)
266268
enableBootstrapStandbyFromS3 = viper.GetBool(enableBootstrapStandbyFromS3Flg)
267269

270+
viper.SetDefault(enableSuperUserForDBOFlg, false)
271+
enableSuperUserForDBO = viper.GetBool(enableSuperUserForDBOFlg)
272+
268273
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
269274

270275
ctrl.Log.Info("flag",
@@ -305,6 +310,7 @@ func main() {
305310
enableWalGEncryptionFlg, enableWalGEncryption,
306311
enableForceSharedIPFlg, enableForceSharedIP,
307312
enableBootstrapStandbyFromS3Flg, enableBootstrapStandbyFromS3,
313+
enableSuperUserForDBOFlg, enableSuperUserForDBO,
308314
)
309315

310316
svcClusterConf := ctrl.GetConfigOrDie()
@@ -413,6 +419,7 @@ func main() {
413419
EnableWalGEncryption: enableWalGEncryption,
414420
PostgresletFullname: postgresletFullname,
415421
EnableBootstrapStandbyFromS3: enableBootstrapStandbyFromS3,
422+
EnableSuperUserForDBO: enableSuperUserForDBO,
416423
}).SetupWithManager(ctrlPlaneClusterMgr); err != nil {
417424
setupLog.Error(err, "unable to create controller", "controller", "Postgres")
418425
os.Exit(1)

0 commit comments

Comments
 (0)