mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-06 09:52:37 +02:00
make pooler labels configurable and change defaults
This commit is contained in:
@@ -898,6 +898,17 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
|
||||
"connection_pooler_image": {
|
||||
Type: "string",
|
||||
},
|
||||
"connection_pooler_labels": {
|
||||
Type: "object",
|
||||
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
|
||||
Schema: &apiextv1.JSONSchemaProps{
|
||||
Type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
"connection_pooler_role_label": {
|
||||
Type: "string",
|
||||
},
|
||||
"connection_pooler_max_db_connections": {
|
||||
Type: "integer",
|
||||
},
|
||||
|
||||
@@ -209,16 +209,18 @@ type ScalyrConfiguration struct {
|
||||
|
||||
// ConnectionPoolerConfiguration defines default configuration for connection pooler
|
||||
type ConnectionPoolerConfiguration struct {
|
||||
NumberOfInstances *int32 `json:"connection_pooler_number_of_instances,omitempty"`
|
||||
Schema string `json:"connection_pooler_schema,omitempty"`
|
||||
User string `json:"connection_pooler_user,omitempty"`
|
||||
Image string `json:"connection_pooler_image,omitempty"`
|
||||
Mode string `json:"connection_pooler_mode,omitempty"`
|
||||
MaxDBConnections *int32 `json:"connection_pooler_max_db_connections,omitempty"`
|
||||
DefaultCPURequest string `json:"connection_pooler_default_cpu_request,omitempty"`
|
||||
DefaultMemoryRequest string `json:"connection_pooler_default_memory_request,omitempty"`
|
||||
DefaultCPULimit string `json:"connection_pooler_default_cpu_limit,omitempty"`
|
||||
DefaultMemoryLimit string `json:"connection_pooler_default_memory_limit,omitempty"`
|
||||
NumberOfInstances *int32 `json:"connection_pooler_number_of_instances,omitempty"`
|
||||
Schema string `json:"connection_pooler_schema,omitempty"`
|
||||
User string `json:"connection_pooler_user,omitempty"`
|
||||
Image string `json:"connection_pooler_image,omitempty"`
|
||||
Mode string `json:"connection_pooler_mode,omitempty"`
|
||||
MaxDBConnections *int32 `json:"connection_pooler_max_db_connections,omitempty"`
|
||||
Labels map[string]string `json:"connection_pooler_labels,omitempty"`
|
||||
RoleLabel string `json:"connection_pooler_role_label,omitempty"`
|
||||
DefaultCPURequest string `json:"connection_pooler_default_cpu_request,omitempty"`
|
||||
DefaultMemoryRequest string `json:"connection_pooler_default_memory_request,omitempty"`
|
||||
DefaultCPULimit string `json:"connection_pooler_default_cpu_limit,omitempty"`
|
||||
DefaultMemoryLimit string `json:"connection_pooler_default_memory_limit,omitempty"`
|
||||
}
|
||||
|
||||
// OperatorLogicalBackupConfiguration defines configuration for logical backup
|
||||
|
||||
@@ -1782,6 +1782,8 @@ func TestCrossNamespacedSecrets(t *testing.T) {
|
||||
Config{
|
||||
OpConfig: config.Config{
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
|
||||
@@ -115,8 +115,9 @@ func (c *Cluster) poolerUser(spec *acidv1.PostgresSpec) string {
|
||||
func (c *Cluster) poolerLabelsSet(addExtraLabels bool) labels.Set {
|
||||
poolerLabels := c.labelsSet(addExtraLabels)
|
||||
|
||||
// TODO should be config values
|
||||
poolerLabels["application"] = "db-connection-pooler"
|
||||
for k, v := range c.OpConfig.ConnectionPooler.Labels {
|
||||
poolerLabels[k] = v
|
||||
}
|
||||
|
||||
return poolerLabels
|
||||
}
|
||||
@@ -134,7 +135,7 @@ func (c *Cluster) connectionPoolerLabels(role PostgresRole, addExtraLabels bool)
|
||||
|
||||
if addExtraLabels {
|
||||
extraLabels := map[string]string{}
|
||||
extraLabels[c.OpConfig.PodRoleLabel] = string(role)
|
||||
extraLabels[c.OpConfig.ConnectionPooler.RoleLabel] = string(role)
|
||||
|
||||
poolerLabelsSet = labels.Merge(poolerLabelsSet, extraLabels)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func deploymentUpdated(cluster *Cluster, err error, reason SyncReason) error {
|
||||
for _, role := range [2]PostgresRole{Master, Replica} {
|
||||
|
||||
poolerLabels := cluster.labelsSet(false)
|
||||
poolerLabels["application"] = "db-connection-pooler"
|
||||
poolerLabels["component"] = "db-connection-pooler"
|
||||
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)
|
||||
|
||||
if cluster.ConnectionPooler[role] != nil && cluster.ConnectionPooler[role].Deployment != nil &&
|
||||
@@ -65,7 +65,7 @@ func objectsAreSaved(cluster *Cluster, err error, reason SyncReason) error {
|
||||
|
||||
for _, role := range []PostgresRole{Master, Replica} {
|
||||
poolerLabels := cluster.labelsSet(false)
|
||||
poolerLabels["application"] = "db-connection-pooler"
|
||||
poolerLabels["component"] = "db-connection-pooler"
|
||||
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)
|
||||
|
||||
if cluster.ConnectionPooler[role].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[role].Deployment.Labels, poolerLabels) {
|
||||
@@ -86,7 +86,7 @@ func MasterObjectsAreSaved(cluster *Cluster, err error, reason SyncReason) error
|
||||
}
|
||||
|
||||
poolerLabels := cluster.labelsSet(false)
|
||||
poolerLabels["application"] = "db-connection-pooler"
|
||||
poolerLabels["component"] = "db-connection-pooler"
|
||||
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(Master)
|
||||
|
||||
if cluster.ConnectionPooler[Master].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[Master].Deployment.Labels, poolerLabels) {
|
||||
@@ -106,7 +106,7 @@ func ReplicaObjectsAreSaved(cluster *Cluster, err error, reason SyncReason) erro
|
||||
}
|
||||
|
||||
poolerLabels := cluster.labelsSet(false)
|
||||
poolerLabels["application"] = "db-connection-pooler"
|
||||
poolerLabels["component"] = "db-connection-pooler"
|
||||
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(Replica)
|
||||
|
||||
if cluster.ConnectionPooler[Replica].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[Replica].Deployment.Labels, poolerLabels) {
|
||||
@@ -170,6 +170,8 @@ func TestNeedConnectionPooler(t *testing.T) {
|
||||
ReplicationUsername: replicationUserName,
|
||||
},
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -301,6 +303,8 @@ func TestConnectionPoolerCreateDeletion(t *testing.T) {
|
||||
Config{
|
||||
OpConfig: config.Config{
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -336,7 +340,7 @@ func TestConnectionPoolerCreateDeletion(t *testing.T) {
|
||||
}
|
||||
for _, role := range [2]PostgresRole{Master, Replica} {
|
||||
poolerLabels := cluster.labelsSet(false)
|
||||
poolerLabels["application"] = "db-connection-pooler"
|
||||
poolerLabels["component"] = "db-connection-pooler"
|
||||
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)
|
||||
|
||||
if cluster.ConnectionPooler[role] != nil {
|
||||
@@ -409,6 +413,8 @@ func TestConnectionPoolerSync(t *testing.T) {
|
||||
Config{
|
||||
OpConfig: config.Config{
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -678,6 +684,8 @@ func TestConnectionPoolerPodSpec(t *testing.T) {
|
||||
PodServiceAccountName: "postgres-pod",
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
MaxDBConnections: k8sutil.Int32ToPointer(60),
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -789,6 +797,8 @@ func TestConnectionPoolerDeploymentSpec(t *testing.T) {
|
||||
ReplicationUsername: replicationUserName,
|
||||
},
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -1003,6 +1013,8 @@ func TestPoolerTLS(t *testing.T) {
|
||||
SpiloFSGroup: &spiloFSGroup,
|
||||
},
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -1072,6 +1084,8 @@ func TestConnectionPoolerServiceSpec(t *testing.T) {
|
||||
ReplicationUsername: replicationUserName,
|
||||
},
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
|
||||
@@ -3022,6 +3022,8 @@ func TestEnableLoadBalancers(t *testing.T) {
|
||||
subTest: "LBs enabled in config, disabled in manifest",
|
||||
config: config.Config{
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
@@ -3069,6 +3071,8 @@ func TestEnableLoadBalancers(t *testing.T) {
|
||||
subTest: "LBs enabled in manifest, disabled in config",
|
||||
config: config.Config{
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
|
||||
@@ -192,6 +192,8 @@ func TestPodAnnotationsSync(t *testing.T) {
|
||||
PodManagementPolicy: "ordered_ready",
|
||||
CustomPodAnnotations: customPodAnnotations,
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
|
||||
@@ -301,6 +301,8 @@ func newInheritedAnnotationsCluster(client k8sutil.KubernetesClient) (*Cluster,
|
||||
PatroniAPICheckTimeout: time.Duration(5),
|
||||
KubernetesUseConfigMaps: true,
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
Labels: map[string]string{"component": "db-connection-pooler"},
|
||||
RoleLabel: "pooler-role",
|
||||
ConnectionPoolerDefaultCPURequest: "100m",
|
||||
ConnectionPoolerDefaultCPULimit: "100m",
|
||||
ConnectionPoolerDefaultMemoryRequest: "100Mi",
|
||||
|
||||
@@ -280,6 +280,8 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
|
||||
fromCRD.ConnectionPooler.Mode,
|
||||
constants.ConnectionPoolerDefaultMode)
|
||||
|
||||
result.ConnectionPooler.Labels = util.CoalesceStrMap(fromCRD.ConnectionPooler.Labels, map[string]string{"application": "spilo"})
|
||||
result.ConnectionPooler.RoleLabel = util.Coalesce(fromCRD.ConnectionPooler.RoleLabel, "pooler-role")
|
||||
result.ConnectionPooler.ConnectionPoolerDefaultCPURequest = fromCRD.ConnectionPooler.DefaultCPURequest
|
||||
result.ConnectionPooler.ConnectionPoolerDefaultMemoryRequest = fromCRD.ConnectionPooler.DefaultMemoryRequest
|
||||
result.ConnectionPooler.ConnectionPoolerDefaultCPULimit = fromCRD.ConnectionPooler.DefaultCPULimit
|
||||
|
||||
+17
-10
@@ -152,16 +152,18 @@ type LogicalBackup struct {
|
||||
|
||||
// Operator options for connection pooler
|
||||
type ConnectionPooler struct {
|
||||
NumberOfInstances *int32 `name:"connection_pooler_number_of_instances" default:"2"`
|
||||
Schema string `name:"connection_pooler_schema" default:"pooler"`
|
||||
User string `name:"connection_pooler_user" default:"pooler"`
|
||||
Image string `name:"connection_pooler_image" default:"registry.opensource.zalan.do/acid/pgbouncer"`
|
||||
Mode string `name:"connection_pooler_mode" default:"transaction"`
|
||||
MaxDBConnections *int32 `name:"connection_pooler_max_db_connections" default:"60"`
|
||||
ConnectionPoolerDefaultCPURequest string `name:"connection_pooler_default_cpu_request"`
|
||||
ConnectionPoolerDefaultMemoryRequest string `name:"connection_pooler_default_memory_request"`
|
||||
ConnectionPoolerDefaultCPULimit string `name:"connection_pooler_default_cpu_limit"`
|
||||
ConnectionPoolerDefaultMemoryLimit string `name:"connection_pooler_default_memory_limit"`
|
||||
NumberOfInstances *int32 `name:"connection_pooler_number_of_instances" default:"2"`
|
||||
Schema string `name:"connection_pooler_schema" default:"pooler"`
|
||||
User string `name:"connection_pooler_user" default:"pooler"`
|
||||
Image string `name:"connection_pooler_image" default:"registry.opensource.zalan.do/acid/pgbouncer"`
|
||||
Mode string `name:"connection_pooler_mode" default:"transaction"`
|
||||
MaxDBConnections *int32 `name:"connection_pooler_max_db_connections" default:"60"`
|
||||
Labels map[string]string `name:"connection_pooler_labels,omitempty" default:"component:db-connection-pooler"`
|
||||
RoleLabel string `name:"connection_pooler_role_label" default:"pooler-role"`
|
||||
ConnectionPoolerDefaultCPURequest string `name:"connection_pooler_default_cpu_request"`
|
||||
ConnectionPoolerDefaultMemoryRequest string `name:"connection_pooler_default_memory_request"`
|
||||
ConnectionPoolerDefaultCPULimit string `name:"connection_pooler_default_cpu_limit"`
|
||||
ConnectionPoolerDefaultMemoryLimit string `name:"connection_pooler_default_memory_limit"`
|
||||
}
|
||||
|
||||
// Config describes operator config
|
||||
@@ -304,6 +306,11 @@ func Copy(c *Config) Config {
|
||||
cfg.ClusterLabels[k] = v
|
||||
}
|
||||
|
||||
cfg.ConnectionPooler.Labels = make(map[string]string, len(c.ConnectionPooler.Labels))
|
||||
for k, v := range c.ConnectionPooler.Labels {
|
||||
cfg.ConnectionPooler.Labels[k] = v
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user