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

feat: Added support for Consul wan address #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion patroni/dcs/consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ def _update_service(self, data: Dict[str, Any]) -> Optional[bool]:
api_parts = api_parts._replace(path='/{0}'.format(role))
conn_url: str = data['conn_url']
conn_parts = urlparse(conn_url)
conn_wan = data['addresses']
check = base.Check.http(api_parts.geturl(), self._service_check_interval,
deregister='{0}s'.format(self._client.http.ttl * 10))
if self._service_check_tls_server_name is not None:
Expand All @@ -507,6 +508,12 @@ def _update_service(self, data: Dict[str, Any]) -> Optional[bool]:
params = {
'service_id': '{0}/{1}'.format(self._scope, self._name),
'address': conn_parts.hostname,
'tagged_addresses': {
'wan_ipv4' : {
'address' : conn_wan,
'port' : conn_parts.port
}
},
'port': conn_parts.port,
'check': check,
'tags': tags,
Expand All @@ -529,7 +536,7 @@ def _update_service(self, data: Dict[str, Any]) -> Optional[bool]:
def update_service(self, old_data: Dict[str, Any], new_data: Dict[str, Any], force: bool = False) -> Optional[bool]:
update = False

for key in ['role', 'api_url', 'conn_url', 'state']:
for key in ['role', 'api_url', 'conn_url', 'addresses', 'state']:
if key not in new_data:
logger.warning('Could not register service: not enough params in member data')
return
Expand Down
1 change: 1 addition & 0 deletions patroni/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def touch_member(self) -> bool:
with self._member_state_lock:
data: Dict[str, Any] = {
'conn_url': self.state_handler.connection_string,
'addresses': self.state_handler.multi_connection,
'api_url': self.patroni.api.connection_string,
'state': self.state_handler.state,
'role': self.state_handler.role,
Expand Down
1 change: 1 addition & 0 deletions patroni/postgresql/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ def resolve_connection_addresses(self) -> None:
if self._config.get('use_unix_socket_repl') else tcp_local_address

self._postgresql.connection_string = uri('postgres', netloc, self._postgresql.database)
self._postgresql.multi_connection = self._config.get('connect_address_wan')
self._postgresql.set_connection_kwargs(self.local_connect_kwargs)

def _get_pg_settings(
Expand Down