Skip to content

Commit

Permalink
feat: introduce pgbouncer as a PostgreSQL proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
skatsaounis committed Jul 2, 2024
1 parent 81bb7a0 commit b3ef176
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
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 / length(var.machine_ids))
}, 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 = {}
}

0 comments on commit b3ef176

Please sign in to comment.