Skip to content

Commit 793f4ed

Browse files
committed
feat: generate postgres user secret with r2dbc uris
1 parent e8bcff1 commit 793f4ed

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

internal/controller/postgrescluster/postgres.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ func (r *Reconciler) generatePostgresUserSecret(
128128
Path: database,
129129
RawQuery: query.Encode(),
130130
}).String())
131+
// The R2DBC driver requires a different URI scheme than the JDBC driver
132+
// - https://r2dbc.io/spec/1.0.0.RELEASE/spec/html/#overview.connection.url
133+
intent.Data["r2dbc-uri"] = []byte((&url.URL{
134+
Scheme: "r2dbc:postgresql",
135+
Host: net.JoinHostPort(hostname, port),
136+
Path: database,
137+
RawQuery: query.Encode(),
138+
}).String())
131139
}
132140

133141
// When PgBouncer is enabled, include values for connecting through it.
@@ -164,6 +172,12 @@ func (r *Reconciler) generatePostgresUserSecret(
164172
Path: database,
165173
RawQuery: query.Encode(),
166174
}).String())
175+
intent.Data["pgbouncer-r2dbc-uri"] = []byte((&url.URL{
176+
Scheme: "r2dbc:postgresql",
177+
Host: net.JoinHostPort(hostname, port),
178+
Path: database,
179+
RawQuery: query.Encode(),
180+
}).String())
167181
}
168182
}
169183

internal/controller/postgrescluster/postgres_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
183183
`^jdbc:postgresql://hippo2-primary.ns1.svc:9999/db1`+
184184
`[?]password=[^&]+&user=some-user-name$`,
185185
string(secret.Data["jdbc-uri"])))
186+
assert.Assert(t, cmp.Regexp(
187+
`^r2dbc:postgresql://hippo2-primary.ns1.svc:9999/db1`+
188+
`[?]password=[^&]+&user=some-user-name$`,
189+
string(secret.Data["r2dbc-uri"])))
186190
}
187191

188192
// Only the first in the list.
@@ -199,7 +203,9 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
199203
assert.Assert(t, cmp.Regexp(
200204
`^jdbc:postgresql://hippo2-primary.ns1.svc:9999/first[?].+$`,
201205
string(secret.Data["jdbc-uri"])))
202-
206+
assert.Assert(t, cmp.Regexp(
207+
`^r2dbc:postgresql://hippo2-primary.ns1.svc:9999/first[?].+$`,
208+
string(secret.Data["r2dbc-uri"])))
203209
}
204210
})
205211

@@ -233,6 +239,10 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
233239
`^jdbc:postgresql://hippo2-pgbouncer.ns1.svc:10220/yes`+
234240
`[?]password=[^&]+&prepareThreshold=0&user=some-user-name$`,
235241
string(secret.Data["pgbouncer-jdbc-uri"])))
242+
assert.Assert(t, cmp.Regexp(
243+
`^r2dbc:postgresql://hippo2-pgbouncer.ns1.svc:10220/yes`+
244+
`[?]password=[^&]+&prepareThreshold=0&user=some-user-name$`,
245+
string(secret.Data["pgbouncer-r2dbc-uri"])))
236246
}
237247
})
238248
}

0 commit comments

Comments
 (0)