Skip to content

Commit

Permalink
fix: Correctly refference configmap and update bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe committed Nov 1, 2024
1 parent 78bf230 commit 781e941
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 19 deletions.
8 changes: 8 additions & 0 deletions bootstrap/stage1/crd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion bootstrap/stage2/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")}"
}
}
141 changes: 141 additions & 0 deletions bootstrap/stage2/control-plane.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
}
}
10 changes: 5 additions & 5 deletions bootstrap/stage2/deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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 {
Expand Down
34 changes: 31 additions & 3 deletions bootstrap/stage2/main.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
locals {
component = "operator"
configmap = "hydra-pod-config"
operator_component = "operator"
configmap = "hydra-pod-config"
control_plane_component = "control-plane"
}

variable "namespace" {
type = string
default = "hydra-doom"
}

variable "image" {
variable "operator_image" {
type = string
}

Expand All @@ -25,6 +26,10 @@ variable "sidecar_image" {
type = string
}

variable "control_plane_image" {
type = string
}

variable "blockfrost_key" {
type = string
}
Expand Down Expand Up @@ -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"
}
}
}
6 changes: 6 additions & 0 deletions bootstrap/stage2/rbac.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 9 additions & 8 deletions playbook/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions playbook/pod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
name: 5py7r5
namespace: hydra-doom
spec:
offline: true
initialUtxoAddress: addr_test1vphyqcvtwdpuwlmslna29ymaua8e9cswlmllt9wkey345cqgtzv2j
networkId: 1
seedInput: foo
participant: foo
Expand Down
4 changes: 2 additions & 2 deletions src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl HydraDoomNode {

Deployment {
metadata: ObjectMeta {
name: Some(name),
name: Some(name.clone()),
..Default::default()
},
spec: Some(DeploymentSpec {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 781e941

Please sign in to comment.