Skip to content

Commit

Permalink
chore: Use same admin key on control plane
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe committed Nov 5, 2024
1 parent 183b696 commit 08c1f0f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
4 changes: 0 additions & 4 deletions bootstrap/stage1/crd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ resource "kubernetes_manifest" "customresourcedefinition_hydradoomnodes_hydra_do
}
"type" = "array"
}
"initialUtxoAddress" = {
"nullable" = true
"type" = "string"
}
"networkId" = {
"format" = "uint8"
"minimum" = 0
Expand Down
17 changes: 17 additions & 0 deletions bootstrap/stage2/control-plane.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ resource "kubernetes_deployment_v1" "control_plane" {
value = 8000
}

env {
name = "ROCKET_ADMIN_KEY_FILE"
value = "${local.secret_mount_path}/admin.sk"
}

volume_mount {
name = "secret"
mount_path = local.secret_mount_path
}

resources {
limits = {
cpu = var.control_plane_resources.limits.cpu
Expand All @@ -76,6 +86,13 @@ resource "kubernetes_deployment_v1" "control_plane" {
}
}

volume {
name = "secret"
config_map {
name = local.secret
}
}

dynamic "toleration" {
for_each = var.tolerations

Expand Down
5 changes: 5 additions & 0 deletions bootstrap/stage2/deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ resource "kubernetes_deployment_v1" "operator" {
value = var.external_port
}

env {
name = "OFFLINE_INITIAL_UTXO_ADDRESS"
value = var.admin_addr
}

resources {
limits = {
cpu = var.resources.limits.cpu
Expand Down
10 changes: 10 additions & 0 deletions bootstrap/stage2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ locals {
operator_component = "operator"
configmap = "hydra-pod-config"
secret = "hydra-pod-admin-key"
secret_mount_path = "/var/secret"
control_plane_component = "control-plane"
}

Expand Down Expand Up @@ -43,6 +44,15 @@ variable "external_port" {
type = number
}

variable "admin_key_path" {
type = string
}

variable "admin_addr" {
type = string
description = "Must be consistent with admin key, calculated using cardano cli."
}

variable "tolerations" {
type = list(object({
effect = string
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/stage2/secret.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ resource "kubernetes_secret" "admin_key" {
namespace = var.namespace
}
data = {
"admin.sk" = "${file("${path.module}/admin.sk")}"
# "admin.sk" = "${file("${path.module}/admin.sk")}"
"admin.sk" = var.admin_key_path
}
type = "Opaque"
}
4 changes: 2 additions & 2 deletions docker/dockerfile.hydra
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ WORKDIR /app

RUN apt-get update && apt-get install -y libssl-dev pkg-config git

RUN git clone https://github.com/scarmuega/hydra-control-plane.git
RUN cd hydra-control-plane && git checkout feat/k8s-integration
RUN git clone https://github.com/gonzalezzfelipe/hydra-control-plane.git
RUN cd hydra-control-plane && git checkout chore/use-admin-key

WORKDIR /app/hydra-control-plane
RUN cargo build --locked --release
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Config {
pub blockfrost_key: String,
pub external_domain: String,
pub external_port: String,
pub offline_initial_utxo_address: String,
}

impl Config {
Expand All @@ -32,6 +33,8 @@ impl Config {
blockfrost_key: env::var("BLOCKFROST_KEY").expect("Missing BLOCKFROST_KEY env var"),
external_domain: env::var("EXTERNAL_DOMAIN").expect("Missing EXTERNAL_DOMAIN env var."),
external_port: env::var("EXTERNAL_PORT").expect("Missing EXTERNAL_PORT env var."),
offline_initial_utxo_address: env::var("OFFLINE_INITIAL_UTXO_ADDRESS")
.expect("Missing OFFLINE_INITIAL_UTXO_ADDRESS env var."),
}
}
}
8 changes: 2 additions & 6 deletions src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub static HYDRA_DOOM_NODE_FINALIZER: &str = "hydradoomnode/finalizer";
#[serde(rename_all = "camelCase")]
pub struct HydraDoomNodeSpec {
pub offline: Option<bool>,
pub initial_utxo_address: Option<String>,
// Open head
pub network_id: u8,
pub seed_input: String,
Expand Down Expand Up @@ -98,7 +97,7 @@ impl HydraDoomNode {
format!("{}.{}", self.name_any(), config.external_domain,)
}

pub fn configmap(&self, _config: &Config, _constants: &K8sConstants) -> ConfigMap {
pub fn configmap(&self, config: &Config, _constants: &K8sConstants) -> ConfigMap {
let name = self.internal_name();

ConfigMap {
Expand All @@ -117,10 +116,7 @@ impl HydraDoomNode {
}}
}}
}}"#,
self.spec.initial_utxo_address.clone().unwrap_or(
"addr_test1vphyqcvtwdpuwlmslna29ymaua8e9cswlmllt9wkey345cqgtzv2j"
.to_string()
)
config.offline_initial_utxo_address.clone()
),
)])),
..Default::default()
Expand Down

0 comments on commit 08c1f0f

Please sign in to comment.