From 1ee79887cf2fbbc9ce0778e3abaa8747a9daf0f5 Mon Sep 17 00:00:00 2001 From: Rafia Sabih Date: Wed, 23 Sep 2020 11:19:01 +0200 Subject: [PATCH] Add sync test --- pkg/cluster/cluster.go | 2 +- pkg/cluster/sync_test.go | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index db0697b5d..95b4f1404 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -905,7 +905,7 @@ func (c *Cluster) initSystemUsers() { // Connection pooler user is an exception, if requested it's going to be // created by operator as a normal pgUser - if c.needMasterConnectionPooler() || c.needReplicaConnectionPooler() { + if c.needConnectionPooler() { // initialize empty connection pooler if not done yet if c.Spec.ConnectionPooler == nil { c.Spec.ConnectionPooler = &acidv1.ConnectionPooler{} diff --git a/pkg/cluster/sync_test.go b/pkg/cluster/sync_test.go index 64aa03678..fa93cf45a 100644 --- a/pkg/cluster/sync_test.go +++ b/pkg/cluster/sync_test.go @@ -215,6 +215,23 @@ func TestConnectionPoolerSynchronization(t *testing.T) { defaultInstances: 1, check: objectsAreSaved, }, + { + subTest: "create both master and replica", + oldSpec: &acidv1.Postgresql{ + Spec: acidv1.PostgresSpec{}, + }, + newSpec: &acidv1.Postgresql{ + Spec: acidv1.PostgresSpec{ + ConnectionPooler: &acidv1.ConnectionPooler{}, + EnableReplicaConnectionPooler: boolToPointer(true), + EnableConnectionPooler: boolToPointer(true), + }, + }, + cluster: clusterMissingObjects, + defaultImage: "pooler:1.0", + defaultInstances: 1, + check: objectsAreSaved, + }, { subTest: "delete if not needed", oldSpec: &acidv1.Postgresql{ @@ -234,7 +251,8 @@ func TestConnectionPoolerSynchronization(t *testing.T) { subTest: "delete only master if not needed", oldSpec: &acidv1.Postgresql{ Spec: acidv1.PostgresSpec{ - ConnectionPooler: &acidv1.ConnectionPooler{}, + ConnectionPooler: &acidv1.ConnectionPooler{}, + EnableConnectionPooler: boolToPointer(true), }, }, newSpec: &acidv1.Postgresql{