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 Jun 27, 2024
1 parent 81bb7a0 commit 877b876
Show file tree
Hide file tree
Showing 5 changed files with 59 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/edge"
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 Down Expand Up @@ -73,7 +75,12 @@
"channel": "charm_postgresql_channel",
"revision": "charm_postgresql_revision",
"config": "charm_postgresql_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
4 changes: 2 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,7 @@ resource "juju_application" "maas-region" {
config = var.charm_maas_region_config
}

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

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

application {
name = "postgresql"
name = "pgbouncer"
endpoint = "database"
}
}
Expand Down
29 changes: 29 additions & 0 deletions cloud/etc/deploy-postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,32 @@ resource "juju_application" "postgresql" {

config = var.charm_postgresql_config
}

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 = var.charm_pgbouncer_config
}

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

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

application {
name = juju_application.pgbouncer.name
endpoint = "backend-database"
}
}
18 changes: 18 additions & 0 deletions cloud/etc/deploy-postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ variable "charm_postgresql_config" {
default = {}
}

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

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 = {}
}

variable "machine_ids" {
description = "List of machine ids to include"
type = list(string)
Expand Down

0 comments on commit 877b876

Please sign in to comment.