Sync in case of missing deployment

If nothing changed we still need to try to sync and test if the
deployment is there. Otherwise it could be deleted, and operator will
not notice.
This commit is contained in:
Dmitrii Dolgov 2020-03-04 16:07:22 +01:00
parent 4d12615c0d
commit e0df9dea0c
1 changed files with 6 additions and 24 deletions

View File

@ -2,7 +2,6 @@ package cluster
import ( import (
"fmt" "fmt"
"reflect"
batchv1beta1 "k8s.io/api/batch/v1beta1" batchv1beta1 "k8s.io/api/batch/v1beta1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
@ -608,29 +607,12 @@ func (c *Cluster) syncConnectionPool(oldSpec, newSpec *acidv1.Postgresql) error
newNeedConnPool := c.needConnectionPoolWorker(&newSpec.Spec) newNeedConnPool := c.needConnectionPoolWorker(&newSpec.Spec)
oldNeedConnPool := c.needConnectionPoolWorker(&oldSpec.Spec) oldNeedConnPool := c.needConnectionPoolWorker(&oldSpec.Spec)
if oldNeedConnPool && newNeedConnPool { if newNeedConnPool {
// sync in case of differences, or if no resources present // Try to sync in any case. If we didn't needed connection pool before,
oldPool := oldSpec.Spec.ConnectionPool // it means we want to create it. If it was already present, still sync
newPool := newSpec.Spec.ConnectionPool // since it could happen that there is no difference in specs, and all
// the resources are remembered, but the deployment was manualy deleted
if c.ConnectionPool == nil || // in between
c.ConnectionPool.Deployment == nil ||
c.ConnectionPool.Service == nil ||
!reflect.DeepEqual(oldPool, newPool) {
c.logger.Debug("syncing connection pool")
if err := c.syncConnectionPoolWorker(oldSpec, newSpec); err != nil {
c.logger.Errorf("could not sync connection pool: %v", err)
return err
}
} else {
c.logger.Debug("No connection pool sync")
}
}
if !oldNeedConnPool && newNeedConnPool {
// sync to create everything
c.logger.Debug("syncing connection pool") c.logger.Debug("syncing connection pool")
if err := c.syncConnectionPoolWorker(oldSpec, newSpec); err != nil { if err := c.syncConnectionPoolWorker(oldSpec, newSpec); err != nil {