Skip to content

Commit b41f677

Browse files
committed
feat: Allow to disable Envoy
1 parent 1a3dd82 commit b41f677

8 files changed

Lines changed: 323 additions & 136 deletions

File tree

stackgres-k8s/e2e/spec/abstract/patroni

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
23
patroni_ports_check() {
34
if patroni_liveness_check
45
then
@@ -38,11 +39,11 @@ patroni_switchover(){
3839
}
3940

4041
patroni_direct_switchover_check(){
41-
patroni_curl -e "switchover" -p 8009 -XPOST -d '{"leader":"'"$CLUSTER_NAME-0"'"}' > /dev/null
42+
patroni_curl -e "switchover" -p 8009 -XPOST -d '{"leader":"'"$CLUSTER_NAME-0"'"}' > /dev/null
4243
}
4344

4445
patroni_liveness_check() {
45-
patroni_curl -e "cluster" > /dev/null
46+
patroni_curl -e "cluster" > /dev/null
4647
}
4748

4849
patroni_readiness_check() {
@@ -54,7 +55,7 @@ get_pod_ip(){
5455
}
5556

5657
patroni_curl(){
57-
PORT=8008
58+
PORT="${PATRONI_PORT:-8008}"
5859
POD_IP="$(get_pod_ip)"
5960
ENPOINT="cluster"
6061

stackgres-k8s/e2e/spec/no-envoy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ e2e_test_extra_hash() {
88
}
99

1010
e2e_test_install() {
11+
PATRONI_PORT=8009
12+
1113
create_or_replace_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE" "2"
1214

1315
deploy_curl_pod "$CLUSTER_NAMESPACE"
@@ -51,11 +53,11 @@ ports_check() {
5153
}
5254

5355
service_check() {
54-
RESPONSE_PRIMARY="$(run_query -h "$CLUSTER_NAME" -i 1 -p 5432)"
56+
RESPONSE_PRIMARY="$(wait_until run_query -h "$CLUSTER_NAME" -i 1 -p 5432)"
5557

5658
if [ "$RESPONSE_PRIMARY" = "1" ]
5759
then
58-
RESPONSE_REPLICA="$(run_query -h "$CLUSTER_NAME"-replicas -i 0 -p 5432)"
60+
RESPONSE_REPLICA="$(wait_until run_query -h "$CLUSTER_NAME"-replicas -i 0 -p 5432)"
5961
if [ "$RESPONSE_REPLICA" = "1" ]
6062
then
6163
success "Connections are possible using services"

stackgres-k8s/src/common/src/main/java/io/stackgres/common/PatroniUtil.java

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,65 @@ private static JsonNode getPatroniEndpointPortsAsJson(
295295

296296
static List<EndpointPort> getPatroniEndpointPorts(final StackGresCluster cluster) {
297297
List<EndpointPort> patroniEndpointPorts = new ArrayList<>();
298-
patroniEndpointPorts.add(new EndpointPortBuilder()
299-
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
300-
.withPort(EnvoyUtil.PG_ENTRY_PORT)
301-
.withProtocol("TCP")
302-
.build());
303-
patroniEndpointPorts.add(new EndpointPortBuilder()
304-
.withName(EnvoyUtil.POSTGRES_REPLICATION_PORT_NAME)
305-
.withPort(EnvoyUtil.PG_REPL_ENTRY_PORT)
306-
.withProtocol("TCP")
307-
.build());
308-
if (getPostgresFlavorComponent(cluster) == StackGresComponent.BABELFISH) {
298+
boolean isEnvoyDisabled = Optional.of(cluster)
299+
.map(StackGresCluster::getSpec)
300+
.map(StackGresClusterSpec::getPods)
301+
.map(StackGresClusterPods::getDisableEnvoy)
302+
.orElse(false);
303+
boolean isConnectionPoolingDisabled = Optional.of(cluster)
304+
.map(StackGresCluster::getSpec)
305+
.map(StackGresClusterSpec::getPods)
306+
.map(StackGresClusterPods::getDisableConnectionPooling)
307+
.orElse(false);
308+
if (isEnvoyDisabled) {
309+
if (isConnectionPoolingDisabled) {
310+
patroniEndpointPorts.add(new EndpointPortBuilder()
311+
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
312+
.withPort(EnvoyUtil.PG_PORT)
313+
.withProtocol("TCP")
314+
.build());
315+
patroniEndpointPorts.add(new EndpointPortBuilder()
316+
.withName(EnvoyUtil.POSTGRES_REPLICATION_PORT_NAME)
317+
.withPort(EnvoyUtil.PG_PORT)
318+
.withProtocol("TCP")
319+
.build());
320+
} else {
321+
patroniEndpointPorts.add(new EndpointPortBuilder()
322+
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
323+
.withPort(EnvoyUtil.PG_POOL_PORT)
324+
.withProtocol("TCP")
325+
.build());
326+
patroniEndpointPorts.add(new EndpointPortBuilder()
327+
.withName(EnvoyUtil.POSTGRES_REPLICATION_PORT_NAME)
328+
.withPort(EnvoyUtil.PG_PORT)
329+
.withProtocol("TCP")
330+
.build());
331+
}
332+
if (getPostgresFlavorComponent(cluster) == StackGresComponent.BABELFISH) {
333+
patroniEndpointPorts.add(new EndpointPortBuilder()
334+
.withName(EnvoyUtil.BABELFISH_PORT_NAME)
335+
.withPort(EnvoyUtil.BF_PORT)
336+
.withProtocol("TCP")
337+
.build());
338+
}
339+
} else {
340+
patroniEndpointPorts.add(new EndpointPortBuilder()
341+
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
342+
.withPort(EnvoyUtil.PG_ENTRY_PORT)
343+
.withProtocol("TCP")
344+
.build());
309345
patroniEndpointPorts.add(new EndpointPortBuilder()
310-
.withName(EnvoyUtil.BABELFISH_PORT_NAME)
311-
.withPort(EnvoyUtil.BF_ENTRY_PORT)
346+
.withName(EnvoyUtil.POSTGRES_REPLICATION_PORT_NAME)
347+
.withPort(EnvoyUtil.PG_REPL_ENTRY_PORT)
312348
.withProtocol("TCP")
313349
.build());
350+
if (getPostgresFlavorComponent(cluster) == StackGresComponent.BABELFISH) {
351+
patroniEndpointPorts.add(new EndpointPortBuilder()
352+
.withName(EnvoyUtil.BABELFISH_PORT_NAME)
353+
.withPort(EnvoyUtil.BF_ENTRY_PORT)
354+
.withProtocol("TCP")
355+
.build());
356+
}
314357
}
315358
Optional.of(cluster)
316359
.map(StackGresCluster::getSpec)

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

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ public Container getContainer(ClusterContainerContext context) {
163163
volumeMounts.addAll(restoreMounts.getVolumeMounts(context))
164164
);
165165

166-
var containerBuilder = new ContainerBuilder()
166+
boolean isEnvoyDisabled = Optional.of(cluster)
167+
.map(StackGresCluster::getSpec)
168+
.map(StackGresClusterSpec::getPods)
169+
.map(StackGresClusterPods::getDisableEnvoy)
170+
.orElse(false);
171+
final int patroniPort = isEnvoyDisabled ? EnvoyUtil.PATRONI_PORT : EnvoyUtil.PATRONI_ENTRY_PORT;
172+
173+
return new ContainerBuilder()
167174
.withName(StackGresContainer.PATRONI.getName())
168175
.withImage(patroniImageName)
169176
.withCommand("/bin/sh", "-ex",
@@ -190,7 +197,7 @@ public Container getContainer(ClusterContainerContext context) {
190197
.withLivenessProbe(new ProbeBuilder()
191198
.withHttpGet(new HTTPGetActionBuilder()
192199
.withPath("/liveness")
193-
.withPort(new IntOrString(EnvoyUtil.PATRONI_ENTRY_PORT))
200+
.withPort(new IntOrString(patroniPort))
194201
.withScheme("HTTP")
195202
.build())
196203
.withInitialDelaySeconds(15)
@@ -200,60 +207,86 @@ public Container getContainer(ClusterContainerContext context) {
200207
.withReadinessProbe(new ProbeBuilder()
201208
.withHttpGet(new HTTPGetActionBuilder()
202209
.withPath("/readiness")
203-
.withPort(new IntOrString(EnvoyUtil.PATRONI_ENTRY_PORT))
210+
.withPort(new IntOrString(patroniPort))
204211
.withScheme("HTTP")
205212
.build())
206213
.withInitialDelaySeconds(0)
207214
.withPeriodSeconds(2)
208215
.withTimeoutSeconds(1)
209-
.build());
210-
if (Optional.of(cluster)
216+
.build())
217+
.withPorts(getContainerPorts(cluster))
218+
.build();
219+
}
220+
221+
private List<ContainerPort> getContainerPorts(StackGresCluster cluster) {
222+
boolean isEnvoyDisabled = Optional.of(cluster)
211223
.map(StackGresCluster::getSpec)
212224
.map(StackGresClusterSpec::getPods)
213225
.map(StackGresClusterPods::getDisableEnvoy)
214-
.orElse(false)) {
215-
containerBuilder.withPorts(getContainerPorts(cluster));
226+
.orElse(false);
227+
if (!isEnvoyDisabled) {
228+
return List.of();
216229
}
217-
return containerBuilder.build();
218-
}
219-
220-
private List<ContainerPort> getContainerPorts(StackGresCluster cluster) {
221230
boolean isConnectionPoolingDisabled = Optional.of(cluster)
222231
.map(StackGresCluster::getSpec)
223232
.map(StackGresClusterSpec::getPods)
224233
.map(StackGresClusterPods::getDisableConnectionPooling)
225234
.orElse(false);
226235
if (getPostgresFlavorComponent(cluster) == StackGresComponent.BABELFISH) {
236+
if (isConnectionPoolingDisabled) {
237+
return List.of(
238+
new ContainerPortBuilder()
239+
.withProtocol("TCP")
240+
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
241+
.withContainerPort(EnvoyUtil.PG_ENTRY_PORT)
242+
.build(),
243+
new ContainerPortBuilder()
244+
.withProtocol("TCP")
245+
.withName(EnvoyUtil.BABELFISH_PORT_NAME)
246+
.withContainerPort(EnvoyUtil.BF_PORT)
247+
.build(),
248+
new ContainerPortBuilder()
249+
.withName(EnvoyUtil.PATRONI_RESTAPI_PORT_NAME)
250+
.withProtocol("TCP")
251+
.withContainerPort(EnvoyUtil.PATRONI_PORT)
252+
.build());
253+
}
227254
return List.of(
228-
new ContainerPortBuilder()
229-
.withProtocol("TCP")
230-
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
231-
.withContainerPort(isConnectionPoolingDisabled
232-
? EnvoyUtil.PG_ENTRY_PORT : EnvoyUtil.PG_POOL_PORT).build(),
233255
new ContainerPortBuilder()
234256
.withProtocol("TCP")
235257
.withName(EnvoyUtil.POSTGRES_REPLICATION_PORT_NAME)
236-
.withContainerPort(EnvoyUtil.PG_PORT).build(),
258+
.withContainerPort(EnvoyUtil.PG_PORT)
259+
.build(),
237260
new ContainerPortBuilder()
238261
.withProtocol("TCP")
239262
.withName(EnvoyUtil.BABELFISH_PORT_NAME)
240-
.withContainerPort(EnvoyUtil.BF_PORT).build(),
263+
.withContainerPort(EnvoyUtil.BF_PORT)
264+
.build(),
265+
new ContainerPortBuilder()
266+
.withName(EnvoyUtil.PATRONI_RESTAPI_PORT_NAME)
267+
.withProtocol("TCP")
268+
.withContainerPort(EnvoyUtil.PATRONI_PORT)
269+
.build());
270+
}
271+
if (isConnectionPoolingDisabled) {
272+
return List.of(
273+
new ContainerPortBuilder()
274+
.withProtocol("TCP")
275+
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
276+
.withContainerPort(EnvoyUtil.PG_PORT)
277+
.build(),
241278
new ContainerPortBuilder()
242279
.withName(EnvoyUtil.PATRONI_RESTAPI_PORT_NAME)
243280
.withProtocol("TCP")
244281
.withContainerPort(EnvoyUtil.PATRONI_PORT)
245282
.build());
246283
}
247284
return List.of(
248-
new ContainerPortBuilder()
249-
.withProtocol("TCP")
250-
.withName(EnvoyUtil.POSTGRES_PORT_NAME)
251-
.withContainerPort(isConnectionPoolingDisabled
252-
? EnvoyUtil.PG_ENTRY_PORT : EnvoyUtil.PG_POOL_PORT).build(),
253285
new ContainerPortBuilder()
254286
.withProtocol("TCP")
255287
.withName(EnvoyUtil.POSTGRES_REPLICATION_PORT_NAME)
256-
.withContainerPort(EnvoyUtil.PG_PORT).build(),
288+
.withContainerPort(EnvoyUtil.PG_PORT)
289+
.build(),
257290
new ContainerPortBuilder()
258291
.withName(EnvoyUtil.PATRONI_RESTAPI_PORT_NAME)
259292
.withProtocol("TCP")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private Map<String, String> getPostgresParameters(
299299
.map(StackGresClusterSpec::getPods)
300300
.map(StackGresClusterPods::getDisableEnvoy)
301301
.orElse(false);
302-
params.put("listen_address", isEnvoyDisabled ? "0.0.0.0" : "localhost");
302+
params.put("listen_addresses", isEnvoyDisabled ? "0.0.0.0" : "localhost");
303303
params.put("port", String.valueOf(EnvoyUtil.PG_PORT));
304304

305305
if (isBackupConfigurationPresent) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static String name(ClusterContext clusterContext) {
116116
.flatMap(StackGresClusterPatroniConfig::getPgCtlTimeout)
117117
.map(Object::toString)
118118
.orElse("60"));
119-
data.put("PATRONI_POSTGRESQL_LISTEN", "127.0.0.1:" + EnvoyUtil.PG_PORT);
119+
data.put("PATRONI_POSTGRESQL_LISTEN", (isEnvoyDisabled ? "0.0.0.0:" : "127.0.0.1:") + EnvoyUtil.PG_PORT);
120120
data.put("PATRONI_POSTGRESQL_CONNECT_ADDRESS",
121121
"${POD_IP}:" + (isEnvoyDisabled ? EnvoyUtil.PG_PORT : EnvoyUtil.PG_REPL_ENTRY_PORT));
122122

0 commit comments

Comments
 (0)