diff --git a/pkg/cluster/connection_pooler.go b/pkg/cluster/connection_pooler.go index 627479038..bebe00d28 100644 --- a/pkg/cluster/connection_pooler.go +++ b/pkg/cluster/connection_pooler.go @@ -461,6 +461,12 @@ func (c *Cluster) deleteConnectionPooler(role PostgresRole) (err error) { c.logger.Infof("Connection pooler service %q has been deleted for role %s", service.Name, role) } + c.ConnectionPooler[role] = nil + return nil +} + +//delete connection pooler +func (c *Cluster) deleteConnectionPoolerSecret() (err error) { // Repeat the same for the secret object secretName := c.credentialSecretName(c.OpConfig.ConnectionPooler.User) @@ -475,8 +481,6 @@ func (c *Cluster) deleteConnectionPooler(role PostgresRole) (err error) { return fmt.Errorf("could not delete pooler secret: %v", err) } } - - c.ConnectionPooler[role] = nil return nil } @@ -692,13 +696,6 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, inst } } if newNeedConnectionPooler { - //Sync pooler secrets in case they were deleted - c.logger.Debugf("syncing secrets") - - if err := c.syncSecrets(); err != nil { - c.logger.Errorf("could not sync secrets: %v", err) - } - // Try to sync in any case. If we didn't needed connection pooler before, // it means we want to create it. If it was already present, still sync // since it could happen that there is no difference in specs, and all @@ -745,6 +742,12 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, inst c.logger.Warningf("could not remove connection pooler: %v", err) } } + if (role == Master && !needReplicaConnectionPoolerWorker(&newSpec.Spec)) || + (role == Replica && !needMasterConnectionPoolerWorker(&newSpec.Spec)) { + if err = c.deleteConnectionPoolerSecret(); err != nil { + c.logger.Warningf("could not remove connection pooler secret: %v", err) + } + } } } diff --git a/pkg/cluster/connection_pooler_test.go b/pkg/cluster/connection_pooler_test.go index 4f3f27176..b5c6b225b 100644 --- a/pkg/cluster/connection_pooler_test.go +++ b/pkg/cluster/connection_pooler_test.go @@ -58,7 +58,7 @@ func TestConnectionPoolerCreationAndDeletion(t *testing.T) { EnableReplicaConnectionPooler: boolToPointer(true), } - reason, err := cluster.createConnectionPooler(mockInstallLookupFunction) + reason, err := cluster.createConnectionPooler() if err != nil { t.Errorf("%s: Cannot create connection pooler, %s, %+v",