Skip to content

Commit c4563ba

Browse files
committed
feat: use FQDN instead of pod IP for Patroni connect_address
This change fixes Citus metadata sync issues where nodes register in pg_dist_node with ephemeral pod IPs. When pods restart and get new IPs, the stale IPs in pg_dist_node cause metadata synchronization to fail. Changes: - PatroniConfigMap.java: Added PATRONI_CONFIG_SERVICE_NAME and PATRONI_POD_NAMESPACE env vars, changed PATRONI_POSTGRESQL_CONNECT_ADDRESS to use FQDN pattern - PatroniEnvironmentVariables.java: Changed PATRONI_RESTAPI_CONNECT_ADDRESS to use FQDN pattern - start-patroni.sh: Changed connect_address in restapi and postgresql sections to use the FQDN-based env vars instead of PATRONI_KUBERNETES_POD_IP The FQDN pattern used is: ${POD_NAME}.${PATRONI_CONFIG_SERVICE_NAME}.${PATRONI_POD_NAMESPACE}.svc.cluster.local This ensures stable node registration that survives pod restarts.
1 parent 3b13f2f commit c4563ba

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/patroni/PatroniConfigMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ public static String name(ClusterContext clusterContext) {
117117
.map(Object::toString)
118118
.orElse("60"));
119119
data.put("PATRONI_POSTGRESQL_LISTEN", (isEnvoyDisabled ? "0.0.0.0,[::]:" : "127.0.0.1,[::1]:") + EnvoyUtil.PG_PORT);
120+
// Use FQDN instead of POD_IP for stable node registration in Citus pg_dist_node
121+
data.put("PATRONI_CONFIG_SERVICE_NAME", PatroniUtil.configName(cluster));
122+
data.put("PATRONI_POD_NAMESPACE", cluster.getMetadata().getNamespace());
120123
data.put("PATRONI_POSTGRESQL_CONNECT_ADDRESS",
121-
"${POD_IP}:" + (isEnvoyDisabled ? EnvoyUtil.PG_PORT : EnvoyUtil.PG_REPL_ENTRY_PORT));
124+
"${POD_NAME}.${PATRONI_CONFIG_SERVICE_NAME}.${PATRONI_POD_NAMESPACE}.svc.cluster.local:"
125+
+ (isEnvoyDisabled ? EnvoyUtil.PG_PORT : EnvoyUtil.PG_REPL_ENTRY_PORT));
122126

123127
data.put("PATRONI_RESTAPI_LISTEN", "*:" + EnvoyUtil.PATRONI_PORT);
124128
data.put("PATRONI_POSTGRESQL_DATA_DIR", ClusterPath.PG_DATA_PATH.path());

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/patroni/PatroniEnvironmentVariables.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ && getPostgresFlavorComponent(cluster) == StackGresComponent.BABELFISH) {
202202
.build(),
203203
new EnvVarBuilder()
204204
.withName("PATRONI_RESTAPI_CONNECT_ADDRESS")
205-
.withValue("${POD_IP}:" + EnvoyUtil.PATRONI_PORT)
205+
// Use FQDN instead of POD_IP for stable node registration in Citus pg_dist_node
206+
.withValue("${POD_NAME}.${PATRONI_CONFIG_SERVICE_NAME}.${PATRONI_POD_NAMESPACE}.svc.cluster.local:" + EnvoyUtil.PATRONI_PORT)
206207
.build());
207208

208209
return ImmutableList.<EnvVar>builder()

stackgres-k8s/src/operator/src/main/resources/templates/start-patroni.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ fi
254254
- 'host replication ${PATRONI_REPLICATION_USERNAME} 0.0.0.0/0 md5'
255255
- 'host replication ${PATRONI_REPLICATION_USERNAME} ::/0 md5'
256256
restapi:
257-
connect_address: '${PATRONI_KUBERNETES_POD_IP}:8008'
257+
connect_address: '${PATRONI_RESTAPI_CONNECT_ADDRESS}'
258258
listen: "*:8008"
259259
postgresql:
260260
use_slots: true
261261
use_pg_rewind: true
262262
remove_data_directory_on_rewind_failure: true
263263
use_unix_socket: true
264264
use_unix_socket_repl: true
265-
connect_address: '${PATRONI_KUBERNETES_POD_IP}:5432'
265+
connect_address: '${PATRONI_POSTGRESQL_CONNECT_ADDRESS}'
266266
listen: 0.0.0.0,[::]:5432
267267
pg_ctl_timeout: $PATRONI_PG_CTL_TIMEOUT
268268
authentication:

0 commit comments

Comments
 (0)