@@ -624,6 +624,14 @@ func (p *Postgres) generateDatabaseName() string {
624624 return generatedDatabaseName
625625}
626626
627+ // ToReadWriteHostsList Force Patroni to add target_session_attrs=read-write by providing a comma separated list (with the same IP...).
628+ // This hopefully prevents cascading replicating by preventing the standby leader pod of the standby cluster to
629+ // connect to a read-only pod in the primary cluster (which would break our sync replication to the standby cluster).
630+ // https://patroni.readthedocs.io/en/latest/standby_cluster.html
631+ func (p * Postgres ) ToReadWriteHostsList () string {
632+ return strings .Join ([]string {p .Spec .PostgresConnection .ConnectionIP , p .Spec .PostgresConnection .ConnectionIP }, "," )
633+ }
634+
627635func (p * Postgres ) ToPeripheralResourceNamespace () string {
628636 // We only want letters and numbers
629637 projectID := alphaNumericRegExp .ReplaceAllString (p .Spec .ProjectID , "" )
@@ -789,13 +797,7 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
789797 z .Spec .StandbyCluster = nil
790798 } else {
791799 // overwrite connection info
792-
793- // Force Patroni to add target_session_attrs=read-write by providing a comma separated list (with the same IP...).
794- // This hopefully prevents cascading replicating by preventing the standby leader pod of the standby cluster to
795- // connect to a read-only pod in the primary cluster (which would break our sync replication to the standby cluster).
796- // https://patroni.readthedocs.io/en/latest/standby_cluster.html
797- standbyHosts := strings .Join ([]string {p .Spec .PostgresConnection .ConnectionIP , p .Spec .PostgresConnection .ConnectionIP }, "," )
798-
800+ standbyHosts := p .ToReadWriteHostsList ()
799801 z .Spec .StandbyCluster = & zalando.StandbyDescription {
800802 StandbyHost : standbyHosts ,
801803 StandbyPort : strconv .FormatInt (int64 (p .Spec .PostgresConnection .ConnectionPort ), 10 ),
0 commit comments