mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-06 02:13:23 +02:00
Address review
This commit is contained in:
@@ -49,7 +49,7 @@ type Config struct {
|
||||
PodServiceAccountRoleBinding *rbacv1beta1.RoleBinding
|
||||
}
|
||||
|
||||
type ConnectionPoolResources struct {
|
||||
type ConnectionPoolObjects struct {
|
||||
Deployment *appsv1.Deployment
|
||||
Service *v1.Service
|
||||
}
|
||||
@@ -59,7 +59,7 @@ type kubeResources struct {
|
||||
Endpoints map[PostgresRole]*v1.Endpoints
|
||||
Secrets map[types.UID]*v1.Secret
|
||||
Statefulset *appsv1.StatefulSet
|
||||
ConnectionPool *ConnectionPoolResources
|
||||
ConnectionPool *ConnectionPoolObjects
|
||||
PodDisruptionBudget *policybeta1.PodDisruptionBudget
|
||||
//Pods are treated separately
|
||||
//PVCs are treated separately
|
||||
|
||||
@@ -541,8 +541,8 @@ func TestConnPoolPodSpec(t *testing.T) {
|
||||
ConnectionPool: config.ConnectionPool{
|
||||
ConnPoolDefaultCPURequest: "100m",
|
||||
ConnPoolDefaultCPULimit: "100m",
|
||||
ConnPoolDefaultMemoryRequest: "100M",
|
||||
ConnPoolDefaultMemoryLimit: "100M",
|
||||
ConnPoolDefaultMemoryRequest: "100Mi",
|
||||
ConnPoolDefaultMemoryLimit: "100Mi",
|
||||
},
|
||||
},
|
||||
}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger)
|
||||
@@ -666,8 +666,8 @@ func TestConnPoolDeploymentSpec(t *testing.T) {
|
||||
ConnectionPool: config.ConnectionPool{
|
||||
ConnPoolDefaultCPURequest: "100m",
|
||||
ConnPoolDefaultCPULimit: "100m",
|
||||
ConnPoolDefaultMemoryRequest: "100M",
|
||||
ConnPoolDefaultMemoryLimit: "100M",
|
||||
ConnPoolDefaultMemoryRequest: "100Mi",
|
||||
ConnPoolDefaultMemoryLimit: "100Mi",
|
||||
},
|
||||
},
|
||||
}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger)
|
||||
@@ -767,8 +767,8 @@ func TestConnPoolServiceSpec(t *testing.T) {
|
||||
ConnectionPool: config.ConnectionPool{
|
||||
ConnPoolDefaultCPURequest: "100m",
|
||||
ConnPoolDefaultCPULimit: "100m",
|
||||
ConnPoolDefaultMemoryRequest: "100M",
|
||||
ConnPoolDefaultMemoryLimit: "100M",
|
||||
ConnPoolDefaultMemoryRequest: "100Mi",
|
||||
ConnPoolDefaultMemoryLimit: "100Mi",
|
||||
},
|
||||
},
|
||||
}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger)
|
||||
|
||||
@@ -97,7 +97,7 @@ func (c *Cluster) createStatefulSet() (*appsv1.StatefulSet, error) {
|
||||
//
|
||||
// After that create all the objects for connection pool, namely a deployment
|
||||
// with a chosen pooler and a service to expose it.
|
||||
func (c *Cluster) createConnectionPool(lookup InstallFunction) (*ConnectionPoolResources, error) {
|
||||
func (c *Cluster) createConnectionPool(lookup InstallFunction) (*ConnectionPoolObjects, error) {
|
||||
var msg string
|
||||
c.setProcessName("creating connection pool")
|
||||
|
||||
@@ -144,7 +144,7 @@ func (c *Cluster) createConnectionPool(lookup InstallFunction) (*ConnectionPoolR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.ConnectionPool = &ConnectionPoolResources{
|
||||
c.ConnectionPool = &ConnectionPoolObjects{
|
||||
Deployment: deployment,
|
||||
Service: service,
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ func mockInstallLookupFunction(schema string, user string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func boolToPointer(value bool) *bool {
|
||||
return &value
|
||||
}
|
||||
|
||||
func TestConnPoolCreationAndDeletion(t *testing.T) {
|
||||
testName := "Test connection pool creation"
|
||||
var cluster = New(
|
||||
@@ -28,8 +32,8 @@ func TestConnPoolCreationAndDeletion(t *testing.T) {
|
||||
ConnectionPool: config.ConnectionPool{
|
||||
ConnPoolDefaultCPURequest: "100m",
|
||||
ConnPoolDefaultCPULimit: "100m",
|
||||
ConnPoolDefaultMemoryRequest: "100M",
|
||||
ConnPoolDefaultMemoryLimit: "100M",
|
||||
ConnPoolDefaultMemoryRequest: "100Mi",
|
||||
ConnPoolDefaultMemoryLimit: "100Mi",
|
||||
},
|
||||
},
|
||||
}, k8sutil.NewMockKubernetesClient(), acidv1.Postgresql{}, logger)
|
||||
@@ -77,8 +81,8 @@ func TestNeedConnPool(t *testing.T) {
|
||||
ConnectionPool: config.ConnectionPool{
|
||||
ConnPoolDefaultCPURequest: "100m",
|
||||
ConnPoolDefaultCPULimit: "100m",
|
||||
ConnPoolDefaultMemoryRequest: "100M",
|
||||
ConnPoolDefaultMemoryLimit: "100M",
|
||||
ConnPoolDefaultMemoryRequest: "100Mi",
|
||||
ConnPoolDefaultMemoryLimit: "100Mi",
|
||||
},
|
||||
},
|
||||
}, k8sutil.NewMockKubernetesClient(), acidv1.Postgresql{}, logger)
|
||||
@@ -93,7 +97,7 @@ func TestNeedConnPool(t *testing.T) {
|
||||
}
|
||||
|
||||
cluster.Spec = acidv1.PostgresSpec{
|
||||
EnableConnectionPool: true,
|
||||
EnableConnectionPool: boolToPointer(true),
|
||||
}
|
||||
|
||||
if !cluster.needConnectionPool() {
|
||||
|
||||
+1
-1
@@ -618,7 +618,7 @@ func (c *Cluster) syncLogicalBackupJob() error {
|
||||
func (c *Cluster) syncConnectionPool(oldSpec, newSpec *acidv1.Postgresql) error {
|
||||
if c.ConnectionPool == nil {
|
||||
c.logger.Warning("Connection pool resources are empty")
|
||||
c.ConnectionPool = &ConnectionPoolResources{}
|
||||
c.ConnectionPool = &ConnectionPoolObjects{}
|
||||
}
|
||||
|
||||
deployment, err := c.KubeClient.
|
||||
|
||||
@@ -54,8 +54,8 @@ func TestConnPoolSynchronization(t *testing.T) {
|
||||
ConnectionPool: config.ConnectionPool{
|
||||
ConnPoolDefaultCPURequest: "100m",
|
||||
ConnPoolDefaultCPULimit: "100m",
|
||||
ConnPoolDefaultMemoryRequest: "100M",
|
||||
ConnPoolDefaultMemoryLimit: "100M",
|
||||
ConnPoolDefaultMemoryRequest: "100Mi",
|
||||
ConnPoolDefaultMemoryLimit: "100Mi",
|
||||
},
|
||||
},
|
||||
}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger)
|
||||
|
||||
+5
-1
@@ -497,5 +497,9 @@ func (c *Cluster) patroniUsesKubernetes() bool {
|
||||
}
|
||||
|
||||
func (c *Cluster) needConnectionPool() bool {
|
||||
return c.Spec.ConnectionPool != nil || c.Spec.EnableConnectionPool == true
|
||||
if c.Spec.EnableConnectionPool == nil {
|
||||
return c.Spec.ConnectionPool != nil
|
||||
} else {
|
||||
return *c.Spec.EnableConnectionPool
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user