Skip to content

Commit 164d006

Browse files
committed
feat: add support for customization
Signed-off-by: Ales Verbic <[email protected]>
1 parent 97744dc commit 164d006

File tree

10 files changed

+210
-59
lines changed

10 files changed

+210
-59
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,31 @@ resource "kubernetes_service_v1" "dbsync_pgbouncer_elb" {
8282
}
8383
}
8484
}
85+
86+
variable "pgbouncer_tolerations" {
87+
type = list(object({
88+
effect = string
89+
key = string
90+
operator = string
91+
value = optional(string)
92+
}))
93+
default = [
94+
{
95+
effect = "NoSchedule"
96+
key = "demeter.run/compute-profile"
97+
operator = "Exists"
98+
},
99+
{
100+
effect = "NoSchedule"
101+
key = "demeter.run/compute-arch"
102+
operator = "Equal"
103+
value = "x86"
104+
},
105+
{
106+
effect = "NoSchedule"
107+
key = "demeter.run/availability-sla"
108+
operator = "Equal"
109+
value = "best-effort"
110+
}
111+
]
112+
}

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ 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/server.key
21-
client_tls_cert_file=/certs/server.crt
19+
# Disable client TLS entirely:
20+
# client_tls_sslmode=allow
21+
client_tls_sslmode=disable
22+
# Remove TLS files if not needed:
23+
# client_tls_key_file=/certs/server.key
24+
# client_tls_cert_file=/certs/server.crt
2225
server_tls_sslmode=disable
2326
ignore_startup_parameters=extra_float_digits,statement_timeout
2427
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
}

bootstrap/pvc/main.tf

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
variable "namespace" {
2-
description = "the namespace where the resources will be created"
2+
description = "The namespace where the resources will be created."
33
}
44

55
variable "volume_name" {
6-
description = "the name of the volume"
6+
description = "The name of the volume. If not specified, the volume will be dynamically provisioned."
7+
type = string
8+
default = null
79
}
810

911
variable "name" {
10-
description = "the name of the pvc"
12+
description = "The name of the PersistentVolumeClaim (PVC)."
1113
}
1214

1315
variable "storage_size" {
14-
description = "the size of the volume"
16+
description = "The size of the volume."
17+
}
18+
19+
variable "storage_class_name" {
20+
description = "The name of the storage class to use."
21+
default = "nvme"
22+
}
23+
24+
variable "access_mode" {
25+
description = "The access mode for the volume."
26+
type = string
27+
default = "ReadWriteMany"
1528
}
1629

1730
resource "kubernetes_persistent_volume_claim" "shared_disk" {
@@ -23,13 +36,15 @@ resource "kubernetes_persistent_volume_claim" "shared_disk" {
2336
}
2437

2538
spec {
26-
access_modes = ["ReadWriteMany"]
39+
access_modes = [var.access_mode]
40+
2741
resources {
2842
requests = {
2943
storage = var.storage_size
3044
}
3145
}
32-
storage_class_name = "nvme"
33-
volume_name = var.volume_name
46+
47+
storage_class_name = var.storage_class_name
48+
volume_name = var.volume_name != null ? var.volume_name : null
3449
}
3550
}

0 commit comments

Comments
 (0)