Bugfix/close db connections (#78)

Open and close DB connections on-demand.

Previously, we used to leave the DB connection open while the
cluster was registered with the operator, potentially resutling
in dangled connections if the operator terminates abnormally.

Small refactoring around the role syncing code.
This commit is contained in:
Oleksii Kliukin
2017-08-10 10:10:00 +02:00
committed by GitHub
parent 8b58782a4a
commit f15f93f479
4 changed files with 45 additions and 38 deletions
+3 -6
View File
@@ -143,6 +143,7 @@ func (c *Cluster) setStatus(status spec.PostgresStatus) {
}
}
// initUsers populates c.systemUsers and c.pgUsers maps.
func (c *Cluster) initUsers() error {
c.initSystemUsers()
@@ -204,7 +205,7 @@ func (c *Cluster) Create() error {
if err = c.initUsers(); err != nil {
return err
}
c.logger.Infof("User secrets have been initialized")
c.logger.Infof("Users have been initialized")
if err = c.applySecrets(); err != nil {
return fmt.Errorf("could not create secrets: %v", err)
@@ -226,11 +227,7 @@ func (c *Cluster) Create() error {
c.logger.Infof("pods are ready")
if !(c.masterLess || c.databaseAccessDisabled()) {
err = c.initDbConn()
if err != nil {
return fmt.Errorf("could not init db connection: %v", err)
}
err = c.createUsers()
err = c.createRoles()
if err != nil {
return fmt.Errorf("could not create users: %v", err)
}