Skip to content
Closed
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
16 changes: 13 additions & 3 deletions postgres-appliance/scripts/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def deep_update(a, b):
scope: &scope '{{SCOPE}}'
restapi:
listen: ':{{APIPORT}}'
connect_address: {{RESTAPI_CONNECT_ADDRESS}}:{{APIPORT}}
connect_address: '{{RESTAPI_CONNECT_ADDRESS}}'
{{#SSL_RESTAPI_CA_FILE}}
cafile: {{SSL_RESTAPI_CA_FILE}}
{{/SSL_RESTAPI_CA_FILE}}
Expand All @@ -284,7 +284,7 @@ def deep_update(a, b):
use_unix_socket_repl: true
name: '{{instance_data.id}}'
listen: '*:{{PGPORT}}'
connect_address: {{instance_data.ip}}:{{PGPORT}}
connect_address: '{{PG_CONNECT_ADDRESS}}'
data_dir: {{PGDATA}}
parameters:
archive_command: {{{postgresql.parameters.archive_command}}}
Expand Down Expand Up @@ -696,7 +696,11 @@ def get_placeholders(provider):
placeholders['postgresql']['parameters']['max_connections'] = min(max(100, int(os_memory_mb/30)), 1000)

placeholders['instance_data'] = get_instance_metadata(provider)
placeholders.setdefault('RESTAPI_CONNECT_ADDRESS', placeholders['instance_data']['ip'])
restapi_connect_address = format_url(placeholders['instance_data']['ip'], placeholders.get("APIPORT"))
placeholders.setdefault('RESTAPI_CONNECT_ADDRESS', restapi_connect_address)

connect_address = format_url(placeholders['instance_data']['ip'], placeholders.get("PGPORT"))
placeholders.setdefault("PG_CONNECT_ADDRESS", connect_address)

placeholders['BGMON_LISTEN_IP'] = get_listen_ip()

Expand All @@ -718,6 +722,12 @@ def get_placeholders(provider):
return placeholders


def format_url(host, port):
if ":" in host:
return "[" + host + "]" + ":" + port
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this does also work with ipv4?

Copy link
Copy Markdown
Member Author

@mikkeloscar mikkeloscar Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if a host (without port) has : in it it indicates IPv6 address and we add the [] if not we leave it as is.

(I was testing this change internally to validate that it works, hence the PR was in draft, it probably changed when you commented)

return host + ":" + port


def pystache_render(*args, **kwargs):
render = pystache.Renderer(missing_tags='strict')
return render.render(*args, **kwargs)
Expand Down