Skip to content

Commit

Permalink
chore: Dynamic tolerations (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe authored Jan 8, 2025
1 parent 9e56210 commit f9985c3
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 58 deletions.
55 changes: 39 additions & 16 deletions bootstrap/cell/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ locals {
dbsync_image = "ghcr.io/demeter-run/dbsync"
db_volume_claim = coalesce(var.db_volume_claim, "pvc-${var.salt}")
postgres_config_name = coalesce(var.postgres_config_name, "postgres-config-${var.salt}")
default_tolerations = [
{
effect = "NoSchedule"
key = "demeter.run/workload"
operator = "Equal"
value = "mem-intensive"
},
{
effect = "NoSchedule"
key = "demeter.run/compute-profile"
operator = "Equal"
value = "mem-intensive"
},
{
effect = "NoSchedule"
key = "demeter.run/compute-arch"
operator = "Equal"
value = "arm64"
},
{
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = "consistent"
}
]
}
module "dbsync_pvc" {
source = "../pvc"
Expand Down Expand Up @@ -47,22 +73,18 @@ module "dbsync_instances" {
source = "../instance"
for_each = var.instances

namespace = var.namespace
network = each.value.network
salt = coalesce(each.value.salt, var.salt)
dbsync_image = coalesce(each.value.dbsync_image, local.dbsync_image)
dbsync_image_tag = each.value.dbsync_image_tag
node_n2n_tcp_endpoint = each.value.node_n2n_tcp_endpoint
release = each.value.release
topology_zone = coalesce(each.value.topology_zone, var.topology_zone)
sync_status = each.value.sync_status
compute_arch = coalesce(each.value.compute_arch, "arm64")
compute_profile = coalesce(each.value.compute_profile, "mem-intensive")
availability_sla = coalesce(each.value.availability_sla, "consistent")
empty_args = coalesce(each.value.empty_args, false)
custom_config = coalesce(each.value.custom_config, true)
network_env_var = coalesce(each.value.network_env_var, false)

namespace = var.namespace
network = each.value.network
salt = coalesce(each.value.salt, var.salt)
dbsync_image = coalesce(each.value.dbsync_image, local.dbsync_image)
dbsync_image_tag = each.value.dbsync_image_tag
node_n2n_tcp_endpoint = each.value.node_n2n_tcp_endpoint
release = each.value.release
topology_zone = coalesce(each.value.topology_zone, var.topology_zone)
sync_status = each.value.sync_status
empty_args = coalesce(each.value.empty_args, false)
custom_config = coalesce(each.value.custom_config, true)
network_env_var = coalesce(each.value.network_env_var, false)
enable_postgrest = each.value.enable_postgrest
postgres_database = "dbsync-${each.value.network}"
postgres_instance_name = local.postgres_host
Expand All @@ -82,4 +104,5 @@ module "dbsync_instances" {
storage_class = "fast"
size = "10Gi"
})
tolerations = coalesce(each.value.tolerations, local.default_tolerations)
}
9 changes: 6 additions & 3 deletions bootstrap/cell/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ variable "instances" {
release = string
sync_status = string
enable_postgrest = bool
availability_sla = optional(string)
compute_profile = optional(string)
compute_arch = optional(string)
topology_zone = optional(string)
empty_args = optional(bool, false)
custom_config = optional(bool, true)
Expand All @@ -109,6 +106,12 @@ variable "instances" {
storage_class = string
size = string
}))
tolerations = optional(list(object({
effect = string
key = string
operator = string
value = optional(string)
})))
}))
}

2 changes: 1 addition & 1 deletion bootstrap/configs/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
source = "hashicorp/kubernetes"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/configs/prime-testnet/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ByronGenesisHash": "acd3e7c4cc071ae176fa253e654f0dd4e759892b16e958d8bd3c393f5c6c66d2",
"ShelleyGenesisHash": "0b67b0cb16e973478888efb1c7f69fca8e80489369afed94624a588e94a94f2b",
"AlonzoGenesisHash": "0f715ff78fcab739c6cb2cc1073eb87d0ffe3514218bfa0337d416f6fbaf7886",
"ConwayGenesisHash": "d43d3f38e01848bddf67e66fe29fbd236aca252de58c7f2c1904c67107c17842",
"ConwayGenesisHash": "47d7c396e8a58db4ae61dfbc1d47f9e9b786defb1d5b1a76c850a436e9017aff",
"SocketPath": "db/node.socket",
"ApplicationName":"cardano-sl",
"ApplicationVersion":0,
Expand Down Expand Up @@ -108,4 +108,4 @@
"TraceLedgerPeers": true,
"TracePeerSelectionCounters": true,
"TracePeerStateActions": true
}
}
5 changes: 4 additions & 1 deletion bootstrap/configs/prime-testnet/db-sync-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
]
],
"minSeverity":"Info",
"insertOptions": {
"offchainPoolData": "enable"
},
"options":{
"cfokey":{
"value":"Release-1.0.0"
},
"mapBackends":{

},
"mapSeverity":{
"db-sync-node":"Info",
Expand Down
12 changes: 6 additions & 6 deletions bootstrap/configs/vector-testnet/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"AlonzoGenesisFile": "/genesis/alonzo-genesis.json",
"AlonzoGenesisFile": "/config/vector_testnet/alonzo-genesis.json",
"AlonzoGenesisHash": "694a30a4be097b10989dde200b273c52df0c4d2e2981cee3537bed7122302291",
"ByronGenesisFile": "/genesis/byron-genesis.json",
"ByronGenesisFile": "/config/vector_testnet/byron-genesis.json",
"ByronGenesisHash": "765ffc6574cd68ee743479e7cc2855d9f4066dda5d65fe56b9762e03d193ed0b",
"ConwayGenesisFile": "/genesis/conway-genesis.json",
"ConwayGenesisFile": "/config/vector_testnet/conway-genesis.json",
"ConwayGenesisHash": "2629ff28ff9539312851b626212dc45be41784c450ab396c0b1da40b2429b78e",
"EnableP2P": false,
"ExperimentalProtocolsEnabled": true,
Expand All @@ -12,7 +12,7 @@
"LastKnownBlockVersion-Minor": 0,
"Protocol": "Cardano",
"RequiresNetworkMagic": "RequiresMagic",
"ShelleyGenesisFile": "/genesis/shelley-genesis.json",
"ShelleyGenesisFile": "/config/vector_testnet/shelley-genesis.json",
"ShelleyGenesisHash": "8189bc6863f6ac448fca1e08c4e8ade54b05b7b0cfcd3b84a7932324ef782a98",
"TargetNumberOfActivePeers": 20,
"TargetNumberOfEstablishedPeers": 50,
Expand Down Expand Up @@ -74,7 +74,7 @@
],
"hasEKG": 12788,
"hasPrometheus": [
"0.0.0.0",
"127.0.0.1",
12798
],
"minSeverity": "Debug",
Expand Down Expand Up @@ -109,4 +109,4 @@
"scRotation": null
}
]
}
}
3 changes: 3 additions & 0 deletions bootstrap/configs/vector-testnet/db-sync-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"stdout"
]
],
"insertOptions": {
"offchainPoolData": "enable"
},
"options": {
"cfokey": {
"value": "Release-1.0.0"
Expand Down
34 changes: 8 additions & 26 deletions bootstrap/instance/dbsync.tf
Original file line number Diff line number Diff line change
Expand Up @@ -266,33 +266,15 @@ resource "kubernetes_deployment_v1" "db_sync" {
}
}

dynamic "toleration" {
for_each = var.tolerations

toleration {
key = "demeter.run/workload"
operator = "Equal"
value = "mem-intensive"
effect = "NoSchedule"
}

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

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

toleration {
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = var.availability_sla
content {
effect = toleration.value.effect
key = toleration.value.key
operator = toleration.value.operator
value = toleration.value.value
}
}
}
}
Expand Down
37 changes: 36 additions & 1 deletion bootstrap/instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ variable "namespace" {}


variable "dbsync_image" {
type = string
type = string
default = "ghcr.io/demeter-run/dbsync"
}
variable "dbsync_image_tag" {
Expand Down Expand Up @@ -113,6 +113,41 @@ variable "network_env_var" {
default = false
}

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

module "configs" {
source = "../configs"
network = var.network
Expand Down
8 changes: 6 additions & 2 deletions bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ variable "cells" {
release = string
sync_status = string
enable_postgrest = bool
compute_arch = optional(string)
compute_profile = optional(string)
empty_args = optional(bool, false)
custom_config = optional(bool, true)
network_env_var = optional(string, false)
Expand All @@ -130,6 +128,12 @@ variable "cells" {
storage_class = string
size = string
}))
tolerations = optional(list(object({
effect = string
key = string
operator = string
value = optional(string)
})))
}))
}))
}

0 comments on commit f9985c3

Please sign in to comment.