From f9985c38037b1ad03d749a551f492948155af0e8 Mon Sep 17 00:00:00 2001 From: Felipe Gonzalez Date: Wed, 8 Jan 2025 15:16:26 -0300 Subject: [PATCH] chore: Dynamic tolerations (#55) --- bootstrap/cell/main.tf | 55 +++++++++++++------ bootstrap/cell/variables.tf | 9 ++- bootstrap/configs/main.tf | 2 +- bootstrap/configs/prime-testnet/config.json | 4 +- .../configs/prime-testnet/db-sync-config.json | 5 +- bootstrap/configs/vector-testnet/config.json | 12 ++-- .../vector-testnet/db-sync-config.json | 3 + bootstrap/instance/dbsync.tf | 34 +++--------- bootstrap/instance/main.tf | 37 ++++++++++++- bootstrap/variables.tf | 8 ++- 10 files changed, 111 insertions(+), 58 deletions(-) diff --git a/bootstrap/cell/main.tf b/bootstrap/cell/main.tf index e248c04..d523db1 100644 --- a/bootstrap/cell/main.tf +++ b/bootstrap/cell/main.tf @@ -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" @@ -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 @@ -82,4 +104,5 @@ module "dbsync_instances" { storage_class = "fast" size = "10Gi" }) + tolerations = coalesce(each.value.tolerations, local.default_tolerations) } diff --git a/bootstrap/cell/variables.tf b/bootstrap/cell/variables.tf index 84e85ee..9d588f5 100644 --- a/bootstrap/cell/variables.tf +++ b/bootstrap/cell/variables.tf @@ -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) @@ -109,6 +106,12 @@ variable "instances" { storage_class = string size = string })) + tolerations = optional(list(object({ + effect = string + key = string + operator = string + value = optional(string) + }))) })) } diff --git a/bootstrap/configs/main.tf b/bootstrap/configs/main.tf index 31086c1..f40c8b8 100644 --- a/bootstrap/configs/main.tf +++ b/bootstrap/configs/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { kubernetes = { - source = "hashicorp/kubernetes" + source = "hashicorp/kubernetes" } } } diff --git a/bootstrap/configs/prime-testnet/config.json b/bootstrap/configs/prime-testnet/config.json index b1960cd..ff15a04 100644 --- a/bootstrap/configs/prime-testnet/config.json +++ b/bootstrap/configs/prime-testnet/config.json @@ -6,7 +6,7 @@ "ByronGenesisHash": "acd3e7c4cc071ae176fa253e654f0dd4e759892b16e958d8bd3c393f5c6c66d2", "ShelleyGenesisHash": "0b67b0cb16e973478888efb1c7f69fca8e80489369afed94624a588e94a94f2b", "AlonzoGenesisHash": "0f715ff78fcab739c6cb2cc1073eb87d0ffe3514218bfa0337d416f6fbaf7886", - "ConwayGenesisHash": "d43d3f38e01848bddf67e66fe29fbd236aca252de58c7f2c1904c67107c17842", + "ConwayGenesisHash": "47d7c396e8a58db4ae61dfbc1d47f9e9b786defb1d5b1a76c850a436e9017aff", "SocketPath": "db/node.socket", "ApplicationName":"cardano-sl", "ApplicationVersion":0, @@ -108,4 +108,4 @@ "TraceLedgerPeers": true, "TracePeerSelectionCounters": true, "TracePeerStateActions": true -} +} \ No newline at end of file diff --git a/bootstrap/configs/prime-testnet/db-sync-config.json b/bootstrap/configs/prime-testnet/db-sync-config.json index e63da69..a6f14cb 100644 --- a/bootstrap/configs/prime-testnet/db-sync-config.json +++ b/bootstrap/configs/prime-testnet/db-sync-config.json @@ -15,12 +15,15 @@ ] ], "minSeverity":"Info", + "insertOptions": { + "offchainPoolData": "enable" + }, "options":{ "cfokey":{ "value":"Release-1.0.0" }, "mapBackends":{ - + }, "mapSeverity":{ "db-sync-node":"Info", diff --git a/bootstrap/configs/vector-testnet/config.json b/bootstrap/configs/vector-testnet/config.json index d300f21..968b5db 100644 --- a/bootstrap/configs/vector-testnet/config.json +++ b/bootstrap/configs/vector-testnet/config.json @@ -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, @@ -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, @@ -74,7 +74,7 @@ ], "hasEKG": 12788, "hasPrometheus": [ - "0.0.0.0", + "127.0.0.1", 12798 ], "minSeverity": "Debug", @@ -109,4 +109,4 @@ "scRotation": null } ] -} +} \ No newline at end of file diff --git a/bootstrap/configs/vector-testnet/db-sync-config.json b/bootstrap/configs/vector-testnet/db-sync-config.json index c5e296a..87d1172 100644 --- a/bootstrap/configs/vector-testnet/db-sync-config.json +++ b/bootstrap/configs/vector-testnet/db-sync-config.json @@ -30,6 +30,9 @@ "stdout" ] ], + "insertOptions": { + "offchainPoolData": "enable" + }, "options": { "cfokey": { "value": "Release-1.0.0" diff --git a/bootstrap/instance/dbsync.tf b/bootstrap/instance/dbsync.tf index 2d70e9c..4f4b21a 100644 --- a/bootstrap/instance/dbsync.tf +++ b/bootstrap/instance/dbsync.tf @@ -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 + } } } } diff --git a/bootstrap/instance/main.tf b/bootstrap/instance/main.tf index 64c5920..da75377 100644 --- a/bootstrap/instance/main.tf +++ b/bootstrap/instance/main.tf @@ -10,7 +10,7 @@ variable "namespace" {} variable "dbsync_image" { - type = string + type = string default = "ghcr.io/demeter-run/dbsync" } variable "dbsync_image_tag" { @@ -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 diff --git a/bootstrap/variables.tf b/bootstrap/variables.tf index fbfbcd7..12dec02 100644 --- a/bootstrap/variables.tf +++ b/bootstrap/variables.tf @@ -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) @@ -130,6 +128,12 @@ variable "cells" { storage_class = string size = string })) + tolerations = optional(list(object({ + effect = string + key = string + operator = string + value = optional(string) + }))) })) })) }