From ea216f63a21853ce7d3372235f43dfd1cd80925f Mon Sep 17 00:00:00 2001 From: gonzalezzfelipe Date: Wed, 28 Aug 2024 16:11:14 -0300 Subject: [PATCH] fix: Update bootsrapping to handle usage driver --- bootstrap/daemon/config.tf | 13 +- bootstrap/daemon/daemon.toml.tftpl | 4 + bootstrap/daemon/main.tf | 16 +++ bootstrap/rpc/config.tf | 2 +- bootstrap/rpc/crds.tf | 3 +- bootstrap/rpc/crds/frontends.json | 137 ++++++++++++++++++++++ bootstrap/rpc/{ => crds}/utxorpcport.json | 0 7 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 bootstrap/rpc/crds/frontends.json rename bootstrap/rpc/{ => crds}/utxorpcport.json (100%) diff --git a/bootstrap/daemon/config.tf b/bootstrap/daemon/config.tf index af14829..1ff08a8 100644 --- a/bootstrap/daemon/config.tf +++ b/bootstrap/daemon/config.tf @@ -8,11 +8,14 @@ resource "kubernetes_config_map_v1" "fabric_daemon_config" { "daemon.toml" = "${templatefile( "${path.module}/daemon.toml.tftpl", { - broker_urls = var.broker_urls - consumer_name = var.consumer_name - kafka_username = var.kafka_username - kafka_password = var.kafka_password - topic = var.kafka_topic + broker_urls = var.broker_urls + consumer_name = var.consumer_name + kafka_username = var.kafka_username + kafka_password = var.kafka_password + topic = var.kafka_topic + cluster_id = var.cluster_id + prometheus_url = var.prometheus_url + prometheus_delay_sec = var.prometheus_delay_sec } )}" } diff --git a/bootstrap/daemon/daemon.toml.tftpl b/bootstrap/daemon/daemon.toml.tftpl index 8cf4f7f..448aeed 100644 --- a/bootstrap/daemon/daemon.toml.tftpl +++ b/bootstrap/daemon/daemon.toml.tftpl @@ -1,5 +1,9 @@ topic = "${topic}" +cluster_id = "${cluster_id}" +prometheus_url = ${prometheus_url} +delay_sec = 60 + [kafka] "bootstrap.servers" = "${broker_urls}" "group.id"= "${consumer_name}" diff --git a/bootstrap/daemon/main.tf b/bootstrap/daemon/main.tf index bf45a03..f22eea6 100644 --- a/bootstrap/daemon/main.tf +++ b/bootstrap/daemon/main.tf @@ -11,6 +11,10 @@ variable "image" { type = string } +variable "cluster_id" { + type = string +} + variable "broker_urls" { type = string description = "Comma separated values of the queue broker urls." @@ -38,6 +42,18 @@ variable "replicas" { default = 1 } +variable "prometheus_url" { + type = string + description = "URL where to query prometheus to report usage metrics." + default = "http://prometheus-operated.demeter-system.svc.cluster.local:9090/api/v1" +} + +variable "prometheus_delay_sec" { + type = number + description = "Delay between usage report loops." + default = 60 +} + variable "tolerations" { type = list(object({ effect = string diff --git a/bootstrap/rpc/config.tf b/bootstrap/rpc/config.tf index e0ea24e..5b4464a 100644 --- a/bootstrap/rpc/config.tf +++ b/bootstrap/rpc/config.tf @@ -8,7 +8,7 @@ resource "kubernetes_config_map_v1" "fabric_rpc_config" { "rpc.toml" = "${templatefile( "${path.module}/rpc.toml.tftpl", { - port = local.port, + port = local.port, // If we change the consumer, we must rebuild the cache. db_path = "/var/cache/${var.consumer_name}.db", broker_urls = var.broker_urls diff --git a/bootstrap/rpc/crds.tf b/bootstrap/rpc/crds.tf index 06520c5..d430adb 100644 --- a/bootstrap/rpc/crds.tf +++ b/bootstrap/rpc/crds.tf @@ -5,6 +5,7 @@ resource "kubernetes_config_map_v1" "fabric_rpc_crds" { } data = { - "utxorpcport.json" = "${file("${path.module}/utxorpcport.json")}" + "utxorpcport.json" = "${file("${path.module}/crds/utxorpcport.json")}" + "frontends.json" = "${file("${path.module}/crds/frontends.json")}" } } diff --git a/bootstrap/rpc/crds/frontends.json b/bootstrap/rpc/crds/frontends.json new file mode 100644 index 0000000..bc18550 --- /dev/null +++ b/bootstrap/rpc/crds/frontends.json @@ -0,0 +1,137 @@ +{ + "apiVersion": "apiextensions.k8s.io/v1", + "kind": "CustomResourceDefinition", + "metadata": { + "name": "frontends.demeter.run" + }, + "spec": { + "group": "demeter.run", + "names": { + "kind": "Frontend", + "plural": "frontends", + "shortNames": [ + "fnd" + ], + "singular": "frontend" + }, + "scope": "Namespaced", + "versions": [ + { + "name": "v1alpha1", + "schema": { + "openAPIV3Schema": { + "type": "object", + "properties": { + "spec": { + "type": "object", + "properties": { + "givenName": { + "type": "string" + }, + "image": { + "type": "string" + }, + "replicas": { + "type": "number" + }, + "enabled": { + "type": "boolean" + }, + "args": { + "type": "string" + }, + "tenancy": { + "type": "string", + "pattern": "^(\\b(cluster|project|proxy)\\b)$" + }, + "envVars": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + }, + "annotations": { + "type": "object", + "x-kubernetes-preserve-unknown-fields": true + }, + "computeClass": { + "type": "string" + } + } + }, + "status": { + "type": "object", + "properties": { + "runningStatus": { + "type": "string" + }, + "availableReplicas": { + "type": "number" + }, + "observedGeneration": { + "type": "number" + }, + "availableEnvVars": { + "type": "array", + "items": { + "type": "string" + } + }, + "startTime": { + "type": "number" + }, + "storageDCUPerMin": { + "type": "number" + }, + "computeDCUPerMin": { + "type": "number" + } + } + } + } + } + }, + "additionalPrinterColumns": [ + { + "name": "Enabled", + "type": "boolean", + "jsonPath": ".spec.enabled" + }, + { + "name": "Replicas", + "type": "number", + "jsonPath": ".spec.replicas" + }, + { + "name": "Compute Class", + "type": "string", + "jsonPath": ".spec.computeClass" + }, + { + "name": "Compute DCU/min", + "type": "number", + "jsonPath": ".status.computeDCUPerMin" + }, + { + "name": "Storage DCU/min", + "type": "number", + "jsonPath": ".status.storageDCUPerMin" + } + ], + "served": true, + "storage": true, + "subresources": { + "status": {} + } + } + ] + } +} diff --git a/bootstrap/rpc/utxorpcport.json b/bootstrap/rpc/crds/utxorpcport.json similarity index 100% rename from bootstrap/rpc/utxorpcport.json rename to bootstrap/rpc/crds/utxorpcport.json