Do sync also when there are no deployment

This commit is contained in:
Dmitrii Dolgov 2020-02-17 14:28:38 +01:00
parent 4add317b48
commit 35d82e5a17
1 changed files with 27 additions and 9 deletions

View File

@ -110,11 +110,17 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
} }
} }
// connection pool // sync connection pool
if c.needConnectionPool() {
oldPool := oldSpec.Spec.ConnectionPool oldPool := oldSpec.Spec.ConnectionPool
newPool := newSpec.Spec.ConnectionPool newPool := newSpec.Spec.ConnectionPool
if c.needConnectionPool() &&
(c.ConnectionPool == nil || !reflect.DeepEqual(oldPool, newPool)) { // do sync in case if any resources were not remembered (it means they
// probably were not created, or if specification differs
if c.ConnectionPool == nil ||
c.ConnectionPool.Deployment == nil ||
c.ConnectionPool.Service == nil ||
!reflect.DeepEqual(oldPool, newPool) {
c.logger.Debug("syncing connection pool") c.logger.Debug("syncing connection pool")
@ -123,6 +129,18 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
return err return err
} }
} }
} else {
// check if we need to clean up connection pool resources after it was
// disabled
if c.ConnectionPool != nil &&
(c.ConnectionPool.Deployment != nil ||
c.ConnectionPool.Service != nil) {
if err := c.deleteConnectionPool(); err != nil {
c.logger.Warningf("could not remove connection pool: %v", err)
}
}
}
return err return err
} }