Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle networks without prefix #10

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions bootstrap/configs/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
locals {
default_address_by_network = {
"mainnet" : "node-mainnet-stable.ext-nodes-m1.svc.cluster.local:3000"
"preprod" : "node-preprod-stable.ext-nodes-m1.svc.cluster.local:3000"
"preview" : "node-preview-stable.ext-nodes-m1.svc.cluster.local:3000"
"cardano-mainnet" : "node-mainnet-stable.ext-nodes-m1.svc.cluster.local:3000"
"cardano-preprod" : "node-preprod-stable.ext-nodes-m1.svc.cluster.local:3000"
"cardano-preview" : "node-preview-stable.ext-nodes-m1.svc.cluster.local:3000"
"vector-testnet" : "85.90.225.26:7532"
}
}
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/proxy/monitor.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ resource "kubernetes_manifest" "proxy_monitor" {
"app.kubernetes.io/component" = "o11y"
"app.kubernetes.io/part-of" = "demeter"
}
name = "proxy"
name = local.name
namespace = var.namespace
}
spec = {
selector = {
matchLabels = {
role = "proxy"
role = local.role
}
}
podMetricsEndpoints = [
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/services/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ variable "namespace" {

variable "networks" {
type = list(string)
default = ["mainnet", "preprod", "preview", "vector-testnet"]
default = ["cardano-mainnet", "cardano-preprod", "cardano-preview", "cardano-vector-testnet"]
}

resource "kubernetes_service_v1" "well_known_service_grpc" {
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ variable "namespace" {

variable "networks" {
type = list(string)
default = ["mainnet", "preprod", "preview", "vector-testnet"]
default = ["cardano-mainnet", "cardano-preprod", "cardano-preview", "vector-testnet"]
}

variable "network_addresses" {
Expand Down
8 changes: 6 additions & 2 deletions operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use serde::{Deserialize, Serialize};
use std::{sync::Arc, time::Duration};
use tracing::{error, info, instrument};

use crate::{build_api_key, build_hostname, patch_resource_status, Error, Metrics, Result, State};
use crate::{
build_api_key, build_hostname, handle_legacy_networks, patch_resource_status, Error, Metrics,
Result, State,
};

pub static UTXORPX_PORT_FINALIZER: &str = "utxorpcports.demeter.run";

Expand Down Expand Up @@ -61,7 +64,8 @@ async fn reconcile(crd: Arc<UtxoRpcPort>, ctx: Arc<Context>) -> Result<Action> {
Some(key) => key.clone(),
None => build_api_key(&crd).await?,
};
let (hostname, _) = build_hostname(&key, &crd.spec.network);
let host_network = handle_legacy_networks(&crd.spec.network);
let (hostname, _) = build_hostname(&key, &host_network);

let status = UtxoRpcPortStatus {
grpc_endpoint_url: hostname,
Expand Down
17 changes: 17 additions & 0 deletions operator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ use kube::{
discovery::ApiResource,
Api, Client, ResourceExt,
};
use lazy_static::lazy_static;
use serde_json::json;
use std::collections::HashMap;

use crate::{get_config, Error, UtxoRpcPort};

lazy_static! {
static ref LEGACY_NETWORKS: HashMap<&'static str, String> = {
let mut m = HashMap::new();
m.insert("mainnet", "cardano-mainnet".into());
m.insert("preprod", "cardano-preprod".into());
m.insert("preview", "cardano-preview".into());
m
};
}

pub async fn patch_resource_status(
client: Client,
namespace: &str,
Expand All @@ -27,6 +39,11 @@ pub async fn patch_resource_status(
Ok(())
}

pub fn handle_legacy_networks(network: &str) -> String {
let default = network.to_string();
LEGACY_NETWORKS.get(network).unwrap_or(&default).to_string()
}

pub fn build_hostname(key: &str, network: &str) -> (String, String) {
let config = get_config();
let extension_subdomain = &config.extension_subdomain;
Expand Down
4 changes: 2 additions & 2 deletions proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use auth::AuthBackgroundService;
use config::Config;
use dotenv::dotenv;
use health::HealthBackgroundService;
use operator::{kube::ResourceExt, UtxoRpcPort};
use operator::{handle_legacy_networks, kube::ResourceExt, UtxoRpcPort};
use pingora::{
server::{configuration::Opt, Server},
services::background::background_service,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Display for Consumer {
}
impl From<&UtxoRpcPort> for Consumer {
fn from(value: &UtxoRpcPort) -> Self {
let network = value.spec.network.to_string();
let network = handle_legacy_networks(&value.spec.network);
let tier = value
.spec
.throughput_tier
Expand Down
Loading