diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 94ca8e864..50cf5392d 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -1240,7 +1240,7 @@ func (c *Cluster) needSyncConnPoolSpecs(oldSpec, newSpec *acidv1.ConnectionPool) } for _, change := range changelog { - msg := fmt.Sprintf("%s %+v from %s to %s", + msg := fmt.Sprintf("%s %+v from '%+v' to '%+v'", change.Type, change.Path, change.From, change.To) reasons = append(reasons, msg) } diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 465c39ff6..1235a7e30 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -2053,6 +2053,13 @@ func (c *Cluster) generateConnPoolDeployment(spec *acidv1.PostgresSpec) ( k8sutil.Int32ToPointer(1)) } + if *numberOfInstances < constants.ConnPoolMinInstances { + msg := "Adjusted number of connection pool instances from %d to %d" + c.logger.Warningf(msg, numberOfInstances, constants.ConnPoolMinInstances) + + *numberOfInstances = constants.ConnPoolMinInstances + } + if err != nil { return nil, err } diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index 931e9e5c8..4e101dd9d 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -727,7 +727,7 @@ func (c *Cluster) syncConnectionPoolWorker(oldSpec, newSpec *acidv1.Postgresql) defaultsSync, defaultsReason := c.needSyncConnPoolDefaults(newConnPool, deployment) reason := append(specReason, defaultsReason...) if specSync || defaultsSync { - c.logger.Infof("Update connection pool deployment %s, reason: %s", + c.logger.Infof("Update connection pool deployment %s, reason: %+v", c.connPoolName(), reason) newDeploymentSpec, err := c.generateConnPoolDeployment(&newSpec.Spec) diff --git a/pkg/spec/types.go b/pkg/spec/types.go index 6f071c44a..36783204d 100644 --- a/pkg/spec/types.go +++ b/pkg/spec/types.go @@ -180,6 +180,8 @@ func (r RoleOrigin) String() string { return "teams API role" case RoleOriginSystem: return "system role" + case RoleConnectionPool: + return "connection pool role" default: panic(fmt.Sprintf("bogus role origin value %d", r)) } diff --git a/pkg/util/constants/pooler.go b/pkg/util/constants/pooler.go index 0426dbfe8..346299a1c 100644 --- a/pkg/util/constants/pooler.go +++ b/pkg/util/constants/pooler.go @@ -14,4 +14,5 @@ const ( ConnPoolContainer = 0 ConnPoolMaxDBConnections = 60 ConnPoolMaxClientConnections = 10000 + ConnPoolMinInstances = 2 ) diff --git a/pkg/util/util.go b/pkg/util/util.go index c78852726..8e3b7cd21 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -149,22 +149,25 @@ func CoalesceInt32(val, defaultVal *int32) *int32 { return val } +// Test if any of the values is nil +func testNil(values ...*int32) bool { + for _, v := range values { + if v == nil { + return true + } + } + + return false +} + // Return maximum of two integers provided via pointers. If one value is not // defined, return the other one. If both are not defined, result is also // undefined, caller needs to check for that. func MaxInt32(a, b *int32) *int32 { - if a == nil && b == nil { + if testNil(a, b) { return nil } - if a == nil { - return b - } - - if b == nil { - return a - } - if *a > *b { return a }