Skip to content

Commit

Permalink
feat: Add bootstrapping (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe authored Jul 12, 2024
1 parent 65072af commit 4fbbddb
Show file tree
Hide file tree
Showing 15 changed files with 937 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ dev.db*
rpc.toml
daemon.toml
grpcurl*
test/.terraform*
test/local.tfstate*
17 changes: 17 additions & 0 deletions bootstap/daemon/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "kubernetes_config_map_v1" "fabric_daemon_config" {
metadata {
name = local.configmap_name
namespace = var.namespace
}

data = {
"daemon.toml" = "${templatefile(
"${path.module}/daemon.toml",
{
broker_urls = var.broker_urls
}
)}"
}
}


83 changes: 83 additions & 0 deletions bootstap/daemon/deployment.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
locals {
role = "fabric-daemon"
}

resource "kubernetes_deployment_v1" "daemon" {
wait_for_rollout = false

metadata {
labels = {
role = local.role
}
name = "fabric-daemon"
namespace = var.namespace
}

spec {
replicas = 1

selector {
match_labels = {
role = local.role
}
}

template {
metadata {
labels = {
role = local.role
}
}

spec {
container {
name = "daemon"
image = var.image

env {
name = "DAEMON_CONFIG"
value = "/fabric/daemon.toml"
}

port {
container_port = local.port
}

volume_mount {
name = "config"
mount_path = "/fabric"
}

resources {
limits = {
cpu = var.resources.limits.cpu
memory = var.resources.limits.memory
}
requests = {
cpu = var.resources.requests.cpu
memory = var.resources.requests.memory
}
}
}

volume {
name = "config"
config_map {
name = local.configmap_name
}
}

dynamic "toleration" {
for_each = var.tolerations

content {
effect = toleration.value.effect
key = toleration.value.key
operator = toleration.value.operator
value = toleration.value.value
}
}
}
}
}
}
70 changes: 70 additions & 0 deletions bootstap/daemon/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
locals {
configmap_name = "fabric-daemon-config"
port = 5000
}

variable "namespace" {
type = string
}

variable "image" {
type = string
}

variable "broker_urls" {
type = string
description = "Comma separated values of the queue broker urls."
}

variable "tolerations" {
type = list(object({
effect = string
key = string
operator = string
value = string
}))
default = [
{
effect = "NoSchedule"
key = "demeter.run/compute-profile"
operator = "Equal"
value = "general-purpose"
},
{
effect = "NoSchedule"
key = "demeter.run/compute-arch"
operator = "Equal"
value = "x86"
},
{
effect = "NoSchedule"
key = "demeter.run/availability-sla"
operator = "Equal"
value = "consistent"
}

]
}

variable "resources" {
type = object({
limits = object({
cpu = optional(string)
memory = string
})
requests = object({
cpu = string
memory = string
})
})
default = {
requests = {
cpu = "100m"
memory = "500Mi"
}
limits = {
cpu = "500m"
memory = "500Mi"
}
}
}
27 changes: 27 additions & 0 deletions bootstap/daemon/rbac.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "kubernetes_cluster_role" "cluster_role" {
metadata {
name = var.namespace
}

rule {
api_groups = ["*"]
resources = ["*"]
verbs = ["*"]
}
}

resource "kubernetes_cluster_role_binding" "cluster_role_binding" {
metadata {
name = var.namespace
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = var.namespace
}
subject {
kind = "ServiceAccount"
name = "default"
namespace = var.namespace
}
}
98 changes: 98 additions & 0 deletions bootstap/queue/console.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
locals {
console_instance_name = "fabric-queue-console"
console_configmap_name = "${local.console_instance_name}-config"
}

resource "kubernetes_config_map_v1" "fabric_queue_console_config" {
metadata {
name = local.console_configmap_name
namespace = var.namespace
}

data = {
"config.yml" = "${templatefile(
"${path.module}/console_config.yml",
{
instance_name = var.instance_name,
kafka_external_port = local.kafka_external_port,
schema_registry_external_port = local.schema_registry_external_port,
admin_api_external_port = local.admin_api_external_port
}
)}"
}
}

resource "kubernetes_deployment_v1" "fabric_queue_console" {
wait_for_rollout = false
depends_on = [kubernetes_config_map_v1.fabric_queue_console_config]

metadata {
name = local.console_instance_name
namespace = var.namespace
}

spec {
replicas = 1

selector {
match_labels = {
"demeter.run/instance" : local.console_instance_name
}
}

template {
metadata {
labels = {
"demeter.run/instance" : local.console_instance_name
}
}

spec {
container {
name = "main"
image = var.console_image

env {
name = "CONFIG_FILEPATH"
value = "/etc/config/config.yml"
}

volume_mount {
name = "config"
mount_path = "/etc/config"
}

resources {
limits = {
cpu = var.console_resources.limits.cpu
memory = var.console_resources.limits.memory
}
requests = {
cpu = var.console_resources.requests.cpu
memory = var.console_resources.requests.memory
}
}

}

volume {
name = "config"
config_map {
name = local.console_configmap_name
}
}

dynamic "toleration" {
for_each = var.tolerations

content {
effect = toleration.value.effect
key = toleration.value.key
operator = toleration.value.operator
value = toleration.value.value
}
}
}
}
}
}
9 changes: 9 additions & 0 deletions bootstap/queue/console_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kafka:
brokers: ["${instance_name}:${kafka_external_port}"]
schemaRegistry:
enabled: true
urls: ["http://${instance_name}:${schema_registry_external_port}"]
redpanda:
adminApi:
enabled: true
urls: ["http://${instance_name}:${admin_api_external_port}"]
Loading

0 comments on commit 4fbbddb

Please sign in to comment.