Skip to content

Commit b94b487

Browse files
committed
feat: add support for customization
Signed-off-by: Ales Verbic <[email protected]>
1 parent 89743f8 commit b94b487

File tree

10 files changed

+239
-61
lines changed

10 files changed

+239
-61
lines changed

bootstrap/cell/main.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ locals {
3434
]
3535
}
3636
module "dbsync_pvc" {
37-
source = "../pvc"
38-
namespace = var.namespace
39-
volume_name = var.volume_name
40-
storage_size = var.storage_size
41-
name = local.db_volume_claim
37+
source = "../pvc"
38+
namespace = var.namespace
39+
access_mode = var.access_mode
40+
volume_name = var.volume_name
41+
storage_class_name = var.storage_class_name
42+
storage_size = var.storage_size
43+
name = local.db_volume_claim
4244
}
4345

4446
module "dbsync_postgres" {
@@ -53,6 +55,7 @@ module "dbsync_postgres" {
5355
postgres_secret_name = var.postgres_secret_name
5456
postgres_resources = var.postgres_resources
5557
is_blockfrost_backend = var.is_blockfrost_backend
58+
postgres_tolerations = var.postgres_tolerations
5659
}
5760

5861
module "dbsync_pgbouncer" {
@@ -67,6 +70,7 @@ module "dbsync_pgbouncer" {
6770
instance_name = "postgres-dbsync-v3-${var.salt}"
6871
postgres_instance_name = local.postgres_host
6972
pgbouncer_reloader_image_tag = var.pgbouncer_reloader_image_tag
73+
pgbouncer_tolerations = var.pgbouncer_tolerations
7074
}
7175

7276
module "dbsync_instances" {

bootstrap/cell/variables.tf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ variable "storage_size" {
2121
type = string
2222
}
2323

24+
variable "storage_class_name" {
25+
type = string
26+
}
27+
28+
variable "access_mode" {
29+
type = string
30+
}
31+
2432
variable "db_volume_claim" {
2533
type = string
2634
default = null
@@ -66,6 +74,35 @@ variable "postgres_config_name" {
6674
default = null
6775
}
6876

77+
variable "postgres_tolerations" {
78+
type = list(object({
79+
key = string
80+
operator = string
81+
value = string
82+
effect = string
83+
}))
84+
default = [
85+
{
86+
key = "demeter.run/compute-profile"
87+
operator = "Equal"
88+
value = "disk-intensive"
89+
effect = "NoSchedule"
90+
},
91+
{
92+
key = "demeter.run/compute-arch"
93+
operator = "Equal"
94+
value = "x86"
95+
effect = "NoSchedule"
96+
},
97+
{
98+
key = "demeter.run/availability-sla"
99+
operator = "Equal"
100+
value = "consistent"
101+
effect = "NoSchedule"
102+
}
103+
]
104+
}
105+
69106
// PGBouncer
70107
variable "pgbouncer_image_tag" {
71108
default = "1.21.0"
@@ -83,6 +120,39 @@ variable "pgbouncer_reloader_image_tag" {
83120
type = string
84121
}
85122

123+
variable "pgbouncer_secret_name" {
124+
type = string
125+
default = ""
126+
}
127+
128+
variable "pgbouncer_tolerations" {
129+
type = list(object({
130+
effect = string
131+
key = string
132+
operator = string
133+
value = optional(string)
134+
}))
135+
default = [
136+
{
137+
effect = "NoSchedule"
138+
key = "demeter.run/compute-profile"
139+
operator = "Exists"
140+
},
141+
{
142+
effect = "NoSchedule"
143+
key = "demeter.run/compute-arch"
144+
operator = "Equal"
145+
value = "x86"
146+
},
147+
{
148+
effect = "NoSchedule"
149+
key = "demeter.run/availability-sla"
150+
operator = "Equal"
151+
value = "best-effort"
152+
}
153+
]
154+
}
155+
86156
// Instance
87157
variable "instances" {
88158
type = map(object({

bootstrap/main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ module "dbsync_cells" {
3939
salt = each.key
4040

4141
// PVC
42-
volume_name = each.value.pvc.volume_name
43-
storage_size = each.value.pvc.storage_size
44-
db_volume_claim = each.value.pvc.name
42+
access_mode = each.value.pvc.access_mode
43+
db_volume_claim = each.value.pvc.name
44+
storage_class_name = each.value.pvc.storage_class_name
45+
storage_size = each.value.pvc.storage_size
46+
volume_name = each.value.pvc.volume_name
4547

4648
// PG
4749
topology_zone = each.value.postgres.topology_zone
@@ -50,12 +52,15 @@ module "dbsync_cells" {
5052
postgres_secret_name = var.postgres_secret_name
5153
postgres_resources = each.value.postgres.resources
5254
postgres_config_name = each.value.postgres.config_name
55+
postgres_tolerations = each.value.postgres.tolerations
5356

5457
// PGBouncer
5558
pgbouncer_image_tag = var.pgbouncer_image_tag
5659
pgbouncer_replicas = each.value.pgbouncer.replicas
5760
pgbouncer_auth_user_password = var.pgbouncer_auth_user_password
5861
pgbouncer_reloader_image_tag = var.pgbouncer_reloader_image_tag
62+
pgbouncer_secret_name = var.postgres_secret_name
63+
pgbouncer_tolerations = each.value.pgbouncer.tolerations
5964

6065
// Instances
6166
instances = each.value.instances

bootstrap/pgbouncer/main.tf

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ variable "instance_name" {
66
default = "dbsync-v3-pgbouncer"
77
}
88

9+
variable "cloud_provider" {
10+
default = "gcp"
11+
}
12+
913
variable "service_name" {
1014
default = "dbsync-v3-pgbouncer"
1115
}
@@ -55,8 +59,8 @@ variable "postgres_instance_name" {
5559
default = "postgres-dbsync-v3-ar9"
5660
}
5761

58-
resource "kubernetes_service_v1" "dbsync_pgbouncer_elb" {
59-
count = var.load_balancer ? 1 : 0
62+
resource "kubernetes_service_v1" "dbsync_pgbouncer_elb_aws" {
63+
for_each = var.load_balancer && var.cloud_provider == "aws" ? toset(["loadbalancer"]) : toset([])
6064
metadata {
6165
namespace = var.namespace
6266
name = var.service_name
@@ -82,3 +86,57 @@ resource "kubernetes_service_v1" "dbsync_pgbouncer_elb" {
8286
}
8387
}
8488
}
89+
90+
resource "kubernetes_service_v1" "dbsync_pgbouncer_elb_gcp" {
91+
for_each = var.load_balancer && var.cloud_provider == "gcp" ? toset(["loadbalancer"]) : toset([])
92+
metadata {
93+
namespace = var.namespace
94+
name = var.service_name
95+
annotations = {
96+
"cloud.google.com/l4-rbs" : "enabled"
97+
}
98+
}
99+
100+
spec {
101+
type = "LoadBalancer"
102+
external_traffic_policy = "Local"
103+
104+
port {
105+
protocol = "TCP"
106+
port = 5432
107+
target_port = 6432
108+
}
109+
110+
selector = {
111+
"role" = var.instance_role
112+
}
113+
}
114+
}
115+
116+
variable "pgbouncer_tolerations" {
117+
type = list(object({
118+
effect = string
119+
key = string
120+
operator = string
121+
value = optional(string)
122+
}))
123+
default = [
124+
{
125+
effect = "NoSchedule"
126+
key = "demeter.run/compute-profile"
127+
operator = "Exists"
128+
},
129+
{
130+
effect = "NoSchedule"
131+
key = "demeter.run/compute-arch"
132+
operator = "Equal"
133+
value = "x86"
134+
},
135+
{
136+
effect = "NoSchedule"
137+
key = "demeter.run/availability-sla"
138+
operator = "Equal"
139+
value = "best-effort"
140+
}
141+
]
142+
}

bootstrap/pgbouncer/pg-bouncer.tf

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ resource "kubernetes_deployment_v1" "pgbouncer" {
7474
name = "POSTGRESQL_PASSWORD"
7575
value_from {
7676
secret_key_ref {
77-
name = "postgres.postgres-dbsync-v3"
77+
name = var.postgres_secret_name
7878
key = "password"
7979
}
8080
}
@@ -281,24 +281,15 @@ resource "kubernetes_deployment_v1" "pgbouncer" {
281281
}
282282
}
283283

284-
toleration {
285-
effect = "NoSchedule"
286-
key = "demeter.run/compute-profile"
287-
operator = "Exists"
288-
}
284+
dynamic "toleration" {
285+
for_each = var.pgbouncer_tolerations
289286

290-
toleration {
291-
effect = "NoSchedule"
292-
key = "demeter.run/compute-arch"
293-
operator = "Equal"
294-
value = "x86"
295-
}
296-
297-
toleration {
298-
effect = "NoSchedule"
299-
key = "demeter.run/availability-sla"
300-
operator = "Equal"
301-
value = "best-effort"
287+
content {
288+
effect = toleration.value.effect
289+
key = toleration.value.key
290+
operator = toleration.value.operator
291+
value = toleration.value.value
292+
}
302293
}
303294
}
304295
}

bootstrap/pgbouncer/pgbouncer.ini.tftpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ auth_query=SELECT usename, passwd FROM user_search($1)
1616
pidfile=/opt/bitnami/pgbouncer/tmp/pgbouncer.pid
1717
logfile=/opt/bitnami/pgbouncer/logs/pgbouncer.log
1818
admin_users=postgres
19-
client_tls_sslmode=allow
20-
client_tls_key_file=/certs/tls.key
21-
client_tls_cert_file=/certs/tls.crt
19+
client_tls_sslmode=disable
20+
client_tls_key_file=/certs/server.key
21+
client_tls_cert_file=/certs/server.crt
2222
server_tls_sslmode=disable
2323
ignore_startup_parameters=extra_float_digits,statement_timeout
2424
stats_period=60

bootstrap/postgres/main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,32 @@ variable "postgres_settings" {
7474
}
7575
}
7676

77+
variable "postgres_tolerations" {
78+
type = list(object({
79+
key = string
80+
operator = string
81+
value = string
82+
effect = string
83+
}))
84+
default = [
85+
{
86+
key = "demeter.run/compute-profile"
87+
operator = "Equal"
88+
value = "disk-intensive"
89+
effect = "NoSchedule"
90+
},
91+
{
92+
key = "demeter.run/compute-arch"
93+
operator = "Equal"
94+
value = "x86"
95+
effect = "NoSchedule"
96+
},
97+
{
98+
key = "demeter.run/availability-sla"
99+
operator = "Equal"
100+
value = "consistent"
101+
effect = "NoSchedule"
102+
}
103+
]
104+
}
105+

bootstrap/postgres/postgres.tf

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,14 @@ resource "kubernetes_stateful_set_v1" "postgres" {
149149
}
150150
}
151151

152-
toleration {
153-
effect = "NoSchedule"
154-
key = "demeter.run/compute-profile"
155-
operator = "Equal"
156-
value = "disk-intensive"
157-
}
158-
159-
toleration {
160-
effect = "NoSchedule"
161-
key = "demeter.run/compute-arch"
162-
operator = "Equal"
163-
value = "x86"
164-
}
165-
166-
toleration {
167-
effect = "NoSchedule"
168-
key = "demeter.run/availability-sla"
169-
operator = "Equal"
170-
value = "consistent"
152+
dynamic "toleration" {
153+
for_each = var.postgres_tolerations
154+
content {
155+
effect = toleration.value.effect
156+
key = toleration.value.key
157+
operator = toleration.value.operator
158+
value = toleration.value.value
159+
}
171160
}
172161
}
173162
}

0 commit comments

Comments
 (0)