fix unit test and delete secret when required only
This commit is contained in:
parent
041b9eec52
commit
2b44eff294
|
|
@ -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.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
|
// Repeat the same for the secret object
|
||||||
secretName := c.credentialSecretName(c.OpConfig.ConnectionPooler.User)
|
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)
|
return fmt.Errorf("could not delete pooler secret: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ConnectionPooler[role] = nil
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -692,13 +696,6 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, inst
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if newNeedConnectionPooler {
|
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,
|
// 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
|
// 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
|
// 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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func TestConnectionPoolerCreationAndDeletion(t *testing.T) {
|
||||||
EnableReplicaConnectionPooler: boolToPointer(true),
|
EnableReplicaConnectionPooler: boolToPointer(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
reason, err := cluster.createConnectionPooler(mockInstallLookupFunction)
|
reason, err := cluster.createConnectionPooler()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: Cannot create connection pooler, %s, %+v",
|
t.Errorf("%s: Cannot create connection pooler, %s, %+v",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue