Skip to content

Commit 104d87a

Browse files
committed
fix: controller fails with error when pgbouncer instance is not configured properly or unavailable
1 parent 90e567b commit 104d87a

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PgBouncerAuthFileReconciliator.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void updatePgbouncerUsersInAuthFile(ClusterContext context)
9898
Collection<String> users = getPoolingConfigUserNames(context);
9999
var postgresCredentials = PostgresUtil.getPostgresCredentials(context, secretFinder);
100100
final String usersSection = extractAuthFileSectionForUsers(
101-
postgresCredentials.username(), postgresCredentials.password(), users);
101+
postgresCredentials.username(), users);
102102
try (
103103
InputStream originalInputStream = fileSystemHandler.newInputStream(
104104
ORIGINAL_AUTH_FILE_PATH);
@@ -128,15 +128,14 @@ private Collection<String> getPoolingConfigUserNames(ClusterContext context) {
128128
@SuppressWarnings("null")
129129
private String extractAuthFileSectionForUsers(
130130
String postgresUser,
131-
String postgresPassword,
132131
Collection<String> users)
133132
throws SQLException {
134133
List<String> authFileUsersLines = new ArrayList<>();
135-
try (Connection connection = postgresConnectionManager.getConnection(
136-
"localhost", EnvoyUtil.PG_PORT,
134+
try (Connection connection = postgresConnectionManager.getUnixConnection(
135+
ClusterPath.PG_RUN_PATH.path(), EnvoyUtil.PG_PORT,
137136
SUPERUSER_DATABASE,
138137
postgresUser,
139-
postgresPassword);
138+
"");
140139
PreparedStatement statement = connection.prepareStatement(
141140
SELECT_PGBOUNCER_USERS_FROM_PG_SHADOW)) {
142141
statement.setArray(1, connection.createArrayOf(

stackgres-k8s/src/cluster-controller/src/test/java/io/stackgres/cluster/controller/PgBouncerAuthFileReconciliatorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void testReconciliationWithoutUsers_authFileIsUpdated() throws Exception {
104104
.thenReturn(Optional.of(poolingConfig));
105105
when(secretFinder.findByNameAndNamespace(any(), any()))
106106
.thenReturn(Optional.of(secret));
107-
when(postgresConnectionManager.getConnection(any(), anyInt(), any(), any(), any()))
107+
when(postgresConnectionManager.getUnixConnection(any(), anyInt(), any(), any(), any()))
108108
.thenReturn(connection);
109109
when(connection.prepareStatement(any()))
110110
.thenReturn(preparedStatement);
@@ -124,7 +124,7 @@ void testReconciliationWithoutUsers_authFileIsUpdated() throws Exception {
124124
reconciliator.updatePgbouncerUsersInAuthFile(context);
125125
verify(fileSystemHandler, times(1)).copyOrReplace(any(Path.class), any());
126126
verify(fileSystemHandler, times(1)).copyOrReplace(any(InputStream.class), any());
127-
verify(postgresConnectionManager, times(1)).getConnection(any(), anyInt(), any(), any(), any());
127+
verify(postgresConnectionManager, times(1)).getUnixConnection(any(), anyInt(), any(), any(), any());
128128
verify(resultSet, times(1)).next();
129129
assertEquals("user0\n\n\n", authFileContent.join());
130130
}
@@ -152,7 +152,7 @@ void testReconciliationWithUsers_authFileIsUpdated() throws Exception {
152152
.thenReturn(Optional.of(poolingConfig));
153153
when(secretFinder.findByNameAndNamespace(any(), any()))
154154
.thenReturn(Optional.of(secret));
155-
when(postgresConnectionManager.getConnection(any(), anyInt(), any(), any(), any()))
155+
when(postgresConnectionManager.getUnixConnection(any(), anyInt(), any(), any(), any()))
156156
.thenReturn(connection);
157157
when(connection.prepareStatement(any()))
158158
.thenReturn(preparedStatement);
@@ -176,7 +176,7 @@ void testReconciliationWithUsers_authFileIsUpdated() throws Exception {
176176
reconciliator.updatePgbouncerUsersInAuthFile(context);
177177
verify(fileSystemHandler, times(1)).copyOrReplace(any(Path.class), any());
178178
verify(fileSystemHandler, times(1)).copyOrReplace(any(InputStream.class), any());
179-
verify(postgresConnectionManager, times(1)).getConnection(any(), anyInt(), any(), any(), any());
179+
verify(postgresConnectionManager, times(1)).getUnixConnection(any(), anyInt(), any(), any(), any());
180180
verify(resultSet, times(3)).next();
181181
verify(resultSet, times(2)).getString(eq(1));
182182
assertEquals("user0\n\nuser1\nuser2\n", authFileContent.join());

0 commit comments

Comments
 (0)