Skip to content

Commit d7efd7e

Browse files
authored
chore: bootstrap (#15)
1 parent 0dfc395 commit d7efd7e

File tree

13 files changed

+565
-131
lines changed

13 files changed

+565
-131
lines changed

bootstrap/feature/main.tf

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,74 @@ variable "topology_zone" {
1414
type = string
1515
}
1616

17-
variable "image_tag" {
17+
variable "postgres_image_tag" {
18+
type = string
19+
}
20+
21+
variable "postgres_resources" {
22+
type = object({
23+
requests = map(string)
24+
limits = map(string)
25+
})
26+
27+
default = {
28+
"limits" = {
29+
memory = "2Gi"
30+
cpu = "4000m"
31+
}
32+
"requests" = {
33+
memory = "2Gi"
34+
cpu = "100m"
35+
}
36+
}
37+
}
38+
39+
variable "postgres_settings" {
40+
default = {
41+
listen_addresses = "*"
42+
max_connections = 1000
43+
shared_buffers = "8GB"
44+
effective_cache_size = "24GB"
45+
maintenance_work_mem = "2GB"
46+
checkpoint_completion_target = 0.9
47+
wal_buffers = "16MB"
48+
default_statistics_target = 500
49+
random_page_cost = 1.1
50+
effective_io_concurrency = 200
51+
work_mem = "1048kB"
52+
huge_pages = "try"
53+
min_wal_size = "4GB"
54+
max_wal_size = "16GB"
55+
max_worker_processes = 8
56+
max_parallel_workers_per_gather = 4
57+
max_parallel_workers = 8
58+
max_parallel_maintenance_workers = 4
59+
ssl = "off"
60+
}
61+
}
62+
63+
64+
variable "operator_image_tag" {
65+
type = string
66+
}
67+
68+
variable "metrics_delay" {
69+
default = 30
70+
}
71+
72+
variable "dcu_per_second" {
73+
type = map(string)
74+
default = {
75+
"mainnet" = "10"
76+
"preprod" = "5"
77+
"preview" = "5"
78+
}
79+
}
80+
81+
variable "postgres_host" {
82+
type = string
83+
}
84+
85+
variable "postgres_secret_name" {
1886
type = string
1987
}

bootstrap/feature/monitor.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,31 @@ resource "kubernetes_manifest" "postgres_podmonitor" {
2525
}
2626
}
2727
}
28+
29+
resource "kubernetes_manifest" "operator_monitor" {
30+
manifest = {
31+
apiVersion = "monitoring.coreos.com/v1"
32+
kind = "PodMonitor"
33+
metadata = {
34+
labels = {
35+
"app.kubernetes.io/component" = "o11y"
36+
"app.kubernetes.io/part-of" = "demeter"
37+
}
38+
name = "operator"
39+
namespace = var.namespace
40+
}
41+
spec = {
42+
selector = {
43+
matchLabels = {
44+
role = "operator"
45+
}
46+
}
47+
podMetricsEndpoints = [
48+
{
49+
port = "metrics",
50+
path = "/metrics"
51+
}
52+
]
53+
}
54+
}
55+
}

bootstrap/feature/operator.tf

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
resource "kubernetes_deployment_v1" "operator" {
2+
wait_for_rollout = false
3+
4+
metadata {
5+
namespace = var.namespace
6+
name = "operator"
7+
labels = {
8+
role = "operator"
9+
}
10+
}
11+
12+
spec {
13+
replicas = 1
14+
15+
selector {
16+
match_labels = {
17+
role = "operator"
18+
}
19+
}
20+
21+
template {
22+
metadata {
23+
labels = {
24+
role = "operator"
25+
}
26+
}
27+
28+
spec {
29+
container {
30+
image = "ghcr.io/demeter-run/ext-cardano-dbsync-serverless:${var.operator_image_tag}"
31+
name = "main"
32+
33+
env {
34+
name = "K8S_IN_CLUSTER"
35+
value = "true"
36+
}
37+
38+
env {
39+
name = "METRICS_DELAY"
40+
value = var.metrics_delay
41+
}
42+
43+
env {
44+
name = "DCU_PER_SECOND_MAINNET"
45+
value = var.dcu_per_second["mainnet"]
46+
}
47+
48+
env {
49+
name = "DCU_PER_SECOND_PREPROD"
50+
value = var.dcu_per_second["preprod"]
51+
}
52+
53+
env {
54+
name = "DCU_PER_SECOND_PREVIEW"
55+
value = var.dcu_per_second["preview"]
56+
}
57+
58+
env {
59+
name = "ADDR"
60+
value = "0.0.0.0:5000"
61+
}
62+
63+
env {
64+
name = "POSTGRES_PASSWORD"
65+
value_from {
66+
secret_key_ref {
67+
name = var.postgres_secret_name
68+
key = "password"
69+
}
70+
}
71+
}
72+
73+
env {
74+
name = "DB_URL_MAINNET"
75+
value = "postgres://postgres:$(POSTGRES_PASSWORD)@${var.postgres_host}:5432/dbsync-mainnet"
76+
}
77+
78+
env {
79+
name = "DB_URL_PREPROD"
80+
value = "postgres://postgres:$(POSTGRES_PASSWORD)@${var.postgres_host}:5432/dbsync-preprod"
81+
}
82+
83+
env {
84+
name = "DB_URL_PREVIEW"
85+
value = "postgres://postgres:$(POSTGRES_PASSWORD)@${var.postgres_host}:5432/dbsync-preview"
86+
}
87+
88+
env {
89+
name = "RUST_BACKTRACE"
90+
value = "1"
91+
}
92+
93+
94+
resources {
95+
limits = {
96+
memory = "256Mi"
97+
}
98+
requests = {
99+
cpu = "50m"
100+
memory = "256Mi"
101+
}
102+
}
103+
104+
port {
105+
name = "metrics"
106+
container_port = 5000
107+
protocol = "TCP"
108+
}
109+
}
110+
111+
toleration {
112+
effect = "NoSchedule"
113+
key = "demeter.run/compute-profile"
114+
operator = "Equal"
115+
value = "general-purpose"
116+
}
117+
118+
toleration {
119+
effect = "NoSchedule"
120+
key = "demeter.run/compute-arch"
121+
operator = "Equal"
122+
value = "x86"
123+
}
124+
125+
toleration {
126+
effect = "NoSchedule"
127+
key = "demeter.run/availability-sla"
128+
operator = "Equal"
129+
value = "consistent"
130+
}
131+
}
132+
}
133+
}
134+
}
135+

bootstrap/feature/pg-configs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "kubernetes_config_map" "postgres_config" {
2+
metadata {
3+
namespace = var.namespace
4+
name = "postgres-config"
5+
}
6+
7+
data = {
8+
"postgresql.conf" = file("${path.module}/postgresql.conf")
9+
}
10+
}

0 commit comments

Comments
 (0)