@@ -45,7 +45,7 @@ type ConnectionPoolerObjects struct {
4545}
4646
4747func (c * Cluster ) connectionPoolerName (role PostgresRole ) string {
48- name := c . Name + "-pooler"
48+ name := fmt . Sprintf ( "%s-%s" , c . Name , constants . ConnectionPoolerResourceSuffix )
4949 if role == Replica {
5050 name = fmt .Sprintf ("%s-%s" , name , "repl" )
5151 }
@@ -163,24 +163,27 @@ func (c *Cluster) createConnectionPooler(LookupFunction InstallFunction) (SyncRe
163163 return reason , nil
164164}
165165
166- //
167166// Generate pool size related environment variables.
168167//
169168// MAX_DB_CONN would specify the global maximum for connections to a target
170- // database.
169+ //
170+ // database.
171171//
172172// MAX_CLIENT_CONN is not configurable at the moment, just set it high enough.
173173//
174174// 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.
179180//
180181// 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.
182184//
183185// RESERVE_SIZE is how many additional connections to allow for a pooler.
186+
184187func (c * Cluster ) getConnectionPoolerEnvVars () []v1.EnvVar {
185188 spec := & c .Spec
186189 connectionPoolerSpec := spec .ConnectionPooler
@@ -475,23 +478,23 @@ func (c *Cluster) generateConnectionPoolerDeployment(connectionPooler *Connectio
475478}
476479
477480func (c * Cluster ) generateConnectionPoolerService (connectionPooler * ConnectionPoolerObjects ) * v1.Service {
478-
479481 spec := & c .Spec
482+ poolerRole := connectionPooler .Role
480483 serviceSpec := v1.ServiceSpec {
481484 Ports : []v1.ServicePort {
482485 {
483486 Name : connectionPooler .Name ,
484487 Port : pgPort ,
485- TargetPort : intstr.IntOrString {IntVal : c .servicePort (connectionPooler . Role )},
488+ TargetPort : intstr.IntOrString {IntVal : c .servicePort (poolerRole )},
486489 },
487490 },
488491 Type : v1 .ServiceTypeClusterIP ,
489492 Selector : map [string ]string {
490- "connection-pooler" : c .connectionPoolerName (connectionPooler . Role ),
493+ "connection-pooler" : c .connectionPoolerName (poolerRole ),
491494 },
492495 }
493496
494- if c .shouldCreateLoadBalancerForPoolerService (connectionPooler . Role , spec ) {
497+ if c .shouldCreateLoadBalancerForPoolerService (poolerRole , spec ) {
495498 c .configureLoadBalanceService (& serviceSpec , spec .AllowedSourceRanges )
496499 }
497500
@@ -500,7 +503,7 @@ func (c *Cluster) generateConnectionPoolerService(connectionPooler *ConnectionPo
500503 Name : connectionPooler .Name ,
501504 Namespace : connectionPooler .Namespace ,
502505 Labels : c .connectionPoolerLabels (connectionPooler .Role , false ).MatchLabels ,
503- Annotations : c .annotationsSet (c .generateServiceAnnotations ( connectionPooler . Role , spec )),
506+ Annotations : c .annotationsSet (c .generatePoolerServiceAnnotations ( poolerRole , spec )),
504507 // make StatefulSet object its owner to represent the dependency.
505508 // By itself StatefulSet is being deleted with "Orphaned"
506509 // propagation policy, which means that it's deletion will not
@@ -515,6 +518,32 @@ func (c *Cluster) generateConnectionPoolerService(connectionPooler *ConnectionPo
515518 return service
516519}
517520
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+
518547func (c * Cluster ) shouldCreateLoadBalancerForPoolerService (role PostgresRole , spec * acidv1.PostgresSpec ) bool {
519548
520549 switch role {
@@ -546,7 +575,7 @@ func (c *Cluster) listPoolerPods(listOptions metav1.ListOptions) ([]v1.Pod, erro
546575 return pods .Items , nil
547576}
548577
549- //delete connection pooler
578+ // delete connection pooler
550579func (c * Cluster ) deleteConnectionPooler (role PostgresRole ) (err error ) {
551580 c .logger .Infof ("deleting connection pooler spilo-role=%s" , role )
552581
@@ -605,7 +634,7 @@ func (c *Cluster) deleteConnectionPooler(role PostgresRole) (err error) {
605634 return nil
606635}
607636
608- //delete connection pooler
637+ // delete connection pooler
609638func (c * Cluster ) deleteConnectionPoolerSecret () (err error ) {
610639 // Repeat the same for the secret object
611640 secretName := c .credentialSecretName (c .OpConfig .ConnectionPooler .User )
@@ -654,7 +683,7 @@ func updateConnectionPoolerDeployment(KubeClient k8sutil.KubernetesClient, newDe
654683 return deployment , nil
655684}
656685
657- //updateConnectionPoolerAnnotations updates the annotations of connection pooler deployment
686+ // updateConnectionPoolerAnnotations updates the annotations of connection pooler deployment
658687func updateConnectionPoolerAnnotations (KubeClient k8sutil.KubernetesClient , deployment * appsv1.Deployment , annotations map [string ]string ) (* appsv1.Deployment , error ) {
659688 patchData , err := metaAnnotationsPatch (annotations )
660689 if err != nil {
0 commit comments