Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions internal/controller/postgrescluster/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ func (r *Reconciler) generatePostgresUserSecret(
Path: database,
RawQuery: query.Encode(),
}).String())
// The R2DBC driver requires a different URI scheme than the JDBC driver
// - https://r2dbc.io/spec/1.0.0.RELEASE/spec/html/#overview.connection.url
intent.Data["r2dbc-uri"] = []byte((&url.URL{
Scheme: "r2dbc:postgresql",
Host: net.JoinHostPort(hostname, port),
Path: database,
RawQuery: query.Encode(),
}).String())
}

// When PgBouncer is enabled, include values for connecting through it.
Expand Down Expand Up @@ -164,6 +172,12 @@ func (r *Reconciler) generatePostgresUserSecret(
Path: database,
RawQuery: query.Encode(),
}).String())
intent.Data["pgbouncer-r2dbc-uri"] = []byte((&url.URL{
Scheme: "r2dbc:postgresql",
Host: net.JoinHostPort(hostname, port),
Path: database,
RawQuery: query.Encode(),
}).String())
}
}

Expand Down
12 changes: 11 additions & 1 deletion internal/controller/postgrescluster/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
`^jdbc:postgresql://hippo2-primary.ns1.svc:9999/db1`+
`[?]password=[^&]+&user=some-user-name$`,
string(secret.Data["jdbc-uri"])))
assert.Assert(t, cmp.Regexp(
`^r2dbc:postgresql://hippo2-primary.ns1.svc:9999/db1`+
`[?]password=[^&]+&user=some-user-name$`,
string(secret.Data["r2dbc-uri"])))
}

// Only the first in the list.
Expand All @@ -199,7 +203,9 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
assert.Assert(t, cmp.Regexp(
`^jdbc:postgresql://hippo2-primary.ns1.svc:9999/first[?].+$`,
string(secret.Data["jdbc-uri"])))

assert.Assert(t, cmp.Regexp(
`^r2dbc:postgresql://hippo2-primary.ns1.svc:9999/first[?].+$`,
string(secret.Data["r2dbc-uri"])))
}
})

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