Skip to content

Commit 5bbc382

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

File tree

15 files changed

+398
-169
lines changed

15 files changed

+398
-169
lines changed

bootstrap/cell/main.tf

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ 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" {
4547
source = "../postgres"
4648

49+
for_each = var.enable_postgres ? { "enabled" = true } : {}
4750
namespace = var.namespace
4851
db_volume_claim = local.db_volume_claim
4952
instance_name = local.postgres_host
@@ -53,11 +56,13 @@ module "dbsync_postgres" {
5356
postgres_secret_name = var.postgres_secret_name
5457
postgres_resources = var.postgres_resources
5558
is_blockfrost_backend = var.is_blockfrost_backend
59+
postgres_tolerations = var.postgres_tolerations
5660
}
5761

5862
module "dbsync_pgbouncer" {
5963
source = "../pgbouncer"
6064

65+
for_each = var.enable_pgbouncer ? { "enabled" = true } : {}
6166
namespace = var.namespace
6267
pg_bouncer_replicas = var.pgbouncer_replicas
6368
certs_secret_name = var.certs_secret_name
@@ -67,6 +72,7 @@ module "dbsync_pgbouncer" {
6772
instance_name = "postgres-dbsync-v3-${var.salt}"
6873
postgres_instance_name = local.postgres_host
6974
pgbouncer_reloader_image_tag = var.pgbouncer_reloader_image_tag
75+
pgbouncer_tolerations = var.pgbouncer_tolerations
7076
}
7177

7278
module "dbsync_instances" {
@@ -82,12 +88,10 @@ module "dbsync_instances" {
8288
release = each.value.release
8389
topology_zone = coalesce(each.value.topology_zone, var.topology_zone)
8490
sync_status = each.value.sync_status
85-
empty_args = coalesce(each.value.empty_args, false)
8691
custom_config = coalesce(each.value.custom_config, true)
87-
network_env_var = coalesce(each.value.network_env_var, false)
8892
enable_postgrest = each.value.enable_postgrest
8993
postgres_database = "dbsync-${each.value.network}"
90-
postgres_instance_name = local.postgres_host
94+
postgres_instance_name = coalesce(each.value.postgres_instance_name, local.postgres_host)
9195
postgres_secret_name = var.postgres_secret_name
9296

9397
dbsync_resources = coalesce(each.value.dbsync_resources, {

bootstrap/cell/variables.tf

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ variable "salt" {
77
description = "Salt used to identify all components as part of the cell. Should be unique between cells."
88
}
99

10-
variable "certs_secret_name" {
11-
type = string
12-
default = "pgbouncer-certs"
13-
}
14-
1510
// PVC
1611
variable "volume_name" {
1712
type = string
@@ -21,6 +16,14 @@ variable "storage_size" {
2116
type = string
2217
}
2318

19+
variable "storage_class_name" {
20+
type = string
21+
}
22+
23+
variable "access_mode" {
24+
type = string
25+
}
26+
2427
variable "db_volume_claim" {
2528
type = string
2629
default = null
@@ -66,11 +69,54 @@ variable "postgres_config_name" {
6669
default = null
6770
}
6871

72+
variable "postgres_tolerations" {
73+
type = list(object({
74+
key = string
75+
operator = string
76+
value = string
77+
effect = string
78+
}))
79+
default = [
80+
{
81+
key = "demeter.run/compute-profile"
82+
operator = "Equal"
83+
value = "disk-intensive"
84+
effect = "NoSchedule"
85+
},
86+
{
87+
key = "demeter.run/compute-arch"
88+
operator = "Equal"
89+
value = "x86"
90+
effect = "NoSchedule"
91+
},
92+
{
93+
key = "demeter.run/availability-sla"
94+
operator = "Equal"
95+
value = "consistent"
96+
effect = "NoSchedule"
97+
}
98+
]
99+
}
100+
69101
// PGBouncer
102+
103+
variable "certs_secret_name" {
104+
type = string
105+
default = "pgbouncer-certs"
106+
}
107+
108+
variable "pgbouncer_cloud_provider" {
109+
type = string
110+
}
111+
70112
variable "pgbouncer_image_tag" {
71113
default = "1.21.0"
72114
}
73115

116+
variable "pgbouncer_load_balancer" {
117+
type = bool
118+
}
119+
74120
variable "pgbouncer_replicas" {
75121
default = 1
76122
}
@@ -83,21 +129,49 @@ variable "pgbouncer_reloader_image_tag" {
83129
type = string
84130
}
85131

132+
variable "pgbouncer_tolerations" {
133+
type = list(object({
134+
effect = string
135+
key = string
136+
operator = string
137+
value = optional(string)
138+
}))
139+
default = [
140+
{
141+
effect = "NoSchedule"
142+
key = "demeter.run/compute-profile"
143+
operator = "Exists"
144+
},
145+
{
146+
effect = "NoSchedule"
147+
key = "demeter.run/compute-arch"
148+
operator = "Equal"
149+
value = "x86"
150+
},
151+
{
152+
effect = "NoSchedule"
153+
key = "demeter.run/availability-sla"
154+
operator = "Equal"
155+
value = "best-effort"
156+
}
157+
]
158+
}
159+
86160
// Instance
87161
variable "instances" {
88162
type = map(object({
89-
salt = optional(string)
90-
network = string
91-
dbsync_image = optional(string)
92-
dbsync_image_tag = string
93-
node_n2n_tcp_endpoint = string
94-
release = string
95-
sync_status = string
96-
enable_postgrest = bool
97-
topology_zone = optional(string)
98-
empty_args = optional(bool, false)
99-
custom_config = optional(bool, true)
100-
network_env_var = optional(string, false)
163+
salt = optional(string)
164+
network = string
165+
dbsync_image = optional(string)
166+
dbsync_image_tag = string
167+
node_n2n_tcp_endpoint = string
168+
release = string
169+
sync_status = string
170+
enable_postgrest = bool
171+
args = optional(list(string), [])
172+
custom_config = optional(bool, true)
173+
topology_zone = optional(string)
174+
postgres_instance_name = optional(string)
101175
dbsync_resources = optional(object({
102176
requests = map(string)
103177
limits = map(string)
@@ -115,3 +189,12 @@ variable "instances" {
115189
}))
116190
}
117191

192+
variable "enable_postgres" {
193+
type = bool
194+
default = true
195+
}
196+
197+
variable "enable_pgbouncer" {
198+
type = bool
199+
default = true
200+
}

bootstrap/configs/preview/config.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"AlonzoGenesisFile": "/genesis/preview/alonzo-genesis.json",
2+
"AlonzoGenesisFile": "/opt/cardano/config/preview/alonzo-genesis.json",
33
"AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874",
44
"ApplicationName": "cardano-sl",
55
"ApplicationVersion": 0,
6-
"ByronGenesisFile": "/genesis/preview/byron-genesis.json",
6+
"ByronGenesisFile": "/opt/cardano/config/preview/byron-genesis.json",
77
"ByronGenesisHash": "83de1d7302569ad56cf9139a41e2e11346d4cb4a31c00142557b6ab3fa550761",
8-
"ConwayGenesisFile": "/genesis/preview/conway-genesis.json",
9-
"ConwayGenesisHash": "f28f1c1280ea0d32f8cd3143e268650d6c1a8e221522ce4a7d20d62fc09783e1",
8+
"ConwayGenesisFile": "/opt/cardano/config/preview/conway-genesis.json",
9+
"ConwayGenesisHash": "9cc5084f02e27210eacba47af0872e3dba8946ad9460b6072d793e1d2f3987ef",
1010
"EnableP2P": true,
1111
"ExperimentalHardForksEnabled": false,
1212
"ExperimentalProtocolsEnabled": false,
@@ -15,7 +15,7 @@
1515
"LastKnownBlockVersion-Minor": 1,
1616
"Protocol": "Cardano",
1717
"RequiresNetworkMagic": "RequiresMagic",
18-
"ShelleyGenesisFile": "/genesis/preview/shelley-genesis.json",
18+
"ShelleyGenesisFile": "/opt/cardano/config/preview/shelley-genesis.json",
1919
"ShelleyGenesisHash": "363498d1024f84bb39d3fa9593ce391483cb40d479b87233f868d6e57c3a400d",
2020
"TargetNumberOfActivePeers": 20,
2121
"TargetNumberOfEstablishedPeers": 50,
@@ -110,4 +110,4 @@
110110
"scRotation": null
111111
}
112112
]
113-
}
113+
}

bootstrap/instance/dbsync.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ resource "kubernetes_deployment_v1" "db_sync" {
152152
requests = var.dbsync_resources.requests
153153
}
154154

155-
args = var.empty_args ? [] : [
156-
"--config /etc/dbsync/db-sync-config.json",
157-
"--socket-path /node-ipc/node.socket",
158-
]
155+
args = var.args
159156

160157
env {
161158
name = "POSTGRES_USER"
@@ -194,7 +191,7 @@ resource "kubernetes_deployment_v1" "db_sync" {
194191

195192
env {
196193
name = "NETWORK"
197-
value = var.network_env_var ? var.network : ""
194+
value = var.network
198195
}
199196

200197
dynamic "env" {

bootstrap/instance/main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ terraform {
88

99
variable "namespace" {}
1010

11-
1211
variable "dbsync_image" {
1312
type = string
1413
default = "ghcr.io/demeter-run/dbsync"
@@ -17,7 +16,9 @@ variable "dbsync_image_tag" {
1716
default = "132ffd0007054bfadd17b23ed608529447833b99"
1817
}
1918

20-
variable "network" {}
19+
variable "network" {
20+
type = string
21+
}
2122

2223
variable "salt" {
2324
type = string
@@ -101,18 +102,15 @@ variable "availability_sla" {
101102
default = "consistent"
102103
}
103104

104-
variable "empty_args" {
105-
default = false
105+
variable "args" {
106+
type = list(string)
107+
default = []
106108
}
107109

108110
variable "custom_config" {
109111
default = true
110112
}
111113

112-
variable "network_env_var" {
113-
default = false
114-
}
115-
116114
variable "tolerations" {
117115
type = list(object({
118116
effect = string

bootstrap/main.tf

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
resource "kubernetes_namespace" "namespace" {
2+
for_each = var.enable_postgres ? { "enabled" = true } : {}
23
metadata {
34
name = var.namespace
45
}
@@ -8,6 +9,7 @@ resource "kubernetes_namespace" "namespace" {
89
module "dbsync_feature" {
910
depends_on = [kubernetes_namespace.namespace]
1011
source = "./feature"
12+
for_each = var.enable_postgres ? { "enabled" = true } : {}
1113

1214
namespace = var.namespace
1315
operator_image_tag = var.operator_image_tag
@@ -23,10 +25,10 @@ module "dbsync_feature" {
2325

2426
// Service
2527
module "dbsync_service" {
26-
depends_on = [kubernetes_namespace.namespace]
27-
source = "./service"
28-
29-
namespace = var.namespace
28+
depends_on = [kubernetes_namespace.namespace]
29+
source = "./service"
30+
cloud_provider = var.cloud_provider
31+
namespace = var.namespace
3032
}
3133

3234
// Cells
@@ -35,27 +37,36 @@ module "dbsync_cells" {
3537
for_each = var.cells
3638
source = "./cell"
3739

38-
namespace = var.namespace
39-
salt = each.key
40+
namespace = var.namespace
41+
salt = each.key
42+
enable_postgres = var.enable_postgres
43+
enable_pgbouncer = var.enable_pgbouncer
4044

4145
// 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
45-
46-
// PG
47-
topology_zone = each.value.postgres.topology_zone
48-
is_blockfrost_backend = each.value.postgres.is_blockfrost_backend
49-
postgres_image_tag = each.value.postgres.image_tag
50-
postgres_secret_name = var.postgres_secret_name
51-
postgres_resources = each.value.postgres.resources
52-
postgres_config_name = each.value.postgres.config_name
53-
54-
// PGBouncer
55-
pgbouncer_image_tag = var.pgbouncer_image_tag
56-
pgbouncer_replicas = each.value.pgbouncer.replicas
57-
pgbouncer_auth_user_password = var.pgbouncer_auth_user_password
58-
pgbouncer_reloader_image_tag = var.pgbouncer_reloader_image_tag
46+
access_mode = each.value.pvc.access_mode
47+
db_volume_claim = each.value.pvc.name
48+
storage_class_name = each.value.pvc.storage_class_name
49+
storage_size = each.value.pvc.storage_size
50+
volume_name = each.value.pvc.volume_name
51+
52+
// PG: conditionally defined if each cell has a postgres key
53+
topology_zone = each.value.postgres != null ? each.value.postgres.topology_zone : null
54+
is_blockfrost_backend = each.value.postgres != null ? each.value.postgres.is_blockfrost_backend : null
55+
postgres_image_tag = each.value.postgres != null ? each.value.postgres.image_tag : null
56+
postgres_secret_name = each.value.postgres != null ? var.postgres_secret_name : null
57+
postgres_resources = each.value.postgres != null ? each.value.postgres.resources : null
58+
postgres_config_name = each.value.postgres != null ? each.value.postgres.config_name : null
59+
postgres_tolerations = each.value.postgres != null ? each.value.postgres.tolerations : null
60+
61+
// PGBouncer: conditionally defined if each cell has a pgbouncer key
62+
certs_secret_name = each.value.pgbouncer != null ? each.value.pgbouncer.certs_secret_name : null
63+
pgbouncer_cloud_provider = each.value.pgbouncer != null ? var.cloud_provider : null
64+
pgbouncer_image_tag = each.value.pgbouncer != null ? var.pgbouncer_image_tag : null
65+
pgbouncer_load_balancer = each.value.pgbouncer != null ? each.value.pgbouncer.load_balancer : null
66+
pgbouncer_replicas = each.value.pgbouncer != null ? each.value.pgbouncer.replicas : null
67+
pgbouncer_auth_user_password = each.value.pgbouncer != null ? var.pgbouncer_auth_user_password : null
68+
pgbouncer_reloader_image_tag = each.value.pgbouncer != null ? var.pgbouncer_reloader_image_tag : null
69+
pgbouncer_tolerations = each.value.pgbouncer != null ? each.value.pgbouncer.tolerations : null
5970

6071
// Instances
6172
instances = each.value.instances

0 commit comments

Comments
 (0)