Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce pgbouncer as a PostgreSQL proxy #16

Merged
merged 2 commits into from
Jul 3, 2024
Merged
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
11 changes: 9 additions & 2 deletions anvil-python/anvil/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@

MAAS_REGION_CHANNEL = "latest/edge"
MAAS_AGENT_CHANNEL = "latest/edge"
POSTGRESQL_CHANNEL = "14/stable"
POSTGRESQL_CHANNEL = "14/candidate"
PGBOUNCER_CHANNEL = "1/candidate"
HAPROXY_CHANNEL = "latest/stable"

MACHINE_CHARMS = {
"maas-region": MAAS_REGION_CHANNEL,
"maas-agent": MAAS_AGENT_CHANNEL,
"haproxy": HAPROXY_CHANNEL,
"postgresql": POSTGRESQL_CHANNEL,
"pgbouncer": PGBOUNCER_CHANNEL,
}
K8S_CHARMS: dict[str, str] = {}

Expand All @@ -43,7 +45,12 @@
"channel": "charm_maas_region_channel",
"revision": "charm_maas_region_revision",
"config": "charm_maas_region_config",
}
},
"pgbouncer": {
"channel": "charm_pgbouncer_channel",
"revision": "charm_pgbouncer_revision",
"config": "charm_pgbouncer_config",
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion cloud/etc/deploy-maas-agent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "juju_application" "maas-agent" {
config = var.charm_maas_agent_config
}

resource "juju_integration" "maas-region-postgresql" {
resource "juju_integration" "maas-agent-region" {
model = data.juju_model.machine_model.name

application {
Expand Down
36 changes: 34 additions & 2 deletions cloud/etc/deploy-maas-region/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,39 @@ resource "juju_application" "maas-region" {
config = var.charm_maas_region_config
}

resource "juju_integration" "maas-region-postgresql" {
resource "juju_application" "pgbouncer" {
name = "pgbouncer"
model = data.juju_model.machine_model.name
units = 0 # it is a subordinate charm

charm {
name = "pgbouncer"
channel = var.charm_pgbouncer_channel
revision = var.charm_pgbouncer_revision
base = "ubuntu@22.04"
}

config = merge({
pool_mode = "transaction"
max_db_connections = floor(90 / max(length(var.machine_ids), 1))
skatsaounis marked this conversation as resolved.
Show resolved Hide resolved
}, var.charm_pgbouncer_config)
}

resource "juju_integration" "postgresql-pgbouncer" {
model = data.juju_model.machine_model.name

application {
name = "postgresql"
endpoint = "database"
}

application {
name = juju_application.pgbouncer.name
endpoint = "backend-database"
}
}

resource "juju_integration" "maas-region-pgbouncer" {
model = data.juju_model.machine_model.name

application {
Expand All @@ -54,7 +86,7 @@ resource "juju_integration" "maas-region-postgresql" {
}

application {
name = "postgresql"
name = juju_application.pgbouncer.name
endpoint = "database"
}
}
Expand Down
18 changes: 18 additions & 0 deletions cloud/etc/deploy-maas-region/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,21 @@ variable "enable_haproxy" {
type = bool
default = false
}

variable "charm_pgbouncer_channel" {
description = "Operator channel for PgBouncer deployment"
type = string
default = "1/candidate"
}

variable "charm_pgbouncer_revision" {
description = "Operator channel revision for PgBouncer deployment"
type = number
default = null
}

variable "charm_pgbouncer_config" {
description = "Operator config for PgBouncer deployment"
type = map(string)
default = {}
}