Address review, add ConnectionPool init for sync

This commit is contained in:
Dmitrii Dolgov 2020-02-17 13:07:40 +01:00
parent a9d02bacc4
commit 515bb2dfad
6 changed files with 35 additions and 14 deletions

View File

@ -152,7 +152,7 @@ These parameters are grouped directly under the `spec` key in the manifest.
* enableConnectionPool
Tells the operator to create a connection pool with a database. If this
field is true, a connection pool deployment will be created even if
`connectionPool` section is empty.
`connectionPool` section is empty. Optional, not set by default.
## Postgres parameters
@ -376,7 +376,7 @@ present.
How many instances of connection pool to create.
* **mode**
In which mode to run connection pool, transaction or section.
In which mode to run connection pool, transaction or session.
* **schema**
Schema to create for credentials lookup function.

View File

@ -613,7 +613,7 @@ operator being able to provide some reasonable defaults.
Docker image to use for connection pool deployment.
* **connection_pool_mode**
Default pool mode, sesssion or transaction.
Default pool mode, session or transaction.
* **connection_pool_default_cpu_request**
**connection_pool_default_memory_reques**

View File

@ -468,7 +468,7 @@ spec:
```
This will tell the operator to create a connection pool with default
configuration, though which one can access the master via a separate service
configuration, through which one can access the master via a separate service
`{cluster-name}-pooler`. In most of the cases provided default configuration
should be good enough.

View File

@ -1217,16 +1217,16 @@ func (c *Cluster) needSyncConnPoolDeployments(oldSpec, newSpec *acidv1.Connectio
if err != nil {
c.logger.Infof("Cannot get diff, do not do anything, %+v", err)
return false, reasons
} else {
if len(changelog) > 0 {
sync = true
}
}
for _, change := range changelog {
msg := fmt.Sprintf("%s %+v from %s to %s",
change.Type, change.Path, change.From, change.To)
reasons = append(reasons, msg)
}
if len(changelog) > 0 {
sync = true
}
for _, change := range changelog {
msg := fmt.Sprintf("%s %+v from %s to %s",
change.Type, change.Path, change.From, change.To)
reasons = append(reasons, msg)
}
return sync, reasons

View File

@ -1860,6 +1860,16 @@ func (c *Cluster) ownerReferences() []metav1.OwnerReference {
func (c *Cluster) generateConnPoolDeployment(spec *acidv1.PostgresSpec) (
*appsv1.Deployment, error) {
// there are two ways to enable connection pooler, either to specify a
// connectionPool section or enableConnectionPool. In the second case
// spec.connectionPool will be nil, so to make it easier to calculate
// default values, initialize it to an empty structure. It could be done
// anywhere, but here is the earliest common entry point between sync and
// create code, so init here.
if spec.ConnectionPool == nil {
spec.ConnectionPool = &acidv1.ConnectionPool{}
}
podTemplate, err := c.generateConnPoolPodTemplate(spec)
numberOfInstances := spec.ConnectionPool.NumberOfInstances
if numberOfInstances == nil {
@ -1895,6 +1905,17 @@ func (c *Cluster) generateConnPoolDeployment(spec *acidv1.PostgresSpec) (
}
func (c *Cluster) generateConnPoolService(spec *acidv1.PostgresSpec) *v1.Service {
// there are two ways to enable connection pooler, either to specify a
// connectionPool section or enableConnectionPool. In the second case
// spec.connectionPool will be nil, so to make it easier to calculate
// default values, initialize it to an empty structure. It could be done
// anywhere, but here is the earliest common entry point between sync and
// create code, so init here.
if spec.ConnectionPool == nil {
spec.ConnectionPool = &acidv1.ConnectionPool{}
}
serviceSpec := v1.ServiceSpec{
Ports: []v1.ServicePort{
{

View File

@ -864,7 +864,7 @@ func (c *Cluster) updateConnPoolDeployment(oldDeploymentSpec, newDeployment *app
}
// An update probably requires RetryOnConflict, but since only one operator
// worker at one time will try to update it changes of conflicts are
// worker at one time will try to update it chances of conflicts are
// minimal.
deployment, err := c.KubeClient.
Deployments(c.ConnectionPool.Deployment.Namespace).