Minor improvements

* Set minimum number of pool instances to 2
* Improve logging of sync reasons
* Improve logging of a new pool role
This commit is contained in:
Dmitrii Dolgov 2020-03-19 10:31:58 +01:00
parent 1c7065e4ce
commit 48cdbb6a65
6 changed files with 24 additions and 11 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)

View File

@ -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))
}

View File

@ -14,4 +14,5 @@ const (
ConnPoolContainer = 0
ConnPoolMaxDBConnections = 60
ConnPoolMaxClientConnections = 10000
ConnPoolMinInstances = 2
)

View File

@ -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
}