Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set tags for load balancers #613

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions inventory
Original file line number Diff line number Diff line change
@@ -2,14 +2,12 @@
# The specified ip addresses will be used to listen by the cluster components.
# Attention! Specify private IP addresses so that the cluster does not listen a public IP addresses.
# For deploying via public IPs, add 'ansible_host=public_ip_address' variable for each node.

# "postgresql_exists='true'" if PostgreSQL is already exists and running
#
# "postgresql_exists=true" if PostgreSQL is already exists and running
# "hostname=" variable is optional (used to change the server name)
# "new_node=true" to add a new server to an existing cluster using the add_pgnode.yml playbook
# patroni_tags="key=value" tags for Patroni in "key=value" format separated by commas (details here: https://patroni.readthedocs.io/en/latest/yaml_configuration.html#tags)

# In this example, all components will be installed on PostgreSQL nodes.
# You can deploy the haproxy balancers and the etcd or consul cluster on other dedicated servers (recomended).
# patroni_tags="key=value" the Patroni tags in "key=value" format separated by commas.
# balancer_tags="key=value" the Balancer tags for the /replica, /sync, /async endpoints. Add the tag to the 'patroni_tags' variable first.

# if dcs_exists: false and dcs_type: "etcd"
[etcd_cluster] # recommendation: 3, or 5-7 nodes
@@ -27,10 +25,11 @@

# if with_haproxy_load_balancing: true
[balancers]
10.128.64.140
10.128.64.142
10.128.64.143
#10.128.64.144 new_node=true
10.128.64.140 # balancer_tags="datacenter=dc1"
10.128.64.142 # balancer_tags="datacenter=dc1"
10.128.64.143 # balancer_tags="datacenter=dc1"
#10.128.64.144 balancer_tags="datacenter=dc2"
#10.128.64.145 balancer_tags="datacenter=dc2" new_node=true

# PostgreSQL nodes
[master]
@@ -39,7 +38,7 @@
[replica]
10.128.64.142 hostname=pgnode02 postgresql_exists=false # patroni_tags="datacenter=dc1"
10.128.64.143 hostname=pgnode03 postgresql_exists=false # patroni_tags="datacenter=dc1"
#10.128.64.144 hostname=pgnode04 postgresql_exists=false patroni_tags="datacenter=dc2" new_node=true
#10.128.64.144 hostname=pgnode04 postgresql_exists=false patroni_tags="datacenter=dc2"
#10.128.64.145 hostname=pgnode04 postgresql_exists=false patroni_tags="datacenter=dc2" new_node=true

[postgres_cluster:children]
@@ -60,6 +59,6 @@ ansible_ssh_pass='secretpassword' # "sshpass" package is required for use "ansi
#ansible_python_interpreter='/usr/bin/python3' # is required for use python3

[pgbackrest:vars]
ansible_user='postgres'
ansible_ssh_pass='secretpassword'
#ansible_user='postgres'
#ansible_ssh_pass='secretpassword'

1 change: 1 addition & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
postgresql_version: "16" # to test custom WAL dir
pgbouncer_processes: 2 # Test multiple pgbouncer processes (so_reuseport)
patroni_tags: "datacenter=dc1,key1=value1"
balancer_tags: "datacenter=dc1"
cacheable: true
delegate_to: localhost
run_once: true # noqa run-once
12 changes: 6 additions & 6 deletions roles/confd/templates/haproxy.tmpl.j2
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ listen replicas
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -91,7 +91,7 @@ listen replicas_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -107,7 +107,7 @@ listen replicas_sync
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -129,7 +129,7 @@ listen replicas_sync_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -145,7 +145,7 @@ listen replicas_async
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -167,7 +167,7 @@ listen replicas_async_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
12 changes: 6 additions & 6 deletions roles/haproxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ listen replicas
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -96,7 +96,7 @@ listen replicas_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -113,7 +113,7 @@ listen replicas_sync
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -137,7 +137,7 @@ listen replicas_sync_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -154,7 +154,7 @@ listen replicas_async
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
@@ -178,7 +178,7 @@ listen replicas_async_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions