@@ -45,7 +45,7 @@ type ConnectionPoolerObjects struct {
45
45
}
46
46
47
47
func (c * Cluster ) connectionPoolerName (role PostgresRole ) string {
48
- name := c . Name + "-pooler"
48
+ name := fmt . Sprintf ( "%s-%s" , c . Name , constants . ConnectionPoolerResourceSuffix )
49
49
if role == Replica {
50
50
name = fmt .Sprintf ("%s-%s" , name , "repl" )
51
51
}
@@ -163,24 +163,27 @@ func (c *Cluster) createConnectionPooler(LookupFunction InstallFunction) (SyncRe
163
163
return reason , nil
164
164
}
165
165
166
- //
167
166
// Generate pool size related environment variables.
168
167
//
169
168
// MAX_DB_CONN would specify the global maximum for connections to a target
170
- // database.
169
+ //
170
+ // database.
171
171
//
172
172
// MAX_CLIENT_CONN is not configurable at the moment, just set it high enough.
173
173
//
174
174
// DEFAULT_SIZE is a pool size per db/user (having in mind the use case when
175
- // most of the queries coming through a connection pooler are from the same
176
- // user to the same db). In case if we want to spin up more connection pooler
177
- // instances, take this into account and maintain the same number of
178
- // connections.
175
+ //
176
+ // most of the queries coming through a connection pooler are from the same
177
+ // user to the same db). In case if we want to spin up more connection pooler
178
+ // instances, take this into account and maintain the same number of
179
+ // connections.
179
180
//
180
181
// MIN_SIZE is a pool's minimal size, to prevent situation when sudden workload
181
- // have to wait for spinning up a new connections.
182
+ //
183
+ // have to wait for spinning up a new connections.
182
184
//
183
185
// RESERVE_SIZE is how many additional connections to allow for a pooler.
186
+
184
187
func (c * Cluster ) getConnectionPoolerEnvVars () []v1.EnvVar {
185
188
spec := & c .Spec
186
189
connectionPoolerSpec := spec .ConnectionPooler
@@ -475,23 +478,23 @@ func (c *Cluster) generateConnectionPoolerDeployment(connectionPooler *Connectio
475
478
}
476
479
477
480
func (c * Cluster ) generateConnectionPoolerService (connectionPooler * ConnectionPoolerObjects ) * v1.Service {
478
-
479
481
spec := & c .Spec
482
+ poolerRole := connectionPooler .Role
480
483
serviceSpec := v1.ServiceSpec {
481
484
Ports : []v1.ServicePort {
482
485
{
483
486
Name : connectionPooler .Name ,
484
487
Port : pgPort ,
485
- TargetPort : intstr.IntOrString {IntVal : c .servicePort (connectionPooler . Role )},
488
+ TargetPort : intstr.IntOrString {IntVal : c .servicePort (poolerRole )},
486
489
},
487
490
},
488
491
Type : v1 .ServiceTypeClusterIP ,
489
492
Selector : map [string ]string {
490
- "connection-pooler" : c .connectionPoolerName (connectionPooler . Role ),
493
+ "connection-pooler" : c .connectionPoolerName (poolerRole ),
491
494
},
492
495
}
493
496
494
- if c .shouldCreateLoadBalancerForPoolerService (connectionPooler . Role , spec ) {
497
+ if c .shouldCreateLoadBalancerForPoolerService (poolerRole , spec ) {
495
498
c .configureLoadBalanceService (& serviceSpec , spec .AllowedSourceRanges )
496
499
}
497
500
@@ -500,7 +503,7 @@ func (c *Cluster) generateConnectionPoolerService(connectionPooler *ConnectionPo
500
503
Name : connectionPooler .Name ,
501
504
Namespace : connectionPooler .Namespace ,
502
505
Labels : c .connectionPoolerLabels (connectionPooler .Role , false ).MatchLabels ,
503
- Annotations : c .annotationsSet (c .generateServiceAnnotations ( connectionPooler . Role , spec )),
506
+ Annotations : c .annotationsSet (c .generatePoolerServiceAnnotations ( poolerRole , spec )),
504
507
// make StatefulSet object its owner to represent the dependency.
505
508
// By itself StatefulSet is being deleted with "Orphaned"
506
509
// propagation policy, which means that it's deletion will not
@@ -515,6 +518,32 @@ func (c *Cluster) generateConnectionPoolerService(connectionPooler *ConnectionPo
515
518
return service
516
519
}
517
520
521
+ func (c * Cluster ) generatePoolerServiceAnnotations (role PostgresRole , spec * acidv1.PostgresSpec ) map [string ]string {
522
+ var dnsString string
523
+ annotations := c .getCustomServiceAnnotations (role , spec )
524
+
525
+ if c .shouldCreateLoadBalancerForPoolerService (role , spec ) {
526
+ // set ELB Timeout annotation with default value
527
+ if _ , ok := annotations [constants .ElbTimeoutAnnotationName ]; ! ok {
528
+ annotations [constants .ElbTimeoutAnnotationName ] = constants .ElbTimeoutAnnotationValue
529
+ }
530
+ // -repl suffix will be added by replicaDNSName
531
+ clusterNameWithPoolerSuffix := c .connectionPoolerName (Master )
532
+ if role == Master {
533
+ dnsString = c .masterDNSName (clusterNameWithPoolerSuffix )
534
+ } else {
535
+ dnsString = c .replicaDNSName (clusterNameWithPoolerSuffix )
536
+ }
537
+ annotations [constants .ZalandoDNSNameAnnotation ] = dnsString
538
+ }
539
+
540
+ if len (annotations ) == 0 {
541
+ return nil
542
+ }
543
+
544
+ return annotations
545
+ }
546
+
518
547
func (c * Cluster ) shouldCreateLoadBalancerForPoolerService (role PostgresRole , spec * acidv1.PostgresSpec ) bool {
519
548
520
549
switch role {
@@ -546,7 +575,7 @@ func (c *Cluster) listPoolerPods(listOptions metav1.ListOptions) ([]v1.Pod, erro
546
575
return pods .Items , nil
547
576
}
548
577
549
- //delete connection pooler
578
+ // delete connection pooler
550
579
func (c * Cluster ) deleteConnectionPooler (role PostgresRole ) (err error ) {
551
580
c .logger .Infof ("deleting connection pooler spilo-role=%s" , role )
552
581
@@ -605,7 +634,7 @@ func (c *Cluster) deleteConnectionPooler(role PostgresRole) (err error) {
605
634
return nil
606
635
}
607
636
608
- //delete connection pooler
637
+ // delete connection pooler
609
638
func (c * Cluster ) deleteConnectionPoolerSecret () (err error ) {
610
639
// Repeat the same for the secret object
611
640
secretName := c .credentialSecretName (c .OpConfig .ConnectionPooler .User )
@@ -654,7 +683,7 @@ func updateConnectionPoolerDeployment(KubeClient k8sutil.KubernetesClient, newDe
654
683
return deployment , nil
655
684
}
656
685
657
- //updateConnectionPoolerAnnotations updates the annotations of connection pooler deployment
686
+ // updateConnectionPoolerAnnotations updates the annotations of connection pooler deployment
658
687
func updateConnectionPoolerAnnotations (KubeClient k8sutil.KubernetesClient , deployment * appsv1.Deployment , annotations map [string ]string ) (* appsv1.Deployment , error ) {
659
688
patchData , err := metaAnnotationsPatch (annotations )
660
689
if err != nil {
0 commit comments