From 781e9415c93cd22d6c3a1b8a46d9a1b0d4c6af0c Mon Sep 17 00:00:00 2001 From: gonzalezzfelipe Date: Fri, 1 Nov 2024 18:23:30 -0300 Subject: [PATCH] fix: Correctly refference configmap and update bootstrap --- bootstrap/stage1/crd.tf | 8 ++ bootstrap/stage2/config.tf | 1 - bootstrap/stage2/control-plane.tf | 141 ++++++++++++++++++++++++++++++ bootstrap/stage2/deployment.tf | 10 +-- bootstrap/stage2/main.tf | 34 ++++++- bootstrap/stage2/rbac.tf | 6 ++ playbook/main.tf | 17 ++-- playbook/pod.yml | 2 + src/custom_resource.rs | 4 +- 9 files changed, 204 insertions(+), 19 deletions(-) create mode 100644 bootstrap/stage2/control-plane.tf diff --git a/bootstrap/stage1/crd.tf b/bootstrap/stage1/crd.tf index a2871e8..c1e8b3f 100644 --- a/bootstrap/stage1/crd.tf +++ b/bootstrap/stage1/crd.tf @@ -68,11 +68,19 @@ resource "kubernetes_manifest" "customresourcedefinition_hydradoomnodes_hydra_do "nullable" = true "type" = "string" } + "initialUtxoAddress" = { + "nullable" = true + "type" = "string" + } "networkId" = { "format" = "uint8" "minimum" = 0 "type" = "integer" } + "offline" = { + "nullable" = true + "type" = "boolean" + } "openHeadImage" = { "nullable" = true "type" = "string" diff --git a/bootstrap/stage2/config.tf b/bootstrap/stage2/config.tf index 5ec2462..ac9cad3 100644 --- a/bootstrap/stage2/config.tf +++ b/bootstrap/stage2/config.tf @@ -7,6 +7,5 @@ resource "kubernetes_config_map" "node-config" { data = { "admin.sk" = "${file("${path.module}/admin.sk")}" "protocol-parameters.json" = "${file("${path.module}/protocol-parameters.json")}" - "utxo.json" = "${file("${path.module}/utxo.json")}" } } diff --git a/bootstrap/stage2/control-plane.tf b/bootstrap/stage2/control-plane.tf new file mode 100644 index 0000000..bcc85ee --- /dev/null +++ b/bootstrap/stage2/control-plane.tf @@ -0,0 +1,141 @@ +resource "kubernetes_deployment_v1" "control_plane" { + wait_for_rollout = false + + metadata { + namespace = var.namespace + name = local.control_plane_component + labels = { + role = local.control_plane_component + } + } + + spec { + // Avoid race conditions + replicas = 1 + + // No 2 replicas simultaneously + strategy { + type = "Recreate" + } + + selector { + match_labels = { + role = local.control_plane_component + } + } + + template { + metadata { + labels = { + role = local.control_plane_component + } + } + + spec { + container { + image = var.control_plane_image + name = "main" + + args = ["control-plane"] + + env { + name = "K8S_IN_CLUSTER" + value = "true" + } + + env { + name = "ROCKET_LOG_LEVEL" + value = "normal" + } + + env { + name = "ROCKET_ADDRESS" + value = "0.0.0.0" + } + + env { + name = "ROCKET_PORT" + value = 8000 + } + + resources { + limits = { + cpu = var.control_plane_resources.limits.cpu + memory = var.control_plane_resources.limits.memory + } + requests = { + cpu = var.control_plane_resources.requests.cpu + memory = var.control_plane_resources.requests.memory + } + } + + port { + name = "api" + container_port = 8000 + protocol = "TCP" + } + } + + dynamic "toleration" { + for_each = var.tolerations + + content { + effect = toleration.value.effect + key = toleration.value.key + operator = toleration.value.operator + value = toleration.value.value + } + } + } + } + } +} + +resource "kubernetes_service_v1" "control_plane_service" { + metadata { + name = local.control_plane_component + namespace = var.namespace + } + + spec { + type = "ClusterIP" + + selector = { + role = local.control_plane_component + } + + port { + name = "api" + port = 8000 + target_port = 8000 + } + } +} + +resource "kubernetes_ingress_v1" "control_plane_ingress" { + metadata { + name = local.control_plane_component + namespace = var.namespace + } + + spec { + ingress_class_name = "nginx" + rule { + host = "api.${var.external_domain}" + http { + path { + path = "/" + path_type = "Prefix" + backend { + service { + name = local.control_plane_component + port { + number = 8000 + } + } + } + } + } + } + } +} diff --git a/bootstrap/stage2/deployment.tf b/bootstrap/stage2/deployment.tf index f1f0806..9781536 100644 --- a/bootstrap/stage2/deployment.tf +++ b/bootstrap/stage2/deployment.tf @@ -3,9 +3,9 @@ resource "kubernetes_deployment_v1" "operator" { metadata { namespace = var.namespace - name = local.component + name = local.operator_component labels = { - role = local.component + role = local.operator_component } } @@ -19,20 +19,20 @@ resource "kubernetes_deployment_v1" "operator" { selector { match_labels = { - role = local.component + role = local.operator_component } } template { metadata { labels = { - role = local.component + role = local.operator_component } } spec { container { - image = var.image + image = var.operator_image name = "main" env { diff --git a/bootstrap/stage2/main.tf b/bootstrap/stage2/main.tf index bdfe7cd..b35d518 100644 --- a/bootstrap/stage2/main.tf +++ b/bootstrap/stage2/main.tf @@ -1,6 +1,7 @@ locals { - component = "operator" - configmap = "hydra-pod-config" + operator_component = "operator" + configmap = "hydra-pod-config" + control_plane_component = "control-plane" } variable "namespace" { @@ -8,7 +9,7 @@ variable "namespace" { default = "hydra-doom" } -variable "image" { +variable "operator_image" { type = string } @@ -25,6 +26,10 @@ variable "sidecar_image" { type = string } +variable "control_plane_image" { + type = string +} + variable "blockfrost_key" { type = string } @@ -69,3 +74,26 @@ variable "resources" { } } } + +variable "control_plane_resources" { + type = object({ + limits = object({ + cpu = optional(string) + memory = string + }) + requests = object({ + cpu = string + memory = string + }) + }) + default = { + requests = { + cpu = "500m" + memory = "512Mi" + } + limits = { + cpu = "2" + memory = "512Mi" + } + } +} diff --git a/bootstrap/stage2/rbac.tf b/bootstrap/stage2/rbac.tf index 13225b0..be3e232 100644 --- a/bootstrap/stage2/rbac.tf +++ b/bootstrap/stage2/rbac.tf @@ -15,6 +15,12 @@ resource "kubernetes_cluster_role" "cluster_role" { verbs = ["*"] } + rule { + api_groups = [""] + resources = ["configmaps"] + verbs = ["*"] + } + rule { api_groups = ["networking.k8s.io"] resources = ["ingresses"] diff --git a/playbook/main.tf b/playbook/main.tf index 111e1b0..eb39d7d 100644 --- a/playbook/main.tf +++ b/playbook/main.tf @@ -1,6 +1,6 @@ locals { namespace = "hydra-doom" - operator_image = "ghcr.io/demeter-run/doom-patrol-operator:sha-f06d308" + operator_image = "ghcr.io/demeter-run/doom-patrol-operator:sha-78bf230" # operator_image = "doom-patrol-operator:local" } @@ -46,11 +46,12 @@ module "stage2" { source = "../bootstrap/stage2" depends_on = [module.stage1] - namespace = local.namespace - external_domain = "external.domain" - image = local.operator_image - open_head_image = "" - sidecar_image = "ghcr.io/demeter-run/doom-patrol-metrics-exporter:a5406f8180a77474c06e44f95619cada183bb8fe" - blockfrost_key = "" - external_port = 80 + namespace = local.namespace + external_domain = "us-east-1.hydra-doom.sundae.fi" + operator_image = local.operator_image + sidecar_image = "ghcr.io/demeter-run/doom-patrol-metrics-exporter:a5406f8180a77474c06e44f95619cada183bb8fe" + open_head_image = "ghcr.io/demeter-run/doom-patrol-hydra:0ee2f6b6d38e500097d992820e0089ead7cb10bc" + control_plane_image = "ghcr.io/demeter-run/doom-patrol-hydra:0ee2f6b6d38e500097d992820e0089ead7cb10bc" + blockfrost_key = "" + external_port = 80 } diff --git a/playbook/pod.yml b/playbook/pod.yml index ab7a7d5..ce98113 100644 --- a/playbook/pod.yml +++ b/playbook/pod.yml @@ -4,6 +4,8 @@ metadata: name: 5py7r5 namespace: hydra-doom spec: + offline: true + initialUtxoAddress: addr_test1vphyqcvtwdpuwlmslna29ymaua8e9cswlmllt9wkey345cqgtzv2j networkId: 1 seedInput: foo participant: foo diff --git a/src/custom_resource.rs b/src/custom_resource.rs index 002c3b2..440c5e0 100644 --- a/src/custom_resource.rs +++ b/src/custom_resource.rs @@ -155,7 +155,7 @@ impl HydraDoomNode { Deployment { metadata: ObjectMeta { - name: Some(name), + name: Some(name.clone()), ..Default::default() }, spec: Some(DeploymentSpec { @@ -293,7 +293,7 @@ impl HydraDoomNode { Volume { name: "initialutxo".to_string(), config_map: Some(ConfigMapVolumeSource { - name: constants.initial_utxo_config_dir.clone(), + name: name.clone(), ..Default::default() }), ..Default::default()