Skip to content

Commit

Permalink
feat: add support for customization
Browse files Browse the repository at this point in the history
Signed-off-by: Ales Verbic <[email protected]>
  • Loading branch information
verbotenj committed Feb 1, 2025
1 parent 97744dc commit 685689f
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 57 deletions.
14 changes: 9 additions & 5 deletions bootstrap/cell/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ locals {
]
}
module "dbsync_pvc" {
source = "../pvc"
namespace = var.namespace
volume_name = var.volume_name
storage_size = var.storage_size
name = local.db_volume_claim
source = "../pvc"
namespace = var.namespace
access_mode = var.access_mode
volume_name = var.volume_name
storage_class_name = var.storage_class_name
storage_size = var.storage_size
name = local.db_volume_claim
}

module "dbsync_postgres" {
Expand All @@ -53,6 +55,7 @@ module "dbsync_postgres" {
postgres_secret_name = var.postgres_secret_name
postgres_resources = var.postgres_resources
is_blockfrost_backend = var.is_blockfrost_backend
postgres_tolerations = var.postgres_tolerations
}

module "dbsync_pgbouncer" {
Expand All @@ -67,6 +70,7 @@ module "dbsync_pgbouncer" {
instance_name = "postgres-dbsync-v3-${var.salt}"
postgres_instance_name = local.postgres_host
pgbouncer_reloader_image_tag = var.pgbouncer_reloader_image_tag
pgbouncer_tolerations = var.pgbouncer_tolerations
}

module "dbsync_instances" {
Expand Down
65 changes: 65 additions & 0 deletions bootstrap/cell/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ variable "storage_size" {
type = string
}

variable "storage_class_name" {
type = string
}

variable "access_mode" {
type = string
}

variable "db_volume_claim" {
type = string
default = null
Expand Down Expand Up @@ -66,6 +74,35 @@ variable "postgres_config_name" {
default = null
}

variable "postgres_tolerations" {
type = list(object({
key = string
operator = string
value = string
effect = string
}))
default = [
{
key = "demeter.run/compute-profile"
operator = "Equal"
value = "disk-intensive"
effect = "NoSchedule"
},
{
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
effect = "NoSchedule"
},
{
key = "demeter.run/availability-sla"
operator = "Equal"
value = "consistent"
effect = "NoSchedule"
}
]
}

// PGBouncer
variable "pgbouncer_image_tag" {
default = "1.21.0"
Expand All @@ -83,6 +120,34 @@ variable "pgbouncer_reloader_image_tag" {
type = string
}

variable "pgbouncer_tolerations" {
type = list(object({
effect = string
key = string
operator = string
value = optional(string)
}))
default = [
{
effect = "NoSchedule"
key = "demeter.run/compute-profile"
operator = "Exists"
},
{
effect = "NoSchedule"
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
},
{
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = "best-effort"
}
]
}

// Instance
variable "instances" {
type = map(object({
Expand Down
9 changes: 6 additions & 3 deletions bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ module "dbsync_cells" {
salt = each.key

// PVC
volume_name = each.value.pvc.volume_name
storage_size = each.value.pvc.storage_size
db_volume_claim = each.value.pvc.name
access_mode = each.value.pvc.access_mode
db_volume_claim = each.value.pvc.name
storage_class_name = each.value.pvc.storage_class_name
storage_size = each.value.pvc.storage_size
volume_name = each.value.pvc.volume_name

// PG
topology_zone = each.value.postgres.topology_zone
Expand All @@ -56,6 +58,7 @@ module "dbsync_cells" {
pgbouncer_replicas = each.value.pgbouncer.replicas
pgbouncer_auth_user_password = var.pgbouncer_auth_user_password
pgbouncer_reloader_image_tag = var.pgbouncer_reloader_image_tag
pgbouncer_tolerations = each.value.pgbouncer.tolerations

// Instances
instances = each.value.instances
Expand Down
28 changes: 28 additions & 0 deletions bootstrap/pgbouncer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,31 @@ resource "kubernetes_service_v1" "dbsync_pgbouncer_elb" {
}
}
}

variable "pgbouncer_tolerations" {
type = list(object({
effect = string
key = string
operator = string
value = optional(string)
}))
default = [
{
effect = "NoSchedule"
key = "demeter.run/compute-profile"
operator = "Exists"
},
{
effect = "NoSchedule"
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
},
{
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = "best-effort"
}
]
}
25 changes: 8 additions & 17 deletions bootstrap/pgbouncer/pg-bouncer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,15 @@ resource "kubernetes_deployment_v1" "pgbouncer" {
}
}

toleration {
effect = "NoSchedule"
key = "demeter.run/compute-profile"
operator = "Exists"
}

toleration {
effect = "NoSchedule"
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
}
dynamic "toleration" {
for_each = var.pgbouncer_tolerations

toleration {
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = "best-effort"
content {
effect = toleration.value.effect
key = toleration.value.key
operator = toleration.value.operator
value = toleration.value.value
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions bootstrap/postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,32 @@ variable "postgres_settings" {
}
}

variable "postgres_tolerations" {
type = list(object({
key = string
operator = string
value = string
effect = string
}))
default = [
{
key = "demeter.run/compute-profile"
operator = "Equal"
value = "disk-intensive"
effect = "NoSchedule"
},
{
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
effect = "NoSchedule"
},
{
key = "demeter.run/availability-sla"
operator = "Equal"
value = "consistent"
effect = "NoSchedule"
}
]
}

27 changes: 8 additions & 19 deletions bootstrap/postgres/postgres.tf
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,14 @@ resource "kubernetes_stateful_set_v1" "postgres" {
}
}

toleration {
effect = "NoSchedule"
key = "demeter.run/compute-profile"
operator = "Equal"
value = "disk-intensive"
}

toleration {
effect = "NoSchedule"
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
}

toleration {
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = "consistent"
dynamic "toleration" {
for_each = var.postgres_tolerations
content {
effect = toleration.value.effect
key = toleration.value.key
operator = toleration.value.operator
value = toleration.value.value
}
}
}
}
Expand Down
29 changes: 22 additions & 7 deletions bootstrap/pvc/main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
variable "namespace" {
description = "the namespace where the resources will be created"
description = "The namespace where the resources will be created."
}

variable "volume_name" {
description = "the name of the volume"
description = "The name of the volume. If not specified, the volume will be dynamically provisioned."
type = string
default = null
}

variable "name" {
description = "the name of the pvc"
description = "The name of the PersistentVolumeClaim (PVC)."
}

variable "storage_size" {
description = "the size of the volume"
description = "The size of the volume."
}

variable "storage_class_name" {
description = "The name of the storage class to use."
default = "nvme"
}

variable "access_mode" {
description = "The access mode for the volume."
type = string
default = "ReadWriteMany"
}

resource "kubernetes_persistent_volume_claim" "shared_disk" {
Expand All @@ -23,13 +36,15 @@ resource "kubernetes_persistent_volume_claim" "shared_disk" {
}

spec {
access_modes = ["ReadWriteMany"]
access_modes = [var.access_mode]

resources {
requests = {
storage = var.storage_size
}
}
storage_class_name = "nvme"
volume_name = var.volume_name

storage_class_name = var.storage_class_name
volume_name = var.volume_name != null ? var.volume_name : null
}
}
29 changes: 23 additions & 6 deletions bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ variable "pgbouncer_auth_user_password" {
variable "cells" {
type = map(object({
pvc = object({
volume_name = string
storage_size = string
name = optional(string)
volume_name = string
storage_size = string
storage_class_name = string
access_mode = string
name = optional(string)
})
postgres = object({
image_tag = string
Expand All @@ -103,10 +105,25 @@ variable "cells" {
memory = string
})
})
tolerations = optional(list(object({
key = string
operator = string
value = string
effect = string
})))
})
pgbouncer = object({
replicas = number
})
pgbouncer = (object({
replicas = number
reloader_image_tag = optional(string)
auth_user_password = optional(string)
certs_configmap_name = optional(string)
tolerations = optional(list(object({
key = string
operator = string
value = string
effect = string
})))
}))
instances = map(object({
salt = optional(string)
network = string
Expand Down

0 comments on commit 685689f

Please sign in to comment.